diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-02 03:16:32 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-02 03:16:32 +0000 |
commit | a3cac5b76a5243d8fca812d3a276950b0cfc56b6 (patch) | |
tree | 5edf3adbed60d56f12d02d6d451ff527c7b7b2eb /test/CodeGenCXX/const-init-cxx11.cpp | |
parent | 77d09441e59d3bced6c3d55505eb3a67a784fe02 (diff) |
PR12145: Avoid emitting loads of constexpr variables in contexts where there
is no odr-use of the variable. Go slightly beyond what the standard requires
for variables of reference type.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151879 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenCXX/const-init-cxx11.cpp')
-rw-r--r-- | test/CodeGenCXX/const-init-cxx11.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/CodeGenCXX/const-init-cxx11.cpp b/test/CodeGenCXX/const-init-cxx11.cpp index 5366d6d485..776a1e12dd 100644 --- a/test/CodeGenCXX/const-init-cxx11.cpp +++ b/test/CodeGenCXX/const-init-cxx11.cpp @@ -337,3 +337,30 @@ namespace VirtualBase { X<D> x; // CHECK: call {{.*}}@_ZN11VirtualBase1XINS_1DEEC1Ev } + +// PR12145 +namespace Unreferenced { + int n; + constexpr int *p = &n; + // We must not emit a load of 'p' here, since it's not odr-used. + int q = *p; + // CHECK-NOT: _ZN12Unreferenced1pE + // CHECK: %0 = load i32* @_ZN12Unreferenced1nE + // CHECK-NEXT: store i32 %0, i32* @_ZN12Unreferenced1qE + // CHECK-NOT: _ZN12Unreferenced1pE + + // Technically, we are not required to substitute variables of reference types + // initialized by constant expressions, because the special case for odr-use + // of variables in [basic.def.odr]p2 only applies to objects. But we do so + // anyway. + + constexpr int &r = n; + // CHECK-NOT: _ZN12Unreferenced1rE + int s = r; + + const int t = 1; + const int &rt = t; + int f(int); + int u = f(rt); + // CHECK: call i32 @_ZN12Unreferenced1fEi(i32 1) +} |