llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.16k stars 10.69k forks source link

GVN: deletes call to _Unwind_Resume causing C++ programs with EH to crash #4960

Closed edwintorok closed 14 years ago

edwintorok commented 14 years ago
Bugzilla Link 4588
Resolution INVALID
Resolved on Jul 20, 2009 02:15
Version unspecified
OS Linux
Blocks llvm/llvm-project#4957
Attachments bugpoint-tooptimize.bc, x.bc, api.i
CC @asl,@lattner

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:

-bb2: ; preds = %ppad9

-return: ; preds = %invcont

-lpad5: ; preds = %bb

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

edwintorok commented 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.

llvmbot commented 14 years ago

Is the problem that it calls terminate?

lattner commented 14 years ago

I don't see an invalid transformation here. It seems likely that gvn is exposing a codegen bug.

edwintorok commented 14 years ago

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