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