]> granicus.if.org Git - clang/commitdiff
Correctly handle conditional operators involving throw.
authorEli Friedman <eli.friedman@gmail.com>
Mon, 7 Dec 2009 20:25:53 +0000 (20:25 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Mon, 7 Dec 2009 20:25:53 +0000 (20:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90800 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp
test/CodeGenCXX/throw-expressions.cpp [new file with mode: 0644]

index c1cbecc9fa857c6123b36de906d66f11b7b6489d..0ad139af4cd46e3f170e1d2ab9e630f6b3d45b36 100644 (file)
@@ -1868,10 +1868,11 @@ VisitConditionalOperator(const ConditionalOperator *E) {
 
   CGF.EmitBlock(ContBlock);
 
-  if (!LHS || !RHS) {
-    assert(E->getType()->isVoidType() && "Non-void value should have a value");
-    return 0;
-  }
+  // If the LHS or RHS is a throw expression, it will be legitimately null.
+  if (!LHS)
+    return RHS;
+  if (!RHS)
+    return LHS;
 
   // Create a PHI node for the real part.
   llvm::PHINode *PN = Builder.CreatePHI(LHS->getType(), "cond");
diff --git a/test/CodeGenCXX/throw-expressions.cpp b/test/CodeGenCXX/throw-expressions.cpp
new file mode 100644 (file)
index 0000000..7fe5563
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: clang-cc -emit-llvm-only -verify %s
+
+int val = 42;
+int& test1() {
+  return throw val, val;
+}
+
+int test2() {
+  return val ? throw val : val;
+}