no const string consolidation in -O0?


Just spent about an hour to narrow down this.

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.

I guess this means clang doesn’t do const string consolidation by default. Is there any switch to make clang do this consolidation in -O0?

Or can Clang dev team can make this consolidate as default?
I hope this make sense. since it’s kind of ‘de facto’ in other compilers, 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;

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

if (gTESTINFO.key == key)
return 0;


No... but we should probably fix that. Pretty sure it's just an
oversight, not intentional. Please file at .