]> granicus.if.org Git - clang/commitdiff
Fix an edge case in IRGen for conditionals. PR11509.
authorEli Friedman <eli.friedman@gmail.com>
Thu, 8 Dec 2011 22:01:56 +0000 (22:01 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 8 Dec 2011 22:01:56 +0000 (22:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146189 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp
test/CodeGen/conditional.c

index 3fc5c7b015cff9e6a54b09e007843e39e8def08b..d556cdfd467b2d4cf23651c939f877d4e5884169 100644 (file)
@@ -2566,6 +2566,11 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
     llvm::Value *CondV = CGF.EvaluateExprAsBool(condExpr);
     llvm::Value *LHS = Visit(lhsExpr);
     llvm::Value *RHS = Visit(rhsExpr);
+    if (!LHS) {
+      // If the conditional has void type, make sure we return a null Value*.
+      assert(!RHS && "LHS and RHS types must match");
+      return 0;
+    }
     return Builder.CreateSelect(CondV, LHS, RHS, "cond");
   }
 
index 15e15f11e35fd9a04494eec5cc58671bca7833ef..88538a2042a764627dbf35b1aea4e9ade67bd55f 100644 (file)
@@ -66,3 +66,9 @@ int test11(int c) {
 double test12(int c) {
   return c ? 4.0 : 2.0;
 }
+// CHECK: @test13
+// CHECK: call {{.*}} @f2(
+int f2(void);
+void test13() {
+  f2() ? (void)0 : (void)0;
+}