aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprComplex.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2012-03-10 03:05:10 +0000
committerJohn McCall <rjmccall@apple.com>2012-03-10 03:05:10 +0000
commitdd2ecee313b558a9b621ec003b45e0fbc83508d7 (patch)
treed071b135e22daff2be22ca0e14c4af47a4952820 /lib/CodeGen/CGExprComplex.cpp
parent89da8cf16b671845660711d3dd4174a809ca6cca (diff)
Unify the BlockDeclRefExpr and DeclRefExpr paths so that
we correctly emit loads of BlockDeclRefExprs even when they don't qualify as ODR-uses. I think I'm adequately convinced that BlockDeclRefExpr can die. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152479 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprComplex.cpp')
-rw-r--r--lib/CodeGen/CGExprComplex.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/CodeGen/CGExprComplex.cpp b/lib/CodeGen/CGExprComplex.cpp
index d2a760054b..7be88440ff 100644
--- a/lib/CodeGen/CGExprComplex.cpp
+++ b/lib/CodeGen/CGExprComplex.cpp
@@ -111,8 +111,24 @@ public:
}
// l-values.
- ComplexPairTy VisitDeclRefExpr(const Expr *E) { return EmitLoadOfLValue(E); }
- ComplexPairTy VisitBlockDeclRefExpr(const Expr *E) { return EmitLoadOfLValue(E); }
+ ComplexPairTy emitDeclRef(ValueDecl *VD, Expr *refExpr) {
+ if (CodeGenFunction::ConstantEmission result
+ = CGF.tryEmitAsConstant(VD, refExpr)) {
+ if (result.isReference())
+ return EmitLoadOfLValue(result.getReferenceLValue(CGF, refExpr));
+
+ llvm::ConstantStruct *pair =
+ cast<llvm::ConstantStruct>(result.getValue());
+ return ComplexPairTy(pair->getOperand(0), pair->getOperand(1));
+ }
+ return EmitLoadOfLValue(refExpr);
+ }
+ ComplexPairTy VisitDeclRefExpr(DeclRefExpr *E) {
+ return emitDeclRef(E->getDecl(), E);
+ }
+ ComplexPairTy VisitBlockDeclRefExpr(BlockDeclRefExpr *E) {
+ return emitDeclRef(E->getDecl(), E);
+ }
ComplexPairTy VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
return EmitLoadOfLValue(E);
}