LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1491 - globalopt crash for packed structs
Summary: globalopt crash for packed structs
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Interprocedural Optimizations (show other bugs)
Version: 2.0
Hardware: All All
: P normal
Assignee: Chris Lattner
URL:
Keywords: compile-fail
Depends on:
Blocks:
 
Reported: 2007-06-03 07:45 PDT by Maarten ter Huurne
Modified: 2010-02-22 12:50 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments
bugpoint-reduced-simplified.bc (1.22 KB, application/octet-stream)
2007-06-03 08:15 PDT, Anton Korobeynikov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Maarten ter Huurne 2007-06-03 07:45:52 PDT
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.
Comment 1 Anton Korobeynikov 2007-06-03 08:04:36 PDT
Confirmed on TOT. Cannot reproduce via "plain" opt. Seems to be somehow
FunctionPasses-specific. Investigating.
Comment 2 Anton Korobeynikov 2007-06-03 08:14:48 PDT
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
Comment 3 Anton Korobeynikov 2007-06-03 08:15:16 PDT
Created attachment 994 [details]
bugpoint-reduced-simplified.bc
Comment 4 Chris Lattner 2007-06-04 17:25:06 PDT
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
Comment 5 Maarten ter Huurne 2007-06-04 21:15:13 PDT
I recompiled LLVM and its GCC with the patch and I can confirm that the bug is 
fixed. Thanks to you both!