[cfe-commits] r114457 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/gnu-conditional-scalar-ext.cpp
Fariborz Jahanian
fjahanian at apple.com
Tue Sep 21 11:32:21 PDT 2010
Author: fjahanian
Date: Tue Sep 21 13:32:21 2010
New Revision: 114457
URL: http://llvm.org/viewvc/llvm-project?rev=114457&view=rev
Log:
IRgen for gnu extension's conditional lvalue expression
with missing LHS. radar 8453812. Executable test is checked
into llvm test suite.
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGenCXX/gnu-conditional-scalar-ext.cpp
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=114457&r1=114456&r2=114457&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Sep 21 13:32:21 2010
@@ -495,6 +495,11 @@
/// length type, this is not possible.
///
LValue CodeGenFunction::EmitLValue(const Expr *E) {
+ llvm::DenseMap<const Expr *, LValue>::iterator I =
+ CGF.ConditionalSaveLValueExprs.find(E);
+ if (I != CGF.ConditionalSaveLValueExprs.end())
+ return I->second;
+
switch (E->getStmtClass()) {
default: return EmitUnsupportedLValue(E, "l-value expression");
@@ -1694,19 +1699,26 @@
return EmitLValue(Live);
}
- if (!E->getLHS())
- return EmitUnsupportedLValue(E, "conditional operator with missing LHS");
-
llvm::BasicBlock *LHSBlock = createBasicBlock("cond.true");
llvm::BasicBlock *RHSBlock = createBasicBlock("cond.false");
llvm::BasicBlock *ContBlock = createBasicBlock("cond.end");
- EmitBranchOnBoolExpr(E->getCond(), LHSBlock, RHSBlock);
+ if (E->getLHS())
+ EmitBranchOnBoolExpr(E->getCond(), LHSBlock, RHSBlock);
+ else {
+ Expr *save = E->getSAVE();
+ assert(save && "VisitConditionalOperator - save is null");
+ // Intentianlly not doing direct assignment to ConditionalSaveExprs[save]
+ LValue SaveVal = EmitLValue(save);
+ ConditionalSaveLValueExprs[save] = SaveVal;
+ EmitBranchOnBoolExpr(E->getCond(), LHSBlock, RHSBlock);
+ }
// Any temporaries created here are conditional.
BeginConditionalBranch();
EmitBlock(LHSBlock);
- LValue LHS = EmitLValue(E->getLHS());
+ LValue LHS = EmitLValue(E->getTrueExpr());
+
EndConditionalBranch();
if (!LHS.isSimple())
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=114457&r1=114456&r2=114457&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Sep 21 13:32:21 2010
@@ -517,6 +517,7 @@
/// extension's missing LHS expression in a conditional operator expression.
llvm::DenseMap<const Expr *, llvm::Value *> ConditionalSaveExprs;
llvm::DenseMap<const Expr *, ComplexPairTy> ConditionalSaveComplexExprs;
+ llvm::DenseMap<const Expr *, LValue> ConditionalSaveLValueExprs;
EHScopeStack EHStack;
Modified: cfe/trunk/test/CodeGenCXX/gnu-conditional-scalar-ext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/gnu-conditional-scalar-ext.cpp?rev=114457&r1=114456&r2=114457&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/gnu-conditional-scalar-ext.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/gnu-conditional-scalar-ext.cpp Tue Sep 21 13:32:21 2010
@@ -39,8 +39,25 @@
return getComplex(1+2i) ? : rhs;
}
+// lvalue test
+void foo (int& lv) {
+ ++lv;
+}
+
+int global = 1;
+
+int &cond() {
+ static int count;
+ if (count++)
+ abort();
+ return global;
+}
+
+
int main() {
cmplx();
- return 0;
+ int rhs = 10;
+ foo (cond()? : rhs);
+ return global-2;
}
}
More information about the cfe-commits
mailing list