[PATCH] D36876: [IRGen] Evaluate constant static variables referenced through member expressions

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 18 07:53:45 PDT 2017


arphaman created this revision.

C++ allows us to reference static variables through member expressions. Prior to this patch, 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 patch ensures that static variables referenced through member expressions are emitted in the same way as ordinary static variable references.

rdar://33942261


Repository:
  rL LLVM

https://reviews.llvm.org/D36876

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGenCXX/member-expr-references-variable.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36876.111673.patch
Type: text/x-patch
Size: 14467 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170818/e5b35fe6/attachment-0001.bin>


More information about the cfe-commits mailing list