[llvm-branch-commits] [llvm-branch] r136067 - in /llvm/branches/exception-handling-rewrite: lib/VMCore/Verifier.cpp test/Feature/exceptionhandling.ll

Bill Wendling isanbard at gmail.com
Tue Jul 26 02:14:20 PDT 2011


Author: void
Date: Tue Jul 26 04:14:20 2011
New Revision: 136067

URL: http://llvm.org/viewvc/llvm-project?rev=136067&view=rev
Log:
Add verification that:

1. The landing pad block (which is defined as a block containing a landingpad
   instruction) can be jumped to only by the unwind edge of an invoke.
2. The landingpad instruction must be the first non-PHI instruction in the
   block.

Added:
    llvm/branches/exception-handling-rewrite/test/Feature/exceptionhandling.ll
Modified:
    llvm/branches/exception-handling-rewrite/lib/VMCore/Verifier.cpp

Modified: llvm/branches/exception-handling-rewrite/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/VMCore/Verifier.cpp?rev=136067&r1=136066&r2=136067&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/VMCore/Verifier.cpp (original)
+++ llvm/branches/exception-handling-rewrite/lib/VMCore/Verifier.cpp Tue Jul 26 04:14:20 2011
@@ -35,6 +35,10 @@
 //  * It is illegal to have a ret instruction that returns a value that does not
 //    agree with the function return value type.
 //  * Function call argument types match the function prototype
+//  * A landing pad is defined by a landingpad instruction, and can be jumped to
+//    only by the unwind edge of an invoke instruction.
+//  * A landingpad instruction must be the first non-PHI instruction in the
+//    block.
 //  * All other things that are tested by asserts spread about the code...
 //
 //===----------------------------------------------------------------------===//
@@ -282,6 +286,7 @@
     void visitAllocaInst(AllocaInst &AI);
     void visitExtractValueInst(ExtractValueInst &EVI);
     void visitInsertValueInst(InsertValueInst &IVI);
+    void visitLandingPadInst(LandingPadInst &LPI);
 
     void VerifyCallSite(CallSite CS);
     bool PerformTypeCheck(Intrinsic::ID ID, Function *F, Type *Ty,
@@ -1321,7 +1326,7 @@
   Assert1(Ordering == Acquire || Ordering == Release ||
           Ordering == AcquireRelease || Ordering == SequentiallyConsistent,
           "fence instructions may only have "
-          " acquire, release, acq_rel, or seq_cst ordering.", &FI);
+          "acquire, release, acq_rel, or seq_cst ordering.", &FI);
   visitInstruction(FI);
 }
 
@@ -1343,6 +1348,30 @@
   visitInstruction(IVI);
 }
 
+void Verifier::visitLandingPadInst(LandingPadInst &LPI) {
+  BasicBlock *BB = LPI.getParent();
+
+  // The landingpad instruction defines is parent as a landing pad block. The
+  // landing pad block may be branched to only by the unwind edge of an invoke.
+  for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
+    const InvokeInst *II = dyn_cast<InvokeInst>((*I)->getTerminator());
+    Assert1(II && II->getUnwindDest() == BB,
+            "Block containing LandingPadInst must be jumped to "
+            "only by the unwind edge of an invoke.", &LPI);
+  }
+
+  // The landingpad instruction must be the first non-PHI instruction in the
+  // block.
+  BasicBlock::iterator I = BB->begin(), E = BB->end();
+  while (I != E && isa<PHINode>(I))
+    ++I;
+  Assert1(I != E && isa<LandingPadInst>(I) && I == LPI,
+          "LandingPadInst not the first non-PHI instruction in the block.",
+          &LPI);
+
+  visitInstruction(LPI);
+}
+
 /// verifyInstruction - Verify that an instruction is well formed.
 ///
 void Verifier::visitInstruction(Instruction &I) {

Added: llvm/branches/exception-handling-rewrite/test/Feature/exceptionhandling.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/test/Feature/exceptionhandling.ll?rev=136067&view=auto
==============================================================================
--- llvm/branches/exception-handling-rewrite/test/Feature/exceptionhandling.ll (added)
+++ llvm/branches/exception-handling-rewrite/test/Feature/exceptionhandling.ll Tue Jul 26 04:14:20 2011
@@ -0,0 +1,54 @@
+; RUN: llvm-as < %s | llvm-dis > %t1.ll
+; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
+; RUN: diff %t1.ll %t2.ll
+
+ at _ZTIc = external constant i8*
+ at _ZTId = external constant i8*
+ at _ZTIPKc = external constant i8*
+ at .str = private unnamed_addr constant [16 x i8] c"caught char %c\0A\00", align 1
+
+define void @_Z3barv() uwtable optsize alwaysinline ssp {
+entry:
+  invoke void @_Z3quxv() optsize
+          to label %try.cont unwind label %lpad
+
+invoke.cont4:                                     ; preds = %lpad
+  %eh.obj = extractvalue {i8*, i32} %exn, 0
+  %tmp0 = tail call i8* @__cxa_begin_catch(i8* %eh.obj) nounwind
+  %exn.scalar = load i8* %tmp0, align 1
+  %conv = sext i8 %exn.scalar to i32
+  %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([16 x i8]* @.str, i64 0, i64 0), i32 %conv) optsize
+  tail call void @__cxa_end_catch() nounwind
+  br label %try.cont
+
+try.cont:                                         ; preds = %entry, %invoke.cont4
+  ret void
+
+lpad:                                             ; preds = %entry
+  %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+            cleanup
+            catch i8** @_ZTIc
+            filter i8** @_ZTIPKc
+            catch i8** @_ZTId
+  %tmp1 = extractvalue {i8*, i32} %exn, 1
+  %tmp2 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIc to i8*)) nounwind
+  %tmp3 = icmp eq i32 %tmp1, %tmp2
+  br i1 %tmp3, label %invoke.cont4, label %eh.resume
+
+eh.resume:
+  resume { i8*, i32 } %exn
+}
+
+declare void @_Z3quxv() optsize
+
+declare i32 @__gxx_personality_v0(...)
+
+declare i32 @llvm.eh.typeid.for(i8*) nounwind
+
+declare void @llvm.eh.resume(i8*, i32)
+
+declare i8* @__cxa_begin_catch(i8*)
+
+declare i32 @printf(i8* nocapture, ...) nounwind optsize
+
+declare void @__cxa_end_catch()





More information about the llvm-branch-commits mailing list