Closed edwintorok closed 14 years ago
Ok, the problem is that some files #define NDEBUG, others don't, and if you link a file compiled with NDEBUG that includes boost/date_time/posix_time/posix_time.hpp, with one that includes it w/o defining NDEBUG then bad things happen.
With gcc at -O1 everything is fine, and the result is valgrind clean, however even with gcc at -O0 it segfaults if one files defines it, and the other one doesn't.
Now llvm-gcc at -O1 optimized things differently and preserved the bad behaviour.
Doesn't look like a bug in LLVM, sorry for the noise.
Is the problem that it calls terminate?
I don't see an invalid transformation here. It seems likely that gvn is exposing a codegen bug.
To see the bad output from the program: $ llvm-g++ api.i -o api.o $ llvm-g++ x.i -O1 -o x.o $ llvm-g++ x.o api.o $ ./a.out
^fails vs. works: $ llvm-g++ api.i -o api.o $ llvm-g++ x.i -O0 -o x.o $ llvm-g++ x.o api.o $ ./a.out
Extended Description
I have reduced the crash in luxconsole on startup with -O1, it is GVN's fault, it completely deletes the loads from %eh_*, thus causing a subsequent DSE pass to delete the stores too, which causes the program to crash on startup when this code is reached.
--- bugpoint-tooptimize.ll 2009-07-20 00:02:30.000000000 +0300
+++ opt.ll 2009-07-20 00:03:08.000000000 +0300
@@ -1,4 +1,4 @@
-; ModuleID = 'bugpoint-tooptimize.bc'
+; ModuleID = 'opt.bc'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
target triple = "x86_64-unknown-linux-gnu"
type { i64, i64 } ; type %0
@@ -1386,12 +1386,12 @@
define void @_Z6foobarv() {
entry:
%ss = alloca %"struct.std::basic_stringstream<char,std::char_traits
%td = alloca %"struct.boost::posix_time::time_duration" ; <%"struct.boost::posix_time::time_duration"*> [#uses=2]
%eh_selector = alloca i64 ; <i64> [#uses=3] [#uses=0] %td, i32 0, i32 0, i32 1, i64 0) [#uses=1]
%"alloca point" = bitcast i32 0 to i32 ;
call void @_ZN5boost10posix_time13time_durationC1Eiiil(%"struct.boost::posix_time::time_duration"
%0 = call i32 @_ZStorSt13_IosOpenmodeS(i32 16, i32 8) nounwind ;
@@ -1405,55 +1405,30 @@
invcont: ; preds = %entry,std::allocator >"* %ss)
call void @_ZNSt18basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev(%"struct.std::basic_stringstream<char,std::char_traits
-bb: ; preds = %ppad
-invcont1: ; preds = %bb
-bb2: ; preds = %ppad9
+invcont1: ; preds = %lpad
unreachable
-return: ; preds = %invcont
lpad: ; preds = %entry
store i8* %eh_ptr, i8** %eh_exception
-lpad5: ; preds = %bb
-ppad: ; preds = %lpad
-ppad9: ; preds = %lpad5
-Unwind: ; preds = %invcont1
To reproduce run: opt -gvn bugpoint-tooptimize.bc, and look at the output (see diff above), if you run -dse too, then the EH stuff is completely broken.
I have debugged this using bugpoint like so: bugpoint -Xlinker="-Wl,/tmp/api.o,-lstdc++" -safe-run-custom -run-custom -exec-command ./test2.sh -simplifycfg -domtree -domfrontier -mem2reg -instcombine -simplifycfg -simplify-libcalls -instcombine -jump-threading -simplifycfg -domtree -domfrontier -scalarrepl -instcombine -break-crit-edges -condprop -tailcallelim -simplifycfg -reassociate -domtree -loops -loopsimplify -domfrontier -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -lcssa -iv-users -indvars -loop-deletion -instcombine -memdep -gvn -memdep -memcpyopt -sccp -instcombine -break-crit-edges -condprop -domtree -memdep -dse -adce -simplifycfg -preverify -domtree -verify x.bc