[cfe-commits] r142047 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGenCXX/throw-expressions.cpp

Eli Friedman eli.friedman at gmail.com
Fri Oct 14 19:10:40 PDT 2011


Author: efriedma
Date: Fri Oct 14 21:10:40 2011
New Revision: 142047

URL: http://llvm.org/viewvc/llvm-project?rev=142047&view=rev
Log:
Handle an edge case involving the conditional operator and throw expressions.  PR10582.


Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/test/CodeGenCXX/throw-expressions.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=142047&r1=142046&r2=142047&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Oct 14 21:10:40 2011
@@ -2503,11 +2503,18 @@
     Expr *live = lhsExpr, *dead = rhsExpr;
     if (!CondExprBool) std::swap(live, dead);
 
-    // If the dead side doesn't have labels we need, and if the Live side isn't
-    // the gnu missing ?: extension (which we could handle, but don't bother
-    // to), just emit the Live part.
-    if (!CGF.ContainsLabel(dead))
-      return Visit(live);
+    // If the dead side doesn't have labels we need, just emit the Live part.
+    if (!CGF.ContainsLabel(dead)) {
+      Value *Result = Visit(live);
+
+      // If the live part is a throw expression, it acts like it has a void
+      // type, so evaluating it returns a null Value*.  However, a conditional
+      // with non-void type must return a non-null Value*.
+      if (!Result && !E->getType()->isVoidType())
+        Result = llvm::UndefValue::get(CGF.ConvertType(E->getType()));
+
+      return Result;
+    }
   }
 
   // OpenCL: If the condition is a vector, we can treat this condition like

Modified: cfe/trunk/test/CodeGenCXX/throw-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/throw-expressions.cpp?rev=142047&r1=142046&r2=142047&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/throw-expressions.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/throw-expressions.cpp Fri Oct 14 21:10:40 2011
@@ -13,3 +13,8 @@
 void test3() {
   throw false;
 }
+
+// PR10582
+int test4() {
+  return 1 ? throw val : val;
+}





More information about the cfe-commits mailing list