I compile this program to LLVM bytecode: #include <map> std::map<int, int> someMap; Using this command line: $ llvm-g++ -O2 --emit-llvm -o mapbug.bc -c mapbug.cc Then when I try to use the resulting bytecode module, the LLVM tools will complain about it being invalid. For example: $ llvm-link -f -o mapbug.linked.bc mapbug.bc Global variable initializer type does not match global variable type! "struct.std::map<int,int,std::less<int>,std::allocator<std::pair<const int, int> > >"* @someMap Broken module found, compilation aborted! This problem disappears if I remove "-O2" or replace it by "-O0". I'm using LLVM 2.0 and its g++ front-end, compiled from source with GCC 4.1.3.
Confirmed on TOT. Cannot reproduce via "plain" opt. Seems to be somehow FunctionPasses-specific. Investigating.
Reduced. Steps to reproduce: ./opt -globalopt bugpoint-reduced-simplified.bc diff'ing: -@llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_someMap } ] ; <[1 x { i32, void ()* }]*> [#uses=0] +@llvm.global_ctors = appending global [0 x { i32, void ()* }] zeroinitializer ; <[0 x { i32, void ()* }]*> [#uses=0] It seems, it dropped the function at all
Created attachment 994 [details] bugpoint-reduced-simplified.bc
Fixed, patch here: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070604/050206.html Testcase here: GlobalOpt/2007-06-04-PackedStruct.ll -Chris
I recompiled LLVM and its GCC with the patch and I can confirm that the bug is fixed. Thanks to you both!