[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGen / aggregate-assign-call.c
blobd13cae7294ebc2601c2b670c70fa4791a80f2a56
1 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-linux-gnu -O1 -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=O1
2 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-linux-gnu -O0 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=O0
3 //
4 // Ensure that we place appropriate lifetime markers around indirectly returned
5 // temporaries, and that the lifetime.ends appear in a timely manner.
6 //
7 // -O1 is used so lifetime markers actually get emitted and optnone is added
8 // to avoid elimination of lifetime markers by optimizations.
10 struct S {
11 int ns[40];
14 struct S foo(void);
16 // CHECK-LABEL: define dso_local void @bar
17 __attribute__((optnone))
18 struct S bar(void) {
19 // O0-NOT: @llvm.lifetime.start
20 // O0-NOT: @llvm.lifetime.end
22 struct S r;
23 // O1: %[[TMP1_ALLOCA:[^ ]+]] = alloca %struct.S
24 // O1: %[[TMP2_ALLOCA:[^ ]+]] = alloca %struct.S
25 // O1: %[[TMP3_ALLOCA:[^ ]+]] = alloca %struct.S
27 // O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
28 // O1: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* %[[P]])
29 // O1: call void @foo
30 r = foo();
31 // O1: memcpy
32 // O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
33 // O1: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
35 // O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
36 // O1: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* %[[P]])
37 // O1: call void @foo
38 r = foo();
39 // O1: memcpy
40 // O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
41 // O1: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
43 // O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP3_ALLOCA]] to i8*
44 // O1: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* %[[P]])
45 // O1: call void @foo
46 r = foo();
47 // O1: memcpy
48 // O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP3_ALLOCA]] to i8*
49 // O1: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
51 return r;
54 struct S foo_int(int);
56 // Be sure that we're placing the lifetime.end so that all paths go through it.
57 // CHECK-LABEL: define dso_local void @baz
58 __attribute__((optnone))
59 struct S baz(int i, volatile int *j) {
60 // O0-NOT: @llvm.lifetime.start
61 // O0-NOT: @llvm.lifetime.end
63 struct S r;
64 // O1: %[[TMP1_ALLOCA:[^ ]+]] = alloca %struct.S
65 // O1: %[[TMP2_ALLOCA:[^ ]+]] = alloca %struct.S
67 do {
68 // O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
69 // O1: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* %[[P]])
71 // O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
72 // O1: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
74 // O1: call void @foo_int(%struct.S* sret(%struct.S) align 4 %[[TMP1_ALLOCA]],
75 // O1: call void @llvm.memcpy
76 // O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP1_ALLOCA]] to i8*
77 // O1: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
78 // O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
79 // O1: call void @llvm.lifetime.start.p0i8({{[^,]*}}, i8* %[[P]])
80 // O1: call void @foo_int(%struct.S* sret(%struct.S) align 4 %[[TMP2_ALLOCA]],
81 // O1: call void @llvm.memcpy
82 // O1: %[[P:[^ ]+]] = bitcast %struct.S* %[[TMP2_ALLOCA]] to i8*
83 // O1: call void @llvm.lifetime.end.p0i8({{[^,]*}}, i8* %[[P]])
84 r = foo_int(({
85 if (*j)
86 break;
87 i++;
88 }));
90 r = foo_int(i++);
91 } while (1);
93 return r;