Code generation of Conditional operators that are lvalues (but that aren't bitfields).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81867 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anders Carlsson 2009-09-15 16:35:24 +00:00
Родитель bf4ea56cdc
Коммит 6fcec8b58d
2 изменённых файлов: 39 добавлений и 6 удалений

Просмотреть файл

@ -246,7 +246,7 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
case Expr::CompoundLiteralExprClass:
return EmitCompoundLiteralLValue(cast<CompoundLiteralExpr>(E));
case Expr::ConditionalOperatorClass:
return EmitConditionalOperator(cast<ConditionalOperator>(E));
return EmitConditionalOperatorLValue(cast<ConditionalOperator>(E));
case Expr::ChooseExprClass:
return EmitLValue(cast<ChooseExpr>(E)->getChosenSubExpr(getContext()));
case Expr::ImplicitCastExprClass:
@ -1135,10 +1135,44 @@ LValue CodeGenFunction::EmitCompoundLiteralLValue(const CompoundLiteralExpr* E){
return Result;
}
LValue CodeGenFunction::EmitConditionalOperator(const ConditionalOperator* E) {
if (E->isLvalue(getContext()) == Expr::LV_Valid)
return EmitUnsupportedLValue(E, "conditional operator");
LValue
CodeGenFunction::EmitConditionalOperatorLValue(const ConditionalOperator* E) {
if (E->isLvalue(getContext()) == Expr::LV_Valid) {
llvm::BasicBlock *LHSBlock = createBasicBlock("cond.true");
llvm::BasicBlock *RHSBlock = createBasicBlock("cond.false");
llvm::BasicBlock *ContBlock = createBasicBlock("cond.end");
llvm::Value *Cond = EvaluateExprAsBool(E->getCond());
Builder.CreateCondBr(Cond, LHSBlock, RHSBlock);
EmitBlock(LHSBlock);
LValue LHS = EmitLValue(E->getLHS());
if (!LHS.isSimple())
return EmitUnsupportedLValue(E, "conditional operator");
llvm::Value *Temp = CreateTempAlloca(LHS.getAddress()->getType(),
"condtmp");
Builder.CreateStore(LHS.getAddress(), Temp);
EmitBranch(ContBlock);
EmitBlock(RHSBlock);
LValue RHS = EmitLValue(E->getRHS());
if (!RHS.isSimple())
return EmitUnsupportedLValue(E, "conditional operator");
Builder.CreateStore(RHS.getAddress(), Temp);
EmitBranch(ContBlock);
EmitBlock(ContBlock);
Temp = Builder.CreateLoad(Temp, "lv");
return LValue::MakeAddr(Temp, E->getType().getCVRQualifiers(),
getContext().getObjCGCAttrKind(E->getType()),
E->getType().getAddressSpace());
}
// ?: here should be an aggregate.
assert((hasAggregateLLVMType(E->getType()) &&
!E->getType()->isAnyComplexType()) &&
@ -1150,7 +1184,6 @@ LValue CodeGenFunction::EmitConditionalOperator(const ConditionalOperator* E) {
return LValue::MakeAddr(Temp, E->getType().getCVRQualifiers(),
getContext().getObjCGCAttrKind(E->getType()),
E->getType().getAddressSpace());
}
/// EmitCastLValue - Casts are never lvalues. If a cast is needed by the code

Просмотреть файл

@ -794,7 +794,7 @@ public:
LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
LValue EmitMemberExpr(const MemberExpr *E);
LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
LValue EmitConditionalOperator(const ConditionalOperator *E);
LValue EmitConditionalOperatorLValue(const ConditionalOperator *E);
LValue EmitCastLValue(const CastExpr *E);
llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,