From 1bf9a9e6a5bdc0de7939908855dcddf46b661800 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 12 Nov 2011 22:28:03 +0000 Subject: Represent an APValue based on a Decl as that Decl, rather than a DeclRefExpr or MemberExpr which refers to it. As a side-effect, MemberExprs which refer to static member functions and static data members are now emitted as constant expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144468 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprConstant.cpp | 45 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'lib/CodeGen/CGExprConstant.cpp') diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index fc87873687..819fc3fa08 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -843,25 +843,8 @@ public: } public: - llvm::Constant *EmitLValue(Expr *E) { - switch (E->getStmtClass()) { - default: break; - case Expr::CompoundLiteralExprClass: { - // Note that due to the nature of compound literals, this is guaranteed - // to be the only use of the variable, so we just generate it here. - CompoundLiteralExpr *CLE = cast(E); - llvm::Constant* C = Visit(CLE->getInitializer()); - // FIXME: "Leaked" on failure. - if (C) - C = new llvm::GlobalVariable(CGM.getModule(), C->getType(), - E->getType().isConstant(CGM.getContext()), - llvm::GlobalValue::InternalLinkage, - C, ".compoundliteral", 0, false, - CGM.getContext().getTargetAddressSpace(E->getType())); - return C; - } - case Expr::DeclRefExprClass: { - ValueDecl *Decl = cast(E)->getDecl(); + llvm::Constant *EmitLValue(APValue::LValueBase LVBase) { + if (const ValueDecl *Decl = LVBase.dyn_cast()) { if (Decl->hasAttr()) return CGM.GetWeakRefReference(Decl); if (const FunctionDecl *FD = dyn_cast(Decl)) @@ -877,7 +860,25 @@ public: } } } - break; + return 0; + } + + Expr *E = const_cast(LVBase.get()); + switch (E->getStmtClass()) { + default: break; + case Expr::CompoundLiteralExprClass: { + // Note that due to the nature of compound literals, this is guaranteed + // to be the only use of the variable, so we just generate it here. + CompoundLiteralExpr *CLE = cast(E); + llvm::Constant* C = Visit(CLE->getInitializer()); + // FIXME: "Leaked" on failure. + if (C) + C = new llvm::GlobalVariable(CGM.getModule(), C->getType(), + E->getType().isConstant(CGM.getContext()), + llvm::GlobalValue::InternalLinkage, + C, ".compoundliteral", 0, false, + CGM.getContext().getTargetAddressSpace(E->getType())); + return C; } case Expr::StringLiteralClass: return CGM.GetAddrOfConstantStringFromLiteral(cast(E)); @@ -963,8 +964,8 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E, Result.Val.getLValueOffset().getQuantity()); llvm::Constant *C; - if (const Expr *LVBase = Result.Val.getLValueBase()) { - C = ConstExprEmitter(*this, CGF).EmitLValue(const_cast(LVBase)); + if (APValue::LValueBase LVBase = Result.Val.getLValueBase()) { + C = ConstExprEmitter(*this, CGF).EmitLValue(LVBase); // Apply offset if necessary. if (!Offset->isNullValue()) { -- cgit v1.2.3