Debian Codegraph @

clang/test/CodeGen/struct-passing.c

raw
1 // This verifies that structs returned from functions by value are passed
2 // correctly according to their attributes and the ABI.
3 // SEE: PR3835
4
5 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s
6
7 typedef int T0;
8 typedef struct { int a[16]; } T1;
9
10 T0 __attribute__((const)) f0(void);
11 T0 __attribute__((pure)) f1(void);
12 T1 __attribute__((const)) f2(void);
13 T1 __attribute__((pure)) f3(void);
14 int __attribute__((const)) f4(T1 a);
15 int __attribute__((pure)) f5(T1 a);
16
17 // NOTE: The int parameters verifies non-ptr parameters are not a problem
18 T1 __attribute__((const)) f6(void*, int);
19 T1 __attribute__((pure)) f7(void*, int);
20
21 T1 __attribute__((const)) f8(int, ...);
22 int __attribute__((const)) f9(int, ...);
23
24 void *ps[] = { f0, f1, f2, f3, f4, f5, f6, f7, f8, f9 };
25
26 // Check markings for varargs arguments.
27 //
28 // FIXME: We can add markings in more cases.
29 void test(T1 t1, void *p) {
30 f8(1);
31 f8(1, t1);
32 f8(1, p);
33
34 f9(1);
35 f9(1, t1);
36 f9(1, p);
37 }
38
39 // CHECK: declare i32 @f0() [[RN:#[0-9]+]]
40 // CHECK: declare i32 @f1() [[RO:#[0-9]+]]
41 // CHECK: declare void @f2(ptr {{[^,]*}} sret({{[^)]*}}) align 4) [[RNRW:#[0-9]+]]
42 // CHECK: declare void @f3(ptr {{[^,]*}} sret({{[^)]*}}) align 4) [[RORW:#[0-9]+]]
43 // CHECK: declare i32 @f4(ptr {{[^,]*}} byval({{[^)]*}}) align 4) [[RNRW]]
44 // CHECK: declare i32 @f5(ptr {{[^,]*}} byval({{[^)]*}}) align 4) [[RORW]]
45 // CHECK: declare void @f6(ptr {{[^,]*}} sret({{[^)]*}}) align 4, ptr {{[^,]*}} readnone, i32 {{[^,]*}}) [[RNRW]]
46 // CHECK: declare void @f7(ptr {{[^,]*}} sret({{[^)]*}}) align 4, ptr {{[^,]*}} readonly, i32 {{[^,]*}}) [[RORW]]
47 // CHECK: declare void @f8(ptr dead_on_unwind writable sret(%struct.T1) align 4, i32 noundef, ...) [[RNRW]]
48 // CHECK: declare i32 @f9(i32 noundef, ...) [[RNRW]]
49
50
51 // CHECK: call void (ptr, i32, ...) @f8(ptr dead_on_unwind writable sret(%struct.T1) align 4 {{.*}}, i32 noundef 1) [[RNRW_CALL:#[0-9]+]]
52 // CHECK: call void (ptr, i32, ...) @f8(ptr dead_on_unwind writable sret(%struct.T1) align 4 {{.*}}, i32 noundef 1, ptr noundef byval(%struct.T1) align 4 {{.*}}) [[RNRW_CALL]]
53 // CHECK: call void (ptr, i32, ...) @f8(ptr dead_on_unwind writable sret(%struct.T1) align 4 {{.*}}, i32 noundef 1, ptr noundef %0) [[RNRW_CALL]]
54 // CHECK: call i32 (i32, ...) @f9(i32 noundef 1) [[RN_CALL:#[0-9]+]]
55 // CHECK: call i32 (i32, ...) @f9(i32 noundef 1, ptr noundef byval(%struct.T1) align 4 {{.*}}) [[RNRW_CALL]]
56 // CHECK: call i32 (i32, ...) @f9(i32 noundef 1, ptr noundef %1) [[RN_CALL]]
57
58
59 // CHECK: attributes [[RN]] = { nounwind willreturn memory(none){{.*}} }
60 // CHECK: attributes [[RO]] = { nounwind willreturn memory(read){{.*}} }
61 // CHECK: attributes [[RNRW]] = { nounwind willreturn memory(argmem: readwrite){{.*}} }
62 // CHECK: attributes [[RORW]] = { nounwind willreturn memory(read, argmem: readwrite){{.*}} }
63 // CHECK: attributes [[RNRW_CALL]] = { nounwind willreturn memory(argmem: readwrite) }
64 // CHECK: attributes [[RN_CALL]] = { nounwind willreturn memory(none) }