From 6cc8317c38b8fd9b4debeabf5d28aa128bb61160 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Fri, 25 Aug 2017 10:07:00 +0000 Subject: [IRGen] Evaluate constant static variables referenced through member expressions C++ allows us to reference static variables through member expressions. Prior to this commit, non-integer static variables that were referenced using a member expression were always emitted using lvalue loads. The old behaviour introduced an inconsistency between regular uses of static variables and member expressions uses. For example, the following program compiled and linked successfully: struct Foo { constexpr static const char *name = "foo"; }; int main() { return Foo::name[0] == 'f'; } but this program failed to link because "Foo::name" wasn't found: struct Foo { constexpr static const char *name = "foo"; }; int main() { Foo f; return f.name[0] == 'f'; } This commit ensures that constant static variables referenced through member expressions are emitted in the same way as ordinary static variable references. rdar://33942261 Differential Revision: https://reviews.llvm.org/D36876 llvm-svn: 311772 --- clang/lib/CodeGen/CGExprAgg.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'clang/lib/CodeGen/CGExprAgg.cpp') diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index a05a088f091..1ab8433864c 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -124,24 +124,7 @@ public: } // l-values. - void VisitDeclRefExpr(DeclRefExpr *E) { - // For aggregates, we should always be able to emit the variable - // as an l-value unless it's a reference. This is due to the fact - // that we can't actually ever see a normal l2r conversion on an - // aggregate in C++, and in C there's no language standard - // actively preventing us from listing variables in the captures - // list of a block. - if (E->getDecl()->getType()->isReferenceType()) { - if (CodeGenFunction::ConstantEmission result - = CGF.tryEmitAsConstant(E)) { - EmitFinalDestCopy(E->getType(), result.getReferenceLValue(CGF, E)); - return; - } - } - - EmitAggLoadOfLValue(E); - } - + void VisitDeclRefExpr(DeclRefExpr *E) { EmitAggLoadOfLValue(E); } void VisitMemberExpr(MemberExpr *ME) { EmitAggLoadOfLValue(ME); } void VisitUnaryDeref(UnaryOperator *E) { EmitAggLoadOfLValue(E); } void VisitStringLiteral(StringLiteral *E) { EmitAggLoadOfLValue(E); } -- cgit v1.2.3