aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGExprScalar.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index e64ae9ddce..8097e58614 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -1129,14 +1129,23 @@ VisitConditionalOperator(const ConditionalOperator *E) {
llvm::BasicBlock *LHSBlock = CGF.createBasicBlock("cond.?");
llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("cond.:");
llvm::BasicBlock *ContBlock = CGF.createBasicBlock("cond.cont");
-
- // Evaluate the conditional, then convert it to bool. We do this explicitly
- // because we need the unconverted value if this is a GNU ?: expression with
- // missing middle value.
- Value *CondVal = CGF.EmitScalarExpr(E->getCond());
- Value *CondBoolVal =CGF.EmitScalarConversion(CondVal, E->getCond()->getType(),
- CGF.getContext().BoolTy);
- Builder.CreateCondBr(CondBoolVal, LHSBlock, RHSBlock);
+ Value *CondVal = 0;
+
+ // If we have the GNU missing condition extension, evaluate the conditional
+ // and then convert it to bool the hard way. We do this explicitly
+ // because we need the unconverted value for the missing middle value of
+ // the ?:.
+ if (E->getLHS() == 0) {
+ CondVal = CGF.EmitScalarExpr(E->getCond());
+ Value *CondBoolVal =
+ CGF.EmitScalarConversion(CondVal, E->getCond()->getType(),
+ CGF.getContext().BoolTy);
+ Builder.CreateCondBr(CondBoolVal, LHSBlock, RHSBlock);
+ } else {
+ // Otherwise, just use EmitBranchOnBoolExpr to get small and simple code for
+ // the branch on bool.
+ CGF.EmitBranchOnBoolExpr(E->getCond(), LHSBlock, RHSBlock);
+ }
CGF.EmitBlock(LHSBlock);