xref: /llvm-project/clang/test/CodeGen/attributes.c (revision 8421307b6b165778260b9814ca4d2256bc3711df)
1 // RUN: %clang_cc1 -emit-llvm -Wno-strict-prototypes -Wno-incompatible-function-pointer-types -fcf-protection=branch -triple i386-linux-gnu %s -o - | FileCheck %s
2 
3 // CHECK: @t5 = weak{{.*}} global i32 2
4 int t5 __attribute__((weak)) = 2;
5 
6 // CHECK: @t13 ={{.*}} global %struct.s0 zeroinitializer, section "SECT"
7 struct s0 { int x; };
8 struct s0 t13 __attribute__((section("SECT"))) = { 0 };
9 
10 // CHECK: @t14.x = internal global i32 0, section "SECT"
t14(void)11 void t14(void) {
12   static int x __attribute__((section("SECT"))) = 0;
13 }
14 
15 // CHECK: @t18 ={{.*}} global i32 1, align 4
16 extern int t18 __attribute__((weak_import));
17 int t18 = 1;
18 
19 // CHECK: @t16 = extern_weak global i32
20 extern int t16 __attribute__((weak_import));
21 
22 // CHECK: @t6 = protected global i32 0
23 int t6 __attribute__((visibility("protected")));
24 
25 // CHECK: @t12 ={{.*}} global i32 0, section "SECT"
26 int t12 __attribute__((section("SECT")));
27 
28 // CHECK: @t9 = weak{{.*}} alias void (...), ptr @__t8
__t8()29 void __t8() {}
30 void t9() __attribute__((weak, alias("__t8")));
31 
32 // CHECK: declare extern_weak i32 @t15()
33 int __attribute__((weak_import)) t15(void);
t17(void)34 int t17(void) {
35   return t15() + t16;
36 }
37 
38 // CHECK: define{{.*}} void @t1() [[NR:#[0-9]+]] {
39 void t1(void) __attribute__((noreturn));
t1(void)40 void t1(void) { while (1) {} }
41 
42 // CHECK: define{{.*}} void @t2() [[NUW:#[0-9]+]] {
43 void t2(void) __attribute__((nothrow));
t2(void)44 void t2(void) {}
45 
46 // CHECK: define weak{{.*}} void @t3() [[NUW]] {
47 void t3(void) __attribute__((weak));
t3(void)48 void t3(void) {}
49 
50 // CHECK: define hidden void @t4() [[NUW]] {
51 void t4(void) __attribute__((visibility("hidden")));
t4(void)52 void t4(void) {}
53 
54 // CHECK: define{{.*}} void @t7() [[NR]] {
55 void t7(void) __attribute__((noreturn, nothrow));
t7(void)56 void t7(void) { while (1) {} }
57 
58 // CHECK: define{{.*}} void @t72() [[COLDDEF:#[0-9]+]] {
59 void t71(void) __attribute__((cold));
60 void t72(void) __attribute__((cold));
t72(void)61 void t72(void) { t71(); }
62 // CHECK: call void @t71() [[COLDSITE:#[0-9]+]]
63 // CHECK: declare void @t71() [[COLDDECL:#[0-9]+]]
64 
65 // CHECK: define{{.*}} void @t82() [[HOTDEF:#[0-9]+]] {
66 void t81(void) __attribute__((hot));
67 void t82(void) __attribute__((hot));
t82(void)68 void t82(void) { t81(); }
69 // CHECK: call void @t81() [[HOTSITE:#[0-9]+]]
70 // CHECK: declare void @t81() [[HOTDECL:#[0-9]+]]
71 
72 // CHECK: define{{.*}} void @t10() [[NUW]] section "xSECT" {
73 void t10(void) __attribute__((section("xSECT")));
t10(void)74 void t10(void) {}
75 // CHECK: define{{.*}} void @t11() [[NUW]] section "xSECT" {
t11(void)76 void __attribute__((section("xSECT"))) t11(void) {}
77 
78 // CHECK: define{{.*}} i32 @t19() [[NUW]] {
79 extern int t19(void) __attribute__((weak_import));
t19(void)80 int t19(void) {
81   return 10;
82 }
83 
84 // CHECK:define{{.*}} void @t20() [[NUW]] {
85 // CHECK: call void @abort()
86 // CHECK-NEXT: unreachable
t20(void)87 void t20(void) {
88   __builtin_abort();
89 }
90 
91 void (__attribute__((fastcall)) *fptr)(int);
t21(void)92 void t21(void) {
93   fptr(10);
94 }
95 // CHECK: [[FPTRVAR:%[a-z0-9]+]] = load ptr, ptr @fptr
96 // CHECK-NEXT: call x86_fastcallcc void [[FPTRVAR]](i32 inreg noundef 10)
97 
98 
99 // PR9356: We might want to err on this, but for now at least make sure we
100 // use the section in the definition.
101 void __attribute__((section(".foo"))) t22(void);
t22(void)102 void __attribute__((section(".bar"))) t22(void) {}
103 
104 // CHECK: define{{.*}} void @t22() [[NUW]] section ".bar"
105 
106 // CHECK: define{{.*}} void @t23() [[NOCF_CHECK_FUNC:#[0-9]+]]
t23(void)107 void __attribute__((nocf_check)) t23(void) {}
108 
109 // CHECK: call void %{{[a-z0-9]+}}() [[NOCF_CHECK_CALL:#[0-9]+]]
110 typedef void (*f_t)(void);
t24(f_t f1)111 void t24(f_t f1) {
112   __attribute__((nocf_check)) f_t p = f1;
113   (*p)();
114 }
115 
116 // CHECK: attributes [[NUW]] = { noinline nounwind{{.*}} }
117 // CHECK: attributes [[NR]] = { noinline noreturn nounwind{{.*}} }
118 // CHECK: attributes [[COLDDEF]] = { cold {{.*}}}
119 // CHECK: attributes [[COLDDECL]] = { cold {{.*}}}
120 // CHECK: attributes [[HOTDEF]] = { hot {{.*}}}
121 // CHECK: attributes [[HOTDECL]] = { hot {{.*}}}
122 // CHECK: attributes [[NOCF_CHECK_FUNC]] = { nocf_check {{.*}}}
123 // CHECK: attributes [[COLDSITE]] = { cold {{.*}}}
124 // CHECK: attributes [[HOTSITE]] = { hot {{.*}}}
125 // CHECK: attributes [[NOCF_CHECK_CALL]] = { nocf_check }
126