<div dir="ltr">This is breaking tests on buildbots:<div><a href="http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_check/2279/" target="_blank" class="cremed">http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_check/2279/</a><br></div><div><br></div><div>Rolling back.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 25, 2015 at 5:05 AM, Nico Weber <span dir="ltr"><<a href="mailto:nicolasweber@gmx.de" target="_blank">nicolasweber@gmx.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: nico<br>
Date: Tue Feb 24 22:05:18 2015<br>
New Revision: 230460<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=230460&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=230460&view=rev</a><br>
Log:<br>
Produce less broken basic block sequences for __finally blocks.<br>
<br>
The way cleanups (such as PerformSEHFinally) get emitted is that codegen<br>
generates some initialization code, then calls the cleanup's Emit() with the<br>
insertion point set to a good place, then the cleanup is supposed to emit its<br>
stuff, and then codegen might tack in a jump or similar to where the insertion<br>
point is after the cleanup.<br>
<br>
The PerformSEHFinally cleanup tries to just stash away the block it's supposed<br>
to codegen into, and then does codegen later, into that stashed block.  However,<br>
after codegen'ing the __finally block, it used to set the insertion point to<br>
the finally's continuation block (where the __finally cleanup goes when its body<br>
is completed after regular, non-exceptional control flow).  That's not correct,<br>
as that block can (and generally does) already ends in a jump.  Instead,<br>
remember the insertion point that was current before the __finally got emitted,<br>
and restore that.<br>
<br>
Fixes two of the crashes in PR22553.<br>
<br>
Modified:<br>
    cfe/trunk/lib/CodeGen/CGException.cpp<br>
    cfe/trunk/test/CodeGen/exceptions-seh-finally.c<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGException.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=230460&r1=230459&r2=230460&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=230460&r1=230459&r2=230460&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGException.cpp Tue Feb 24 22:05:18 2015<br>
@@ -813,8 +813,8 @@ llvm::BasicBlock *CodeGenFunction::EmitL<br>
   bool hasFilter = false;<br>
   SmallVector<llvm::Value*, 4> filterTypes;<br>
   llvm::SmallPtrSet<llvm::Value*, 4> catchTypes;<br>
-  for (EHScopeStack::iterator I = EHStack.begin(), E = EHStack.end();<br>
-         I != E; ++I) {<br>
+  for (EHScopeStack::iterator I = EHStack.begin(), E = EHStack.end(); I != E;<br>
+       ++I) {<br>
<br>
     switch (I->getKind()) {<br>
     case EHScope::Cleanup:<br>
@@ -1927,6 +1927,7 @@ void CodeGenFunction::ExitSEHTryStmt(con<br>
     assert(FI.ContBB && "did not emit normal cleanup");<br>
<br>
     // Emit the code into FinallyBB.<br>
+    CGBuilderTy::InsertPoint SavedIP = Builder.saveIP();<br>
     Builder.SetInsertPoint(FI.FinallyBB);<br>
     EmitStmt(Finally->getBlock());<br>
<br>
@@ -1949,7 +1950,7 @@ void CodeGenFunction::ExitSEHTryStmt(con<br>
       Builder.CreateBr(FI.ContBB);<br>
     }<br>
<br>
-    Builder.SetInsertPoint(FI.ContBB);<br>
+    Builder.restoreIP(SavedIP);<br>
<br>
     return;<br>
   }<br>
<br>
Modified: cfe/trunk/test/CodeGen/exceptions-seh-finally.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exceptions-seh-finally.c?rev=230460&r1=230459&r2=230460&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exceptions-seh-finally.c?rev=230460&r1=230459&r2=230460&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGen/exceptions-seh-finally.c (original)<br>
+++ cfe/trunk/test/CodeGen/exceptions-seh-finally.c Tue Feb 24 22:05:18 2015<br>
@@ -160,3 +160,45 @@ void noreturn_finally() {<br>
 // CHECK-NEXT: cleanup<br>
 // CHECK: store i8 1, i8* %<br>
 // CHECK: br label %[[finally]]<br>
+<br>
+int finally_with_return() {<br>
+  __try {<br>
+    return 42;<br>
+  } __finally {<br>
+  }<br>
+}<br>
+// CHECK-LABEL: define i32 @finally_with_return()<br>
+// CHECK: store i8 0, i8* %<br>
+// CHECK-NEXT: br label %[[finally:[^ ]*]]<br>
+//<br>
+// CHECK: [[finally]]<br>
+// CHECK-NEXT: br label %[[finallycont:[^ ]*]]<br>
+//<br>
+// CHECK: [[finallycont]]<br>
+// CHECK-NEXT: ret i32 42<br>
+<br>
+int nested___finally___finally() {<br>
+  __try {<br>
+    __try {<br>
+    } __finally {<br>
+      return 1;<br>
+    }<br>
+  } __finally {<br>
+    // Intentionally no return here.<br>
+  }<br>
+  return 0;<br>
+}<br>
+// CHECK-LABEL: define i32 @nested___finally___finally<br>
+// CHECK: store i8 0, i8* %<br>
+// CHECK-NEXT: br label %[[finally:[^ ]*]]<br>
+//<br>
+// CHECK: [[finally]]<br>
+// CHECK-NEXT:  store i32 1, i32* %cleanup.dest.slot<br>
+// CHECK-NEXT:  store i8 0, i8* %abnormal.termination.slot<br>
+// CHECK-NEXT: br label %[[outerfinally:[^ ]*]]<br>
+//<br>
+// CHECK: [[outerfinally]]<br>
+// CHECK-NEXT: br label %[[finallycont:[^ ]*]]<br>
+//<br>
+// CHECK: [[finallycont]]<br>
+// CHECK-NEXT: ret i32 1<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>