aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-09-15 16:35:24 +0000
committerAnders Carlsson <andersca@mac.com>2009-09-15 16:35:24 +0000
commit6fcec8b58d0571866fcb162db947b029cc539ec4 (patch)
treeec569b4fdf5542b0360daf27fb9c93cd52abfdb7 /lib/CodeGen
parentbf4ea56cdc376cef5a12abf6bf18dc34805c2226 (diff)
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
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGExpr.cpp43
-rw-r--r--lib/CodeGen/CodeGenFunction.h2
2 files changed, 39 insertions, 6 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 6ef004962c..699d7b16ec 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -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
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index cc7b0b0455..8629b6902e 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -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,