blob: 69632a7de2f4759b31df003199e7f053799dc214 [file] [log] [blame]
David Majnemer17e26332014-12-14 12:16:43 +00001// RUN: %clang_cc1 -std=c++11 -triple armv7-none-eabi -emit-llvm -o - %s | FileCheck %s
Douglas Gregor9b71f0c2011-06-17 04:59:12 +00002
3struct X {
4 X();
5 X(const X&);
6 X(const char*);
7 ~X();
8};
9
10struct Y {
11 int i;
12 X x;
13};
14
Stephen Lin43622612013-08-15 06:47:53 +000015// CHECK-LABEL: define i32 @_Z1fv()
Douglas Gregor9b71f0c2011-06-17 04:59:12 +000016int f() {
17 // CHECK: [[LVALUE:%[a-z0-9.]+]] = alloca
David Blaikie218b7832015-02-27 19:18:17 +000018 // CHECK-NEXT: [[I:%[a-z0-9]+]] = getelementptr inbounds {{.*}}, {{.*}}* [[LVALUE]], i32 0, i32 0
Douglas Gregor9b71f0c2011-06-17 04:59:12 +000019 // CHECK-NEXT: store i32 17, i32* [[I]]
20 // CHECK-NEXT: [[X:%[a-z0-9]+]] = getelementptr inbounds {{.*}} [[LVALUE]], i32 0, i32 1
David Blaikie2fc41612012-09-19 18:46:03 +000021 // CHECK-NEXT: call %struct.X* @_ZN1XC1EPKc({{.*}}[[X]]
Douglas Gregor9b71f0c2011-06-17 04:59:12 +000022 // CHECK-NEXT: [[I:%[a-z0-9]+]] = getelementptr inbounds {{.*}} [[LVALUE]], i32 0, i32 0
David Blaikiea953f282015-02-27 21:19:58 +000023 // CHECK-NEXT: [[RESULT:%[a-z0-9]+]] = load i32, i32*
David Blaikie2fc41612012-09-19 18:46:03 +000024 // CHECK-NEXT: call %struct.Y* @_ZN1YD1Ev
Douglas Gregor9b71f0c2011-06-17 04:59:12 +000025 // CHECK-NEXT: ret i32 [[RESULT]]
26 return ((Y){17, "seventeen"}).i;
27}
Peter Collingbournefcc764d2011-11-13 00:51:30 +000028
Stephen Lin43622612013-08-15 06:47:53 +000029// CHECK-LABEL: define i32 @_Z1gv()
Peter Collingbournefcc764d2011-11-13 00:51:30 +000030int g() {
Benjamin Kramer85be49d2015-04-09 22:54:53 +000031 // CHECK: store [2 x i32]* %{{[a-z0-9.]+}}, [2 x i32]** [[V:%[a-z0-9.]+]]
Peter Collingbournefcc764d2011-11-13 00:51:30 +000032 const int (&v)[2] = (int [2]) {1,2};
33
David Blaikiea953f282015-02-27 21:19:58 +000034 // CHECK: [[A:%[a-z0-9.]+]] = load [2 x i32]*, [2 x i32]** [[V]]
David Blaikie218b7832015-02-27 19:18:17 +000035 // CHECK-NEXT: [[A0ADDR:%[a-z0-9.]+]] = getelementptr inbounds [2 x i32], [2 x i32]* [[A]], i32 0, {{.*}} 0
David Blaikiea953f282015-02-27 21:19:58 +000036 // CHECK-NEXT: [[A0:%[a-z0-9.]+]] = load i32, i32* [[A0ADDR]]
Peter Collingbournefcc764d2011-11-13 00:51:30 +000037 // CHECK-NEXT: ret i32 [[A0]]
38 return v[0];
39}
Richard Smith2d988f02011-11-22 22:48:32 +000040
41struct Z { int i[3]; };
42int *p = (Z){ {1, 2, 3} }.i;
43// CHECK: define {{.*}}__cxx_global_var_init()
David Blaikiebdf40a62015-03-13 18:21:46 +000044// CHECK: store i32* getelementptr inbounds (%struct.Z, %struct.Z* @.compoundliteral, i32 0, i32 0, i32 0), i32** @p
David Majnemer17e26332014-12-14 12:16:43 +000045
46
47int *PR21912_1 = (int []){};
Sunil Srivastava3acf6272015-05-12 16:48:43 +000048// CHECK-LABEL: define {{.*}}__cxx_global_var_init.1()
49// CHECK: store i32* getelementptr inbounds ([0 x i32], [0 x i32]* @.compoundliteral.2, i32 0, i32 0), i32** @PR21912_1
David Majnemer17e26332014-12-14 12:16:43 +000050
51union PR21912Ty {
52 long long l;
53 double d;
54};
55union PR21912Ty *PR21912_2 = (union PR21912Ty[]){{.d = 2.0}, {.l = 3}};
Sunil Srivastava3acf6272015-05-12 16:48:43 +000056// CHECK-LABEL: define {{.*}}__cxx_global_var_init.3()
57// CHECK: store %union.PR21912Ty* getelementptr inbounds ([2 x %union.PR21912Ty], [2 x %union.PR21912Ty]* bitcast (<{ { double }, %union.PR21912Ty }>* @.compoundliteral.4 to [2 x %union.PR21912Ty]*), i32 0, i32 0), %union.PR21912Ty** @PR21912_2