[cfe-commits] r44454 - in /cfe/trunk: CodeGen/CGExpr.cpp CodeGen/CGExprScalar.cpp test/CodeGen/conditional.c
Chris Lattner
sabre at nondot.org
Fri Nov 30 09:56:23 PST 2007
Author: lattner
Date: Fri Nov 30 11:56:23 2007
New Revision: 44454
URL: http://llvm.org/viewvc/llvm-project?rev=44454&view=rev
Log:
Fix a codegen crash on void ?: reported by Oliver
Modified:
cfe/trunk/CodeGen/CGExpr.cpp
cfe/trunk/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGen/conditional.c
Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=44454&r1=44453&r2=44454&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Fri Nov 30 11:56:23 2007
@@ -492,6 +492,11 @@
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);
}
Modified: cfe/trunk/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprScalar.cpp?rev=44454&r1=44453&r2=44454&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Fri Nov 30 11:56:23 2007
@@ -912,6 +912,11 @@
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 @@
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);
Modified: cfe/trunk/test/CodeGen/conditional.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/conditional.c?rev=44454&r1=44453&r2=44454&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/conditional.c (original)
+++ cfe/trunk/test/CodeGen/conditional.c Fri Nov 30 11:56:23 2007
@@ -8,3 +8,10 @@
{
return cond ? a : b;
}
+
+void f();
+
+void test3(){
+ 1 ? f() : (void)0;
+}
+
More information about the cfe-commits
mailing list