diff options
Diffstat (limited to 'test/CodeGenCXX/references.cpp')
-rw-r--r-- | test/CodeGenCXX/references.cpp | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp index 5a5947d..6fc6102 100644 --- a/test/CodeGenCXX/references.cpp +++ b/test/CodeGenCXX/references.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -verify -emit-llvm -o - %s | FileCheck %s void t1() { extern int& a; int b = a; @@ -155,3 +155,73 @@ void f0(s1 a) { s1 b = a; } // CHECK: load // CHECK: ret const int &f2() { return 0; } + +// Don't constant fold const reference parameters with default arguments to +// their default arguments. +namespace N1 { + const int foo = 1; + // CHECK: @_ZN2N14test + int test(const int& arg = foo) { + // Ensure this array is on the stack where we can set values instead of + // being a global constant. + // CHECK: %args_array = alloca + const int* const args_array[] = { &arg }; + } +} + +// Bind to subobjects while extending the life of the complete object. +namespace N2 { + class X { + public: + X(const X&); + X &operator=(const X&); + ~X(); + }; + + struct P { + X first; + }; + + P getP(); + + // CHECK: define void @_ZN2N21fEi + // CHECK: call void @_ZN2N24getPEv + // CHECK: getelementptr inbounds + // CHECK: store i32 17 + // CHECK: call void @_ZN2N21PD1Ev + void f(int i) { + const X& xr = getP().first; + i = 17; + } + + struct SpaceWaster { + int i, j; + }; + + struct ReallyHasX { + X x; + }; + + struct HasX : ReallyHasX { }; + + struct HasXContainer { + HasX has; + }; + + struct Y : SpaceWaster, HasXContainer { }; + struct Z : SpaceWaster, Y { }; + + Z getZ(); + + // CHECK: define void @_ZN2N21gEi + // CHECK: call void @_ZN2N24getZEv + // CHECK: {{getelementptr inbounds.*i32 0, i32 0}} + // CHECK: {{getelementptr inbounds.*i32 0, i32 0}} + // CHECK: store i32 19 + // CHECK: call void @_ZN2N21ZD1Ev + // CHECK: ret void + void g(int i) { + const X &xr = getZ().has.x; + i = 19; + } +} |