]> granicus.if.org Git - clang/commit
[IRGen] Evaluate constant static variables referenced through member
authorAlex Lorenz <arphaman@gmail.com>
Fri, 25 Aug 2017 10:07:00 +0000 (10:07 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Fri, 25 Aug 2017 10:07:00 +0000 (10:07 +0000)
commitb92a424f05b905b5b3c616066f1064b9aceaed22
treec0bcefedcf9d248010d63c5516bd0e41d1b3d8da
parent2a74f265b5b1ae275ae0829c632b662ff63d42bc
[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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311772 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGExpr.cpp
lib/CodeGen/CGExprAgg.cpp
lib/CodeGen/CGExprComplex.cpp
lib/CodeGen/CGExprScalar.cpp
lib/CodeGen/CodeGenFunction.h
test/CodeGenCXX/member-expr-references-variable.cpp [new file with mode: 0644]