1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions -O0 %s -emit-llvm -o - | FileCheck %s
3 extern "C" int printf(const char *, ...);
8 __attribute__((nothrow
)) { printf("%d: S()\n", ++N
); }
9 ~S() __attribute__((nothrow
)) { printf("%d: ~S()\n", N
--); }
12 // CHECK: [[struct_S:%.+]] = type { [17 x i32] }
13 void print(int n
, int a
, int b
, int c
, int d
) {
14 printf("n=%d\n,sizeof(S)=%d\nsizeof(array_t[0][0])=%d\nsizeof(array_t[0])=%d\nsizeof(array_t)=%d\n",
21 // CHECK: define{{.*}} void {{.*test.*}}(i32 noundef [[n:%.+]]) #
22 // CHECK: [[n_addr:%.+]] = alloca
23 // CHECK-NEXT: [[saved_stack:%.+]] = alloca
24 // CHECK-NEXT: [[vla_expr:%.+]] = alloca i64, align 8
25 // CHECK-NEXT: [[vla_expr1:%.+]] = alloca i64, align 8
26 // CHECK-NEXT: [[sizeof_S:%.+]] = alloca
27 // CHECK-NEXT: [[sizeof_array_t_0_0:%.+]] = alloca
28 // CHECK-NEXT: [[sizeof_array_t_0:%.+]] = alloca
29 // CHECK-NEXT: [[sizeof_array_t:%.+]] = alloca
30 // CHECK-NEXT: [[exn_slot:%.+]] = alloca ptr
31 // CHECK-NEXT: [[ehselector_slot:%.+]] = alloca i32
32 // CHECK-NEXT: store i32 [[n]], ptr [[n_addr]]
33 // CHECK-NEXT: [[t0:%.+]] = load i32, ptr [[n_addr]]
34 // CHECK-NEXT: [[t1:%.+]] = zext i32 [[t0]] to i64
35 // CHECK-NEXT: [[t2:%.+]] = load i32, ptr [[n_addr]]
36 // CHECK-NEXT: [[add:%.+]] = add nsw i32 [[t2]], 1
37 // CHECK-NEXT: [[t3:%.+]] = zext i32 [[add]] to i64
38 // CHECK-NEXT: [[t4:%.+]] = call ptr @llvm.stacksave()
39 // CHECK-NEXT: store ptr [[t4]], ptr [[saved_stack]]
40 // CHECK-NEXT: [[t5:%.+]] = mul nuw i64 [[t1]], [[t3]]
41 // CHECK-NEXT: [[vla:%.+]] = alloca [[struct_S]], i64 [[t5]]
42 // CHECK-NEXT: store i64 [[t1]], ptr [[vla_expr]]
43 // CHECK-NEXT: store i64 [[t3]], ptr [[vla_expr1]]
44 // CHECK-NEXT: [[t6:%.+]] = mul nuw i64 [[t1]], [[t3]]
45 // CHECK-NEXT: [[isempty:%.+]] = icmp eq i64 [[t6]], 0
46 // CHECK-NEXT: br i1 [[isempty]], label %[[arrayctor_cont:.+]], label %[[new_ctorloop:.+]]
50 // CHECK: [[new_ctorloop]]
51 // CHECK-NEXT: [[arrayctor_end:%.+]] = getelementptr inbounds [[struct_S]], ptr [[vla]], i64 [[t6]]
52 // CHECK-NEXT: br label %[[arrayctor_loop:.+]]
54 // CHECK: [[arrayctor_loop]]
55 // CHECK-NEXT: [[arrayctor_cur:%.+]] = phi ptr [ [[vla]], %[[new_ctorloop]] ], [ [[arrayctor_next:%.+]], %[[arrayctor_loop]] ]
56 // CHECK-NEXT: call void [[ctor:@.+]](ptr {{[^,]*}} [[arrayctor_cur]])
57 // CHECK-NEXT: [[arrayctor_next]] = getelementptr inbounds [[struct_S]], ptr [[arrayctor_cur]], i64 1
58 // CHECK-NEXT: [[arrayctor_done:%.+]] = icmp eq ptr [[arrayctor_next]], [[arrayctor_end]]
59 // CHECK-NEXT: br i1 [[arrayctor_done]], label %[[arrayctor_cont]], label %[[arrayctor_loop]]
61 int sizeof_S
= sizeof(S
);
62 int sizeof_array_t_0_0
= sizeof(array_t
[0][0]);
63 int sizeof_array_t_0
= sizeof(array_t
[0]);
64 int sizeof_array_t
= sizeof(array_t
);
65 print(n
, sizeof_S
, sizeof_array_t_0_0
, sizeof_array_t_0
, sizeof_array_t
);
67 // CHECK: [[arrayctor_cont]]
68 // CHECK-NEXT: store i32 68, ptr [[sizeof_S]]
69 // CHECK-NEXT: store i32 68, ptr [[sizeof_array_t_0_0]]
70 // CHECK: [[t8:%.+]] = mul nuw i64 68, [[t3]]
71 // CHECK-NEXT: [[conv:%.+]] = trunc i64 [[t8]] to i32
72 // CHECK-NEXT: store i32 [[conv]], ptr [[sizeof_array_t_0]]
73 // CHECK-NEXT: [[t9:%.+]] = mul nuw i64 [[t1]], [[t3]]
74 // CHECK-NEXT: [[t10:%.+]] = mul nuw i64 68, [[t9]]
75 // CHECK-NEXT: [[conv1:%.+]] = trunc i64 [[t10]] to i32
76 // CHECK-NEXT: store i32 [[conv1]], ptr [[sizeof_array_t]]
77 // CHECK-NEXT: [[t11:%.+]] = load i32, ptr [[n_addr:%.+]]
78 // CHECK-NEXT: [[t12:%.+]] = load i32, ptr [[sizeof_S]]
79 // CHECK-NEXT: [[t13:%.+]] = load i32, ptr [[sizeof_array_t_0_0]]
80 // CHECK-NEXT: [[t14:%.+]] = load i32, ptr [[sizeof_array_t_0]]
81 // CHECK-NEXT: [[t15:%.+]] = load i32, ptr [[sizeof_array_t]]
82 // CHECK-NEXT: invoke void @{{.*print.*}}(i32 noundef [[t11]], i32 noundef [[t12]], i32 noundef [[t13]], i32 noundef [[t14]], i32 noundef [[t15]])
83 // CHECK-NEXT: to label %[[invoke_cont:.+]] unwind label %[[lpad:.+]]
85 // CHECK: [[invoke_cont]]
86 // CHECK-NEXT: [[t16:%.+]] = mul nuw i64 [[t1]], [[t3]]
87 // CHECK-NEXT: [[t17:%.+]] = getelementptr inbounds [[struct_S]], ptr [[vla]], i64 [[t16]]
88 // CHECK-NEXT: [[arraydestroy_isempty:%.+]] = icmp eq ptr [[vla]], [[t17]]
89 // CHECK-NEXT: br i1 [[arraydestroy_isempty]], label %[[arraydestroy_done2:.+]], label %[[arraydestroy_body:.+]]
91 // CHECK: [[arraydestroy_body]]
92 // CHECK-NEXT: [[arraydestroy_elementPast:%.+]] = phi ptr [ [[t17]], %[[invoke_cont]] ], [ [[arraydestroy_element:%.+]], %[[arraydestroy_body]] ]
93 // CHECK-NEXT: [[arraydestroy_element]] = getelementptr inbounds [[struct_S]], ptr [[arraydestroy_elementPast]]
94 // CHECK-NEXT: call void @[[dtor:.+]](ptr {{[^,]*}} [[arraydestroy_element]])
95 // CHECK-NEXT: [[arraydestroy_done:%.+]] = icmp eq ptr [[arraydestroy_element]], [[vla]]
96 // CHECK-NEXT: br i1 [[arraydestroy_done]], label %[[arraydestroy_done2]], label %[[arraydestroy_body]]
98 // CHECK: [[arraydestroy_done2]]
99 // CHECK-NEXT: [[t17:%.+]] = load ptr, ptr [[saved_stack]]
100 // CHECK-NEXT: call void @llvm.stackrestore(ptr [[t17]])
104 // CHECK-NEXT: [[t19:%.+]] = landingpad { ptr, i32 }
105 // CHECK: [[t20:%.+]] = extractvalue { ptr, i32 } [[t19]], 0
106 // CHECK-NEXT: store ptr [[t20]], ptr [[exn_slot]]
107 // CHECK-NEXT: [[t21:%.+]] = extractvalue { ptr, i32 } [[t19]], 1
108 // CHECK-NEXT: store i32 [[t21]], ptr [[ehselector_slot]]
109 // CHECK-NEXT: [[t22:%.+]] = mul nuw i64 [[t1]], [[t3]]
110 // CHECK-NEXT: [[t23:%.+]] = getelementptr inbounds [[struct_S]], ptr [[vla]], i64 [[t22]]
111 // CHECK-NEXT: [[arraydestroy_isempty3:%.+]] = icmp eq ptr [[vla]], [[t23]]
112 // CHECK-NEXT: br i1 [[arraydestroy_isempty3]], label %[[arraydestroy_done8:.+]], label %[[arraydestroy_body4:.+]]
114 // CHECK: [[arraydestroy_body4]]
115 // CHECK: [[arraydestroy_elementPast5:%.+]] = phi ptr [ [[t23]], %[[lpad]] ], [ [[arraydestroy_element6:.+]], %[[arraydestroy_body4]] ]
116 // CHECK-NEXT: [[arraydestroy_element6]] = getelementptr inbounds [[struct_S]], ptr [[arraydestroy_elementPast5]], i64 -1
117 // CHECK-NEXT: call void @[[dtor]](ptr {{[^,]*}} [[arraydestroy_element6]])
118 // CHECK-NEXT: [[arraydestroy_done7:%.+]] = icmp eq ptr [[arraydestroy_element6]], [[vla]]
119 // CHECK-NEXT: br i1 [[arraydestroy_done7]], label %[[arraydestroy_done8]], label %[[arraydestroy_body4]]
121 // CHECK: [[arraydestroy_done8]]
122 // CHECK-NEXT: br label %[[eh_resume:.+]]
124 // CHECK: [[eh_resume]]
125 // CHECK-NEXT: [[exn:%.+]] = load ptr, ptr [[exn_slot]]
126 // CHECK-NEXT: [[sel:%.+]] = load i32, ptr [[ehselector_slot]]
127 // CHECK-NEXT: [[lpad_val:%.+]] = insertvalue { ptr, i32 } poison, ptr [[exn]], 0
128 // CHECK-NEXT: [[lpad_val9:%.+]] = insertvalue { ptr, i32 } [[lpad_val]], i32 [[sel]], 1
129 // CHECK-NEXT: resume { ptr, i32 } [[lpad_val9]]
136 printf("expeption %d\n", e
);
141 printf("expeption %d", e
);