Hi,<div><br></div><div>I'm trying to compile an llvm program which makes use of exception handling. While compiling the code with llc i get the following assertion failure</div><div><br></div><div><div>llc: FunctionLoweringInfo.cpp:163: void llvm::FunctionLoweringInfo::clear(): Assertion `CatchInfoFound.size() == CatchInfoLost.size() && "Not all catch info was assigned to a landing pad!"' failed.</div>
<div>0  llc             0x0000000000d5d23f</div><div>1  llc             0x0000000000d5f026</div><div>2  libpthread.so.0 0x00007f47688d38f0</div><div>3  libc.so.6       0x00007f4767bc3a75 gsignal + 53</div><div>4  libc.so.6       0x00007f4767bc75c0 abort + 384</div>
<div>5  libc.so.6       0x00007f4767bbc941 __assert_fail + 241</div><div>6  llc             0x00000000008a5a19 llvm::FunctionLoweringInfo::clear() + 1353</div><div>7  llc             0x00000000009364de llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 3102</div>
<div>8  llc             0x0000000000ce828f llvm::FPPassManager::runOnFunction(llvm::Function&) + 671</div><div>9  llc             0x0000000000ce834b llvm::FPPassManager::runOnModule(llvm::Module&) + 75</div><div>10 llc             0x0000000000ce7d84 llvm::MPPassManager::runOnModule(llvm::Module&) + 564</div>
<div>11 llc             0x0000000000ce7ee0 llvm::PassManagerImpl::run(llvm::Module&) + 160</div><div>12 llc             0x0000000000565941 main + 3009</div><div>13 libc.so.6       0x00007f4767baec4d __libc_start_main + 253</div>
<div>14 llc             0x0000000000563849</div><div>Stack dump:</div><div>0.<span class="Apple-tab-span" style="white-space:pre">      </span>Program arguments: llc b.bc </div><div>1.<span class="Apple-tab-span" style="white-space:pre">       </span>Running pass 'Function Pass Manager' on module 'b.bc'.</div>
<div>2.<span class="Apple-tab-span" style="white-space:pre">    </span>Running pass 'X86 DAG->DAG Instruction Selection' on function '@main'</div><div>Aborted</div></div><div><br></div><div>I only get this error when the b.bc file is generated with opt -O3. The program compiles and executes just fine with opt -O2. I was able to find out the minimum number of optimization passes that cause this crash. They are</div>
<div><br></div><div>opt -inline -jump-threading -instcombine -licm -loop-unswitch -o b.bc a.bc</div><div><br></div><div>I'm attaching the original unoptimized file a.bc.gz and the optimized version b.bc.gz. I apologize for sending in such large files, but I just couldn't reproduce this problem with smaller programs. By putting some debug statements in llc I was able to narrow the problem in b.bc down to following lines of code</div>
<div><br></div><div><div>Unwind.i74.i.i:                                   ; preds = %normal44.i79.i.i</div><div>  %153 = call i8* @llvm.eh.exception()            ; <i8*> [#uses=2]</div><div>  %154 = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %153, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*),</div>
<div> i8* null) ; <i32> [#uses=0]</div><div>  invoke void @_Unwind_Resume_or_Rethrow(i8* %153)</div><div>          to label %.noexc83.i.i unwind label %lpad51.preheader.i.i</div><div><br></div><div>lpad51.preheader.i.i:                             ; preds = %Unwind.i74.i.i, %Unwind.i61.i.i</div>
<div>  %155 = icmp eq i8* %58, null                    ; <i1> [#uses=1]</div><div>  %156 = bitcast i8* %61 to %File*                ; <%File*> [#uses=1]</div><div>  br i1 %155, label %Unwind.loopexit.us-lcssa.us.i.i, label %normal31.i.i.i</div>
<div><br></div><div>Unwind.loopexit.us-lcssa.us.i.i:                  ; preds = %lpad51.preheader.i.i</div><div>  %157 = call i8* @llvm.eh.exception()            ; <i8*> [#uses=2]</div><div>  %158 = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %157, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* null) ; <i32> [#uses=0]</div>
<div>  br label %Unwind.i.i</div></div><div><br></div><div><br></div><div>The Unwind.loopexit.us-lcssa.us.i.i landing pad gets added to CatchInfoLost but not to CatchInfoFound which causes the assertion to fail. I have also attached the output from bugpoint -run-llc b.bc</div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br></div><div>Is there something wrong with the original ll code I am generating?</div><div><br></div><div>I will be glad to provide more information.</div>
<div><br></div><div>Thanks,</div><div>Shivram</div>