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