Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -triple i386-linux-gnu -o %t %s |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 2 | // RUN: FileCheck --input-file=%t %s |
Daniel Dunbar | d58139e | 2008-09-27 00:39:13 +0000 | [diff] [blame] | 3 | |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 4 | // CHECK: @t5 = weak global i32 2 |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 5 | int t5 __attribute__((weak)) = 2; |
| 6 | |
Chris Lattner | c5cbb90 | 2011-06-20 04:01:35 +0000 | [diff] [blame] | 7 | // CHECK: @t13 = global %struct.s0 zeroinitializer, section "SECT" |
Daniel Dunbar | 17f194f | 2009-02-12 17:28:23 +0000 | [diff] [blame] | 8 | struct s0 { int x; }; |
Daniel Dunbar | 30510ab | 2009-02-12 23:32:54 +0000 | [diff] [blame] | 9 | struct s0 t13 __attribute__((section("SECT"))) = { 0 }; |
| 10 | |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 11 | // CHECK: @t14.x = internal global i32 0, section "SECT" |
Daniel Dunbar | 30510ab | 2009-02-12 23:32:54 +0000 | [diff] [blame] | 12 | void t14(void) { |
| 13 | static int x __attribute__((section("SECT"))) = 0; |
| 14 | } |
Daniel Dunbar | 5e27314 | 2009-03-06 16:20:49 +0000 | [diff] [blame] | 15 | |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 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 |
Daniel Dunbar | 5e27314 | 2009-03-06 16:20:49 +0000 | [diff] [blame] | 21 | extern int t16 __attribute__((weak_import)); |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 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 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 29 | // CHECK: @t9 = weak alias bitcast (void ()* @__t8 to void (...)*) |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 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); |
Daniel Dunbar | 5e27314 | 2009-03-06 16:20:49 +0000 | [diff] [blame] | 35 | int t17() { |
| 36 | return t15() + t16; |
| 37 | } |
| 38 | |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 39 | // CHECK: define void @t1() [[NR:#[0-9]+]] { |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 40 | void t1() __attribute__((noreturn)); |
| 41 | void t1() { while (1) {} } |
Daniel Dunbar | 5e27314 | 2009-03-06 16:20:49 +0000 | [diff] [blame] | 42 | |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 43 | // CHECK: define void @t2() [[NUW:#[0-9]+]] { |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 44 | void t2() __attribute__((nothrow)); |
| 45 | void t2() {} |
| 46 | |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 47 | // CHECK: define weak void @t3() [[NUW]] { |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 48 | void t3() __attribute__((weak)); |
| 49 | void t3() {} |
| 50 | |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 51 | // CHECK: define hidden void @t4() [[NUW]] { |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 52 | void t4() __attribute__((visibility("hidden"))); |
| 53 | void t4() {} |
| 54 | |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 55 | // CHECK: define void @t7() [[NR]] { |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 56 | void t7() __attribute__((noreturn, nothrow)); |
| 57 | void t7() { while (1) {} } |
| 58 | |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 59 | // CHECK: define void @t10() [[NUW]] section "SECT" { |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 60 | void t10(void) __attribute__((section("SECT"))); |
| 61 | void t10(void) {} |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 62 | // CHECK: define void @t11() [[NUW]] section "SECT" { |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 63 | void __attribute__((section("SECT"))) t11(void) {} |
| 64 | |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 65 | // CHECK: define i32 @t19() [[NUW]] { |
Daniel Dunbar | 2968b77 | 2009-06-05 22:58:34 +0000 | [diff] [blame] | 66 | extern int t19(void) __attribute__((weak_import)); |
| 67 | int t19(void) { |
| 68 | return 10; |
| 69 | } |
| 70 | |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 71 | // CHECK:define void @t20() [[NUW]] { |
Daniel Dunbar | 131c981 | 2009-11-11 03:48:34 +0000 | [diff] [blame] | 72 | // CHECK: call void @abort() |
Mike Stump | 31c5141 | 2009-10-06 22:58:45 +0000 | [diff] [blame] | 73 | // CHECK-NEXT: unreachable |
| 74 | void t20(void) { |
| 75 | __builtin_abort(); |
| 76 | } |
John McCall | 04a67a6 | 2010-02-05 21:31:56 +0000 | [diff] [blame] | 77 | |
| 78 | void (__attribute__((fastcall)) *fptr)(int); |
| 79 | void t21(void) { |
| 80 | fptr(10); |
| 81 | } |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 82 | // CHECK: [[FPTRVAR:%[a-z0-9]+]] = load void (i32)*, void (i32)** @fptr |
Rafael Espindola | b693269 | 2012-10-24 01:58:58 +0000 | [diff] [blame] | 83 | // CHECK-NEXT: call x86_fastcallcc void [[FPTRVAR]](i32 inreg 10) |
Rafael Espindola | 6565b8a | 2012-05-13 01:56:10 +0000 | [diff] [blame] | 84 | |
| 85 | |
| 86 | // PR9356: We might want to err on this, but for now at least make sure we |
| 87 | // use the section in the definition. |
| 88 | void __attribute__((section(".foo"))) t22(void); |
| 89 | void __attribute__((section(".bar"))) t22(void) {} |
| 90 | |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 91 | // CHECK: define void @t22() [[NUW]] section ".bar" |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame] | 92 | |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 93 | // CHECK: attributes [[NUW]] = { nounwind{{.*}} } |
| 94 | // CHECK: attributes [[NR]] = { noreturn nounwind{{.*}} } |