[llvm-branch-commits] [cfe-branch] r181401 - Merging r181368:

Bill Wendling isanbard at gmail.com
Wed May 8 02:20:56 PDT 2013


Author: void
Date: Wed May  8 04:20:56 2013
New Revision: 181401

URL: http://llvm.org/viewvc/llvm-project?rev=181401&view=rev
Log:
Merging r181368:
------------------------------------------------------------------------
r181368 | rsmith | 2013-05-07 14:53:22 -0700 (Tue, 07 May 2013) | 3 lines

Don't crash in IRGen if a conditional with 'throw' in one of its branches is
used as a branch condition.

------------------------------------------------------------------------

Modified:
    cfe/branches/release_33/   (props changed)
    cfe/branches/release_33/lib/CodeGen/CGException.cpp
    cfe/branches/release_33/lib/CodeGen/CodeGenFunction.cpp
    cfe/branches/release_33/lib/CodeGen/CodeGenFunction.h
    cfe/branches/release_33/test/Analysis/MismatchedDeallocator-checker-test.mm   (props changed)
    cfe/branches/release_33/test/Analysis/NewDelete-checker-test.cpp   (props changed)
    cfe/branches/release_33/test/CodeGenCXX/throw-expressions.cpp
    cfe/branches/release_33/test/SemaCXX/warn-unreachable.cpp   (props changed)

Propchange: cfe/branches/release_33/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed May  8 04:20:56 2013
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:181299
+/cfe/trunk:181299,181368
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_33/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_33/lib/CodeGen/CGException.cpp?rev=181401&r1=181400&r2=181401&view=diff
==============================================================================
--- cfe/branches/release_33/lib/CodeGen/CGException.cpp (original)
+++ cfe/branches/release_33/lib/CodeGen/CGException.cpp Wed May  8 04:20:56 2013
@@ -419,14 +419,16 @@ llvm::Value *CodeGenFunction::getSelecto
   return Builder.CreateLoad(getEHSelectorSlot(), "sel");
 }
 
-void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E) {
+void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E,
+                                       bool KeepInsertionPoint) {
   if (!E->getSubExpr()) {
     EmitNoreturnRuntimeCallOrInvoke(getReThrowFn(CGM),
                                     ArrayRef<llvm::Value*>());
 
     // throw is an expression, and the expression emitters expect us
     // to leave ourselves at a valid insertion point.
-    EmitBlock(createBasicBlock("throw.cont"));
+    if (KeepInsertionPoint)
+      EmitBlock(createBasicBlock("throw.cont"));
 
     return;
   }
@@ -440,7 +442,8 @@ void CodeGenFunction::EmitCXXThrowExpr(c
     CGM.getObjCRuntime().EmitThrowStmt(*this, S, false);
     // This will clear insertion point which was not cleared in
     // call to EmitThrowStmt.
-    EmitBlock(createBasicBlock("throw.cont"));
+    if (KeepInsertionPoint)
+      EmitBlock(createBasicBlock("throw.cont"));
     return;
   }
   
@@ -478,7 +481,8 @@ void CodeGenFunction::EmitCXXThrowExpr(c
 
   // throw is an expression, and the expression emitters expect us
   // to leave ourselves at a valid insertion point.
-  EmitBlock(createBasicBlock("throw.cont"));
+  if (KeepInsertionPoint)
+    EmitBlock(createBasicBlock("throw.cont"));
 }
 
 void CodeGenFunction::EmitStartEHSpec(const Decl *D) {

Modified: cfe/branches/release_33/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_33/lib/CodeGen/CodeGenFunction.cpp?rev=181401&r1=181400&r2=181401&view=diff
==============================================================================
--- cfe/branches/release_33/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/branches/release_33/lib/CodeGen/CodeGenFunction.cpp Wed May  8 04:20:56 2013
@@ -928,6 +928,16 @@ void CodeGenFunction::EmitBranchOnBoolEx
     return;
   }
 
+  if (const CXXThrowExpr *Throw = dyn_cast<CXXThrowExpr>(Cond)) {
+    // Conditional operator handling can give us a throw expression as a
+    // condition for a case like:
+    //   br(c ? throw x : y, t, f) -> br(c, br(throw x, t, f), br(y, t, f)
+    // Fold this to:
+    //   br(c, throw x, br(y, t, f))
+    EmitCXXThrowExpr(Throw, /*KeepInsertionPoint*/false);
+    return;
+  }
+
   // Emit the code with the fully general case.
   llvm::Value *CondV = EvaluateExprAsBool(Cond);
   Builder.CreateCondBr(CondV, TrueBlock, FalseBlock);

Modified: cfe/branches/release_33/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_33/lib/CodeGen/CodeGenFunction.h?rev=181401&r1=181400&r2=181401&view=diff
==============================================================================
--- cfe/branches/release_33/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/branches/release_33/lib/CodeGen/CodeGenFunction.h Wed May  8 04:20:56 2013
@@ -2708,7 +2708,7 @@ public:
   }
   void enterNonTrivialFullExpression(const ExprWithCleanups *E);
 
-  void EmitCXXThrowExpr(const CXXThrowExpr *E);
+  void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint = true);
 
   void EmitLambdaExpr(const LambdaExpr *E, AggValueSlot Dest);
 

Propchange: cfe/branches/release_33/test/Analysis/MismatchedDeallocator-checker-test.mm
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed May  8 04:20:56 2013
@@ -1,3 +1,4 @@
 /cfe/branches/type-system-rewrite/test/Analysis/alloc-match-dealloc.mm:134693-134817
+/cfe/trunk/test/Analysis/MismatchedDeallocator-checker-test.mm:181368
 /cfe/trunk/test/SemaTemplate/test/Analysis/alloc-match-dealloc.mm:126920
 /cfe/trunk/test/test/Analysis/alloc-match-dealloc.mm:170344

Propchange: cfe/branches/release_33/test/Analysis/NewDelete-checker-test.cpp
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed May  8 04:20:56 2013
@@ -1,3 +1,4 @@
 /cfe/branches/type-system-rewrite/test/Analysis/NewDelete-checker-test.mm:134693-134817
+/cfe/trunk/test/Analysis/NewDelete-checker-test.cpp:181368
 /cfe/trunk/test/SemaTemplate/test/Analysis/NewDelete-checker-test.mm:126920
 /cfe/trunk/test/test/Analysis/NewDelete-checker-test.mm:170344

Modified: cfe/branches/release_33/test/CodeGenCXX/throw-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_33/test/CodeGenCXX/throw-expressions.cpp?rev=181401&r1=181400&r2=181401&view=diff
==============================================================================
--- cfe/branches/release_33/test/CodeGenCXX/throw-expressions.cpp (original)
+++ cfe/branches/release_33/test/CodeGenCXX/throw-expressions.cpp Wed May  8 04:20:56 2013
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -emit-llvm-only -verify %s -Wno-unreachable-code
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -Wno-unreachable-code -Werror -emit-llvm -o - %s | FileCheck %s
 // expected-no-diagnostics
 
 int val = 42;
@@ -19,3 +19,28 @@ void test3() {
 int test4() {
   return 1 ? throw val : val;
 }
+
+// PR15923
+int test5(bool x, bool y, int z) {
+  return (x ? throw 1 : y) ? z : throw 2;
+}
+// CHECK: define i32 @_Z5test5bbi(
+// CHECK: br i1
+//
+// x.true:
+// CHECK: call void @__cxa_throw(
+// CHECK-NEXT: unreachable
+//
+// x.false:
+// CHECK: br i1
+//
+// y.true:
+// CHECK: load i32*
+// CHECK: br label
+//
+// y.false:
+// CHECK: call void @__cxa_throw(
+// CHECK-NEXT: unreachable
+//
+// end:
+// CHECK: ret i32

Propchange: cfe/branches/release_33/test/SemaCXX/warn-unreachable.cpp
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed May  8 04:20:56 2013
@@ -1,2 +1,2 @@
 /cfe/branches/type-system-rewrite/test/SemaCXX/warn-unreachable.cpp:134693-134817
-/cfe/trunk/test/SemaCXX/warn-unreachable.cpp:121961
+/cfe/trunk/test/SemaCXX/warn-unreachable.cpp:121961,181368





More information about the llvm-branch-commits mailing list