diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-02-13 23:35:32 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-02-13 23:35:32 +0000 |
| commit | cd7bc144f6ff20061c13a13d21bfce2b16340f09 (patch) | |
| tree | 6463f169b037426ea3ee963f141543449e564877 /clang/lib/CodeGen/CGExprScalar.cpp | |
| parent | b9063fc1b344e8112e52223f7914837ba8d0a021 (diff) | |
fix rdar://6586493, a bug in codegen of the GNU
missing-?:-true-value extension.
llvm-svn: 64505
Diffstat (limited to 'clang/lib/CodeGen/CGExprScalar.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGExprScalar.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 962c2ebaccbd..164d57eb715d 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -1270,20 +1270,30 @@ VisitConditionalOperator(const ConditionalOperator *E) { llvm::BasicBlock *ContBlock = CGF.createBasicBlock("cond.end"); 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) { + // If we don't have the GNU missing condition extension, emit a branch on + // bool the normal way. + if (E->getLHS()) { + // Otherwise, just use EmitBranchOnBoolExpr to get small and simple code for + // the branch on bool. + CGF.EmitBranchOnBoolExpr(E->getCond(), LHSBlock, RHSBlock); + } else { + // Otherwise, for the ?: 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 ?:. CondVal = CGF.EmitScalarExpr(E->getCond()); + + // In some cases, EmitScalarConversion will delete the "CondVal" expression + // if there are no extra uses (an optimization). Inhibit this by making an + // extra dead use, because we're going to add a use of CondVal later. We + // don't use the builder for this, because we don't want it to get optimized + // away. This leaves dead code, but the ?: extension isn't common. + new llvm::BitCastInst(CondVal, CondVal->getType(), "dummy?:holder", + Builder.GetInsertBlock()); + 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); |
