http://llvm.org/bugs/show_bug.cgi?id=12199

             Bug #: 12199
           Summary: const strings not consolidated in -O0
           Product: clang
           Version: 3.0
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]
    Classification: Unclassified


For the program below. clang 3.1 returns "different" unless you optimize it
with -O2 or higher.  In gcc 4.2 and VC,  the code always return "same" no
matter in -O0 or -O2. 

Some code was written with this assumption, they know all the keys are from
const strings so they do pointer compare instead string compare. There're might
be more code relies on this behavior. 

#include <stdio.h>
#define LAYER_KEY L"Layer"
struct TEST {
  const wchar_t* key;
}gTESTINFO = {
    LAYER_KEY
};

int main() {
    const wchar_t* key = LAYER_KEY;

    if (gTESTINFO.key == key)
        printf("same\n");
    else
        printf("different\n"); 
    return 0;
}

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to