]> granicus.if.org Git - clang/commitdiff
Handle an edge case involving the conditional operator and throw expressions. PR10582.
authorEli Friedman <eli.friedman@gmail.com>
Sat, 15 Oct 2011 02:10:40 +0000 (02:10 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 15 Oct 2011 02:10:40 +0000 (02:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142047 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp
test/CodeGenCXX/throw-expressions.cpp

index 3a9fbeed9d69878186d21e5b6c074d5b9e91f129..b088103aa352383a15ea659d88a79941fcb47eef 100644 (file)
@@ -2503,11 +2503,18 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
     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
index 0fd32c44575bfe395d3df498864a36a9d68b586d..2515acb48ee726e62a32857c99931e45500a5c08 100644 (file)
@@ -13,3 +13,8 @@ int test2() {
 void test3() {
   throw false;
 }
+
+// PR10582
+int test4() {
+  return 1 ? throw val : val;
+}