David Blaikie | 1b76fbc | 2012-09-10 23:06:08 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -S -triple armv7-none-eabi -emit-llvm -o - %s | FileCheck %s |
Sebastian Redl | 13dc8f9 | 2011-11-27 16:50:07 +0000 | [diff] [blame] | 2 | |
| 3 | namespace reference { |
| 4 | struct A { |
| 5 | int i1, i2; |
| 6 | }; |
| 7 | |
| 8 | void single_init() { |
| 9 | // No superfluous instructions allowed here, they could be |
| 10 | // hiding extra temporaries. |
| 11 | |
| 12 | // CHECK: store i32 1, i32* |
| 13 | // CHECK-NEXT: store i32* %{{.*}}, i32** |
| 14 | const int &cri2a = 1; |
| 15 | |
| 16 | // CHECK-NEXT: store i32 1, i32* |
| 17 | // CHECK-NEXT: store i32* %{{.*}}, i32** |
| 18 | const int &cri1a = {1}; |
| 19 | |
| 20 | // CHECK-NEXT: store i32 1, i32* |
| 21 | int i = 1; |
| 22 | // CHECK-NEXT: store i32* %{{.*}}, i32** |
| 23 | int &ri1a = {i}; |
| 24 | |
| 25 | // CHECK-NEXT: bitcast |
| 26 | // CHECK-NEXT: memcpy |
| 27 | A a{1, 2}; |
| 28 | // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** % |
| 29 | A &ra1a = {a}; |
| 30 | |
Richard Smith | 13ec910 | 2012-05-14 21:57:21 +0000 | [diff] [blame] | 31 | using T = A&; |
| 32 | // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** % |
| 33 | A &ra1b = T{a}; |
| 34 | |
Sebastian Redl | 13dc8f9 | 2011-11-27 16:50:07 +0000 | [diff] [blame] | 35 | // CHECK-NEXT: ret |
| 36 | } |
| 37 | |
| 38 | void reference_to_aggregate() { |
| 39 | // CHECK: getelementptr {{.*}}, i32 0, i32 0 |
| 40 | // CHECK-NEXT: store i32 1 |
| 41 | // CHECK-NEXT: getelementptr {{.*}}, i32 0, i32 1 |
| 42 | // CHECK-NEXT: store i32 2 |
| 43 | // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %{{.*}}, align |
| 44 | const A &ra1{1, 2}; |
| 45 | |
| 46 | // CHECK-NEXT: getelementptr inbounds [3 x i32]* %{{.*}}, i{{32|64}} 0, i{{32|64}} 0 |
| 47 | // CHECK-NEXT: store i32 1 |
| 48 | // CHECK-NEXT: getelementptr inbounds i32* %{{.*}}, i{{32|64}} 1 |
| 49 | // CHECK-NEXT: store i32 2 |
| 50 | // CHECK-NEXT: getelementptr inbounds i32* %{{.*}}, i{{32|64}} 1 |
| 51 | // CHECK-NEXT: store i32 3 |
| 52 | // CHECK-NEXT: store [3 x i32]* %{{.*}}, [3 x i32]** %{{.*}}, align |
| 53 | const int (&arrayRef)[] = {1, 2, 3}; |
| 54 | |
| 55 | // CHECK-NEXT: ret |
| 56 | } |
| 57 | |
| 58 | struct B { |
| 59 | B(); |
| 60 | ~B(); |
| 61 | }; |
| 62 | |
| 63 | void single_init_temp_cleanup() |
| 64 | { |
| 65 | // Ensure lifetime extension. |
| 66 | |
David Blaikie | 1b76fbc | 2012-09-10 23:06:08 +0000 | [diff] [blame] | 67 | // CHECK: call %"struct.reference::B"* @_ZN9reference1BC1Ev |
Sebastian Redl | 13dc8f9 | 2011-11-27 16:50:07 +0000 | [diff] [blame] | 68 | // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** % |
| 69 | const B &rb{ B() }; |
David Blaikie | 1b76fbc | 2012-09-10 23:06:08 +0000 | [diff] [blame] | 70 | // CHECK: call %"struct.reference::B"* @_ZN9reference1BD1Ev |
Sebastian Redl | 13dc8f9 | 2011-11-27 16:50:07 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | } |