llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.91k stars 11.51k forks source link

const strings not consolidated in -O0 #12571

Open llvmbot opened 12 years ago

llvmbot commented 12 years ago
Bugzilla Link 12199
Version 3.0
OS MacOS X
Reporter LLVM Bugzilla Contributor

Extended Description

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;
}
llvmbot commented 11 years ago

Reproduced with trunk (20130114) on MacOS X. Oddly does not occur on x86_64-linux.

llvmbot commented 12 years ago

http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-March/020070.html