[LLVMbugs] [Bug 19590] New: clang produces an unneeded static initializer

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Apr 28 15:27:15 PDT 2014


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: unassignedclangbugs at nondot.org
          Reporter: nicolasweber at gmx.de
                CC: llvmbugs at cs.uiuc.edu
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140428/6d1fcd53/attachment.html>


More information about the llvm-bugs mailing list