diff options
author | dim <dim@FreeBSD.org> | 2012-04-14 14:01:31 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-04-14 14:01:31 +0000 |
commit | 50b73317314e889cf39c7b1d6cbf419fa7502f22 (patch) | |
tree | be1815eb79b42ff482a8562b13c2dcbf0c5dcbee /test/CodeGenCXX/const-init.cpp | |
parent | dc04cb328508e61aad809d9b53b12f9799a00e7d (diff) | |
download | FreeBSD-src-50b73317314e889cf39c7b1d6cbf419fa7502f22.zip FreeBSD-src-50b73317314e889cf39c7b1d6cbf419fa7502f22.tar.gz |
Vendor import of clang trunk r154661:
http://llvm.org/svn/llvm-project/cfe/trunk@r154661
Diffstat (limited to 'test/CodeGenCXX/const-init.cpp')
-rw-r--r-- | test/CodeGenCXX/const-init.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/test/CodeGenCXX/const-init.cpp b/test/CodeGenCXX/const-init.cpp index 797d137..201ce8f 100644 --- a/test/CodeGenCXX/const-init.cpp +++ b/test/CodeGenCXX/const-init.cpp @@ -29,10 +29,50 @@ namespace test2 { struct A { static const double d = 1.0; static const float f = d / 2; - }; + static int g(); + } a; // CHECK: @_ZN5test22t0E = global double {{1\.0+e\+0+}}, align 8 // CHECK: @_ZN5test22t1E = global [2 x double] [double {{1\.0+e\+0+}}, double {{5\.0+e-0*}}1], align 16 + // CHECK: @_ZN5test22t2E = global double* @_ZN5test21A1d + // CHECK: @_ZN5test22t3E = global {{.*}} @_ZN5test21A1g double t0 = A::d; double t1[] = { A::d, A::f }; + const double *t2 = &a.d; + int (*t3)() = &a.g; } + +// We don't expect to fold this in the frontend, but make sure it doesn't crash. +// CHECK: @PR9558 = global float 0.000000e+0 +float PR9558 = reinterpret_cast<const float&>("asd"); + +// An initialized const automatic variable cannot be promoted to a constant +// global if it has a mutable member. +struct MutableMember { + mutable int n; +}; +int writeToMutable() { + // CHECK-NOT: {{.*}}MM{{.*}} = {{.*}}constant + const MutableMember MM = { 0 }; + return ++MM.n; +} + +// Make sure we don't try to fold this in the frontend; the backend can't +// handle it. +// CHECK: @PR11705 = global i128 0 +__int128_t PR11705 = (__int128_t)&PR11705; + +// Make sure we don't try to fold this either. +// CHECK: @_ZZ23UnfoldableAddrLabelDiffvE1x = internal global i128 0 +void UnfoldableAddrLabelDiff() { static __int128_t x = (long)&&a-(long)&&b; a:b:return;} + +// But make sure we do fold this. +// CHECK: @_ZZ21FoldableAddrLabelDiffvE1x = internal global i64 sub (i64 ptrtoint (i8* blockaddress(@_Z21FoldableAddrLabelDiffv +void FoldableAddrLabelDiff() { static long x = (long)&&a-(long)&&b; a:b:return;} + +// CHECK: @i = constant i32* bitcast (float* @PR9558 to i32*) +int &i = reinterpret_cast<int&>(PR9558); + +int arr[2]; +// CHECK: @pastEnd = constant i32* bitcast (i8* getelementptr (i8* bitcast ([2 x i32]* @arr to i8*), i64 8) to i32*) +int &pastEnd = arr[2]; |