[cfe-commits] r64505 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/conditional-gnu-ext.c
Chris Lattner
sabre at nondot.org
Fri Feb 13 15:35:33 PST 2009
Author: lattner
Date: Fri Feb 13 17:35:32 2009
New Revision: 64505
URL: http://llvm.org/viewvc/llvm-project?rev=64505&view=rev
Log:
fix rdar://6586493, a bug in codegen of the GNU
missing-?:-true-value extension.
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGen/conditional-gnu-ext.c
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=64505&r1=64504&r2=64505&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Feb 13 17:35:32 2009
@@ -1270,20 +1270,30 @@
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);
Modified: cfe/trunk/test/CodeGen/conditional-gnu-ext.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/conditional-gnu-ext.c?rev=64505&r1=64504&r2=64505&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/conditional-gnu-ext.c (original)
+++ cfe/trunk/test/CodeGen/conditional-gnu-ext.c Fri Feb 13 17:35:32 2009
@@ -4,3 +4,9 @@
int foo(int x, short y) {
return x ?: y;
}
+
+// rdar://6586493
+float test(float x, int Y) {
+ return Y != 0 ? : x;
+}
+
More information about the cfe-commits
mailing list