David Majnemer | 17e2633 | 2014-12-14 12:16:43 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -triple armv7-none-eabi -emit-llvm -o - %s | FileCheck %s |
Douglas Gregor | 9b71f0c | 2011-06-17 04:59:12 +0000 | [diff] [blame] | 2 | |
| 3 | struct X { |
| 4 | X(); |
| 5 | X(const X&); |
| 6 | X(const char*); |
| 7 | ~X(); |
| 8 | }; |
| 9 | |
| 10 | struct Y { |
| 11 | int i; |
| 12 | X x; |
| 13 | }; |
| 14 | |
Richard Smith | b3189a1 | 2016-12-05 07:49:14 +0000 | [diff] [blame] | 15 | // CHECK: @.compoundliteral = internal global [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5], align 4 |
| 16 | // CHECK: @q = global i32* getelementptr inbounds ([5 x i32], [5 x i32]* @.compoundliteral, i32 0, i32 0), align 4 |
| 17 | |
Stephen Lin | 4362261 | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 18 | // CHECK-LABEL: define i32 @_Z1fv() |
Douglas Gregor | 9b71f0c | 2011-06-17 04:59:12 +0000 | [diff] [blame] | 19 | int f() { |
| 20 | // CHECK: [[LVALUE:%[a-z0-9.]+]] = alloca |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 21 | // CHECK-NEXT: [[I:%[a-z0-9]+]] = getelementptr inbounds {{.*}}, {{.*}}* [[LVALUE]], i32 0, i32 0 |
Douglas Gregor | 9b71f0c | 2011-06-17 04:59:12 +0000 | [diff] [blame] | 22 | // CHECK-NEXT: store i32 17, i32* [[I]] |
| 23 | // CHECK-NEXT: [[X:%[a-z0-9]+]] = getelementptr inbounds {{.*}} [[LVALUE]], i32 0, i32 1 |
David Blaikie | 2fc4161 | 2012-09-19 18:46:03 +0000 | [diff] [blame] | 24 | // CHECK-NEXT: call %struct.X* @_ZN1XC1EPKc({{.*}}[[X]] |
Douglas Gregor | 9b71f0c | 2011-06-17 04:59:12 +0000 | [diff] [blame] | 25 | // CHECK-NEXT: [[I:%[a-z0-9]+]] = getelementptr inbounds {{.*}} [[LVALUE]], i32 0, i32 0 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 26 | // CHECK-NEXT: [[RESULT:%[a-z0-9]+]] = load i32, i32* |
David Blaikie | 2fc4161 | 2012-09-19 18:46:03 +0000 | [diff] [blame] | 27 | // CHECK-NEXT: call %struct.Y* @_ZN1YD1Ev |
Douglas Gregor | 9b71f0c | 2011-06-17 04:59:12 +0000 | [diff] [blame] | 28 | // CHECK-NEXT: ret i32 [[RESULT]] |
| 29 | return ((Y){17, "seventeen"}).i; |
| 30 | } |
Peter Collingbourne | fcc764d | 2011-11-13 00:51:30 +0000 | [diff] [blame] | 31 | |
Stephen Lin | 4362261 | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 32 | // CHECK-LABEL: define i32 @_Z1gv() |
Peter Collingbourne | fcc764d | 2011-11-13 00:51:30 +0000 | [diff] [blame] | 33 | int g() { |
Benjamin Kramer | 85be49d | 2015-04-09 22:54:53 +0000 | [diff] [blame] | 34 | // CHECK: store [2 x i32]* %{{[a-z0-9.]+}}, [2 x i32]** [[V:%[a-z0-9.]+]] |
Peter Collingbourne | fcc764d | 2011-11-13 00:51:30 +0000 | [diff] [blame] | 35 | const int (&v)[2] = (int [2]) {1,2}; |
| 36 | |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 37 | // CHECK: [[A:%[a-z0-9.]+]] = load [2 x i32]*, [2 x i32]** [[V]] |
David Blaikie | 218b783 | 2015-02-27 19:18:17 +0000 | [diff] [blame] | 38 | // CHECK-NEXT: [[A0ADDR:%[a-z0-9.]+]] = getelementptr inbounds [2 x i32], [2 x i32]* [[A]], i32 0, {{.*}} 0 |
David Blaikie | a953f28 | 2015-02-27 21:19:58 +0000 | [diff] [blame] | 39 | // CHECK-NEXT: [[A0:%[a-z0-9.]+]] = load i32, i32* [[A0ADDR]] |
Peter Collingbourne | fcc764d | 2011-11-13 00:51:30 +0000 | [diff] [blame] | 40 | // CHECK-NEXT: ret i32 [[A0]] |
| 41 | return v[0]; |
| 42 | } |
Richard Smith | 2d988f0 | 2011-11-22 22:48:32 +0000 | [diff] [blame] | 43 | |
Richard Smith | 4baaa5a | 2016-12-03 01:14:32 +0000 | [diff] [blame] | 44 | // GCC's compound-literals-in-C++ extension lifetime-extends a compound literal |
| 45 | // (or a C++11 list-initialized temporary!) if: |
| 46 | // - it is at global scope |
| 47 | // - it has array type |
| 48 | // - it has a constant initializer |
| 49 | |
Richard Smith | 2d988f0 | 2011-11-22 22:48:32 +0000 | [diff] [blame] | 50 | struct Z { int i[3]; }; |
| 51 | int *p = (Z){ {1, 2, 3} }.i; |
| 52 | // CHECK: define {{.*}}__cxx_global_var_init() |
Richard Smith | 4baaa5a | 2016-12-03 01:14:32 +0000 | [diff] [blame] | 53 | // CHECK: alloca %struct.Z |
| 54 | // CHECK: store i32* %{{.*}}, i32** @p |
David Majnemer | 17e2633 | 2014-12-14 12:16:43 +0000 | [diff] [blame] | 55 | |
Richard Smith | 4baaa5a | 2016-12-03 01:14:32 +0000 | [diff] [blame] | 56 | int *q = (int [5]){1, 2, 3, 4, 5}; |
Richard Smith | b3189a1 | 2016-12-05 07:49:14 +0000 | [diff] [blame] | 57 | // (constant initialization, checked above) |
David Majnemer | 17e2633 | 2014-12-14 12:16:43 +0000 | [diff] [blame] | 58 | |
Richard Smith | b3189a1 | 2016-12-05 07:49:14 +0000 | [diff] [blame] | 59 | extern int n; |
| 60 | int *r = (int [5]){1, 2, 3, 4, 5} + n; |
| 61 | // CHECK-LABEL: define {{.*}}__cxx_global_var_init.1() |
| 62 | // CHECK: %[[PTR:.*]] = getelementptr inbounds i32, i32* getelementptr inbounds ([5 x i32], [5 x i32]* @.compoundliteral.2, i32 0, i32 0), i32 % |
| 63 | // CHECK: store i32* %[[PTR]], i32** @r |
| 64 | |
| 65 | int *PR21912_1 = (int []){} + n; |
| 66 | // CHECK-LABEL: define {{.*}}__cxx_global_var_init.3() |
| 67 | // CHECK: %[[PTR:.*]] = getelementptr inbounds i32, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @.compoundliteral.4, i32 0, i32 0), i32 % |
| 68 | // CHECK: store i32* %[[PTR]], i32** @PR21912_1 |
David Majnemer | 17e2633 | 2014-12-14 12:16:43 +0000 | [diff] [blame] | 69 | |
| 70 | union PR21912Ty { |
| 71 | long long l; |
| 72 | double d; |
| 73 | }; |
Richard Smith | b3189a1 | 2016-12-05 07:49:14 +0000 | [diff] [blame] | 74 | union PR21912Ty *PR21912_2 = (union PR21912Ty[]){{.d = 2.0}, {.l = 3}} + n; |
| 75 | // CHECK-LABEL: define {{.*}}__cxx_global_var_init.5() |
| 76 | // CHECK: %[[PTR:.*]] = getelementptr inbounds %union.PR21912Ty, %union.PR21912Ty* getelementptr inbounds ([2 x %union.PR21912Ty], [2 x %union.PR21912Ty]* bitcast (<{ { double }, %union.PR21912Ty }>* @.compoundliteral.6 to [2 x %union.PR21912Ty]*), i32 0, i32 0), i32 % |
| 77 | // CHECK: store %union.PR21912Ty* %[[PTR]], %union.PR21912Ty** @PR21912_2, align 4 |
John McCall | 9648288 | 2016-10-31 21:56:26 +0000 | [diff] [blame] | 78 | |
| 79 | // This compound literal should have local scope. |
| 80 | int computed_with_lambda = [] { |
| 81 | int *array = (int[]) { 1, 3, 5, 7 }; |
| 82 | return array[0]; |
| 83 | }(); |
| 84 | // CHECK-LABEL: define internal i32 @{{.*}}clEv |
| 85 | // CHECK: alloca [4 x i32] |