http://llvm.org/bugs/show_bug.cgi?id=19590
Bug ID: 19590
Summary: clang produces an unneeded static initializer
Product: clang
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: LLVM Codegen
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
Classification: Unclassified
$ cat si.cc
enum LinkerInitialized { LINKER_INITIALIZED };
struct Bar {
// Note: No definition.
static const LinkerInitialized LINKER_INITIALIZED;
};
class Foo {
public:
// Note: `x` isn't used, definition not needed.
explicit Foo(LinkerInitialized /*x*/) {}
private:
int lockword_;
};
Foo foo(Bar::LINKER_INITIALIZED);
int main() {}
$ third_party/llvm-build/Release+Asserts/bin/clang++ -O2 -o foo -fPIC si.cc
$ readelf -SW foo | grep init_arr [18] .init_array INIT_ARRAY
0000000000600dd0 000dd0 000008 00 WA 0 0 8
gcc doesn't do this:
$ g++ -O2 -o foo -fPIC si.cc
$ readelf -SW foo | grep init_arr
This is true for the .o too:
$ g++ -O2 -c -fPIC si.cc
$ nm si.o | grep GLOBAL
$ third_party/llvm-build/Release+Asserts/bin/clang++ -O2 -c -fPIC si.cc
$ nm si.o | grep GLOBAL0000000000000000 t _GLOBAL__I_si.cc
(the "-fPIC" is so that gcc adds the filename to the _GLOBAL__ symbol. clang
only adds that with the "[(questionable but useful) patch] Let codegen write
the filename for translation unit initializer functions" patch on cfe-commits.)
--
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