Fix a codegen crash on void ?: reported by Oliver

llvm-svn: 44454
This commit is contained in:
Chris Lattner 2007-11-30 17:56:23 +00:00
parent aa0b570dfb
commit b6a7b582ee
3 changed files with 19 additions and 4 deletions

View 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);
}

View 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);

View 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;
}