[cfe-commits] r146189 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/conditional.c

Eli Friedman eli.friedman at gmail.com
Thu Dec 8 14:01:57 PST 2011


Author: efriedma
Date: Thu Dec  8 16:01:56 2011
New Revision: 146189

URL: http://llvm.org/viewvc/llvm-project?rev=146189&view=rev
Log:
Fix an edge case in IRGen for conditionals.  PR11509.

Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/test/CodeGen/conditional.c

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=146189&r1=146188&r2=146189&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu Dec  8 16:01:56 2011
@@ -2566,6 +2566,11 @@
     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");
   }
 

Modified: cfe/trunk/test/CodeGen/conditional.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/conditional.c?rev=146189&r1=146188&r2=146189&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/conditional.c (original)
+++ cfe/trunk/test/CodeGen/conditional.c Thu Dec  8 16:01:56 2011
@@ -66,3 +66,9 @@
 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;
+}





More information about the cfe-commits mailing list