]> granicus.if.org Git - clang/commitdiff
Fix a codegen crash on void ?: reported by Oliver
authorChris Lattner <sabre@nondot.org>
Fri, 30 Nov 2007 17:56:23 +0000 (17:56 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 30 Nov 2007 17:56:23 +0000 (17:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44454 91177308-0d34-0410-b5e6-96231b3b80d8

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

index f9a00ebfee3d73ad69eb99f409683e5e451abf8b..8fcc94805ac3952be902e03e04c2645becec8e24 100644 (file)
@@ -492,6 +492,11 @@ RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, const CallExpr *E) {
   else if (hasAggregateLLVMType(E->getType()))
     // Struct return.
     return RValue::getAggregate(Args[0]);
+  else {
+    // void return.
+    assert(E->getType()->isVoidType() && "Should only have a void expr here");
+    V = 0;
+  }
       
   return RValue::get(V);
 }
index f0a75dbf136656afd9db5ae345367b140964a818..37389dcd4475067ccbb21e629a62b500e807c266 100644 (file)
@@ -912,6 +912,11 @@ VisitConditionalOperator(const ConditionalOperator *E) {
   
   CGF.EmitBlock(ContBlock);
   
+  if (!LHS) {
+    assert(E->getType()->isVoidType() && "Non-void value should have a value");
+    return 0;
+  }
+  
   // Create a PHI node for the real part.
   llvm::PHINode *PN = Builder.CreatePHI(LHS->getType(), "cond");
   PN->reserveOperandSpace(2);
@@ -926,16 +931,14 @@ Value *ScalarExprEmitter::VisitChooseExpr(ChooseExpr *E) {
     Visit(E->isConditionTrue(CGF.getContext()) ? E->getLHS() : E->getRHS());
 }
 
-Value *ScalarExprEmitter::VisitVAArgExpr(VAArgExpr *VE)
-{
+Value *ScalarExprEmitter::VisitVAArgExpr(VAArgExpr *VE) {
   llvm::Value *ArgValue = EmitLValue(VE->getSubExpr()).getAddress();
 
   llvm::Value *V = Builder.CreateVAArg(ArgValue, ConvertType(VE->getType()));  
   return V;
 }
 
-Value *ScalarExprEmitter::VisitObjCEncodeExpr(const ObjCEncodeExpr *E)
-{
+Value *ScalarExprEmitter::VisitObjCEncodeExpr(const ObjCEncodeExpr *E) {
   std::string str;
   
   CGF.getContext().getObjcEncodingForType(E->getEncodedType(), str);
index 57a0be1b1057991c09af85099ecad889f0646238..15359e0c8ac183e809a809d2f513ae992d8b1fdc 100644 (file)
@@ -8,3 +8,10 @@ double test2(int cond, float a, double b)
 {
   return cond ? a : b;
 }
+
+void f();
+
+void test3(){
+   1 ? f() : (void)0;
+}
+