开发者

clang optimization bug?

I've been trying to track down what seems like a bug in clang, and I think I've got a reasonably minimal reproduction of it. Here's my program:

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define x_Is_Digit(x)       isdigit((unsigned char) (x))

void        Odd_Behavior(char * version)
{
    char * ptr, *tmp;

    for (ptr = version; x_Is_Digit(*ptr); ptr++);
    ptr++;

    for (tmp = ptr; x_Is_Digit(*ptr); ptr++);
    if (ptr == tmp)
        printf("%08x == %08x! Really?\n", ptr, tmp);
}

int main()
{
    char buffer[100];
    strcpy(buffer, "3.8a");
    Odd_Behavior(buffer);
    return(0);
}

When I compile it with optimization, in the clang included with the Xcode download ("Apple clang 2.1"):

clang++ -Os optimizebug.cpp

And run it, it reports:

6b6f2be3 == 6b6f2be2! Really?

This strikes me as a tad开发者_开发知识库 odd, to say the least. If I remove the (unsigned char) cast in x_Is_Digit, it works properly.

Have I run into a bug in clang? Or am I doing something here that's causing some sort of undefined behavior? If I compile it with -O0, I don't get the problem.


Certainly looks like a bug to me. Clang mainline doesn't display this (at least on darwin/x86-64). Please file a bug at llvm.org/bugs with full details on how to reproduce this. Stack overflow isn't a great place to report compiler bugs :)


Definitively a bug. If the two pointers are equal at the if statement, they must also be equal in the printf statement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜