blob: 4da3eca9e49e044553fdbfc0978ee430b2becaa3 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -emit-llvm -triple i386-linux-gnu -o %t %s
Mike Stump31c51412009-10-06 22:58:45 +00002// RUN: FileCheck --input-file=%t %s
Daniel Dunbard58139e2008-09-27 00:39:13 +00003
Mike Stump31c51412009-10-06 22:58:45 +00004// CHECK: @t5 = weak global i32 2
Chris Lattnerddee4232008-03-03 03:28:21 +00005int t5 __attribute__((weak)) = 2;
6
Chris Lattnerc5cbb902011-06-20 04:01:35 +00007// CHECK: @t13 = global %struct.s0 zeroinitializer, section "SECT"
Daniel Dunbar17f194f2009-02-12 17:28:23 +00008struct s0 { int x; };
Daniel Dunbar30510ab2009-02-12 23:32:54 +00009struct s0 t13 __attribute__((section("SECT"))) = { 0 };
10
Mike Stump31c51412009-10-06 22:58:45 +000011// CHECK: @t14.x = internal global i32 0, section "SECT"
Daniel Dunbar30510ab2009-02-12 23:32:54 +000012void t14(void) {
13 static int x __attribute__((section("SECT"))) = 0;
14}
Daniel Dunbar5e273142009-03-06 16:20:49 +000015
Mike Stump31c51412009-10-06 22:58:45 +000016// CHECK: @t18 = global i32 1, align 4
17extern int t18 __attribute__((weak_import));
18int t18 = 1;
19
20// CHECK: @t16 = extern_weak global i32
Daniel Dunbar5e273142009-03-06 16:20:49 +000021extern int t16 __attribute__((weak_import));
Mike Stump31c51412009-10-06 22:58:45 +000022
23// CHECK: @t6 = common protected global i32 0
24int t6 __attribute__((visibility("protected")));
25
26// CHECK: @t12 = global i32 0, section "SECT"
27int t12 __attribute__((section("SECT")));
28
Stephen Hines176edba2014-12-01 14:53:08 -080029// CHECK: @t9 = weak alias bitcast (void ()* @__t8 to void (...)*)
Mike Stump31c51412009-10-06 22:58:45 +000030void __t8() {}
31void t9() __attribute__((weak, alias("__t8")));
32
33// CHECK: declare extern_weak i32 @t15()
34int __attribute__((weak_import)) t15(void);
Daniel Dunbar5e273142009-03-06 16:20:49 +000035int t17() {
36 return t15() + t16;
37}
38
Bill Wendlingc3af6792013-02-26 23:08:48 +000039// CHECK: define void @t1() [[NR:#[0-9]+]] {
Mike Stump31c51412009-10-06 22:58:45 +000040void t1() __attribute__((noreturn));
41void t1() { while (1) {} }
Daniel Dunbar5e273142009-03-06 16:20:49 +000042
Bill Wendlingc3af6792013-02-26 23:08:48 +000043// CHECK: define void @t2() [[NUW:#[0-9]+]] {
Mike Stump31c51412009-10-06 22:58:45 +000044void t2() __attribute__((nothrow));
45void t2() {}
46
Bill Wendlingc3af6792013-02-26 23:08:48 +000047// CHECK: define weak void @t3() [[NUW]] {
Mike Stump31c51412009-10-06 22:58:45 +000048void t3() __attribute__((weak));
49void t3() {}
50
Bill Wendlingc3af6792013-02-26 23:08:48 +000051// CHECK: define hidden void @t4() [[NUW]] {
Mike Stump31c51412009-10-06 22:58:45 +000052void t4() __attribute__((visibility("hidden")));
53void t4() {}
54
Bill Wendlingc3af6792013-02-26 23:08:48 +000055// CHECK: define void @t7() [[NR]] {
Mike Stump31c51412009-10-06 22:58:45 +000056void t7() __attribute__((noreturn, nothrow));
57void t7() { while (1) {} }
58
Bill Wendlingc3af6792013-02-26 23:08:48 +000059// CHECK: define void @t10() [[NUW]] section "SECT" {
Mike Stump31c51412009-10-06 22:58:45 +000060void t10(void) __attribute__((section("SECT")));
61void t10(void) {}
Bill Wendlingc3af6792013-02-26 23:08:48 +000062// CHECK: define void @t11() [[NUW]] section "SECT" {
Mike Stump31c51412009-10-06 22:58:45 +000063void __attribute__((section("SECT"))) t11(void) {}
64
Bill Wendlingc3af6792013-02-26 23:08:48 +000065// CHECK: define i32 @t19() [[NUW]] {
Daniel Dunbar2968b772009-06-05 22:58:34 +000066extern int t19(void) __attribute__((weak_import));
67int t19(void) {
68 return 10;
69}
70
Bill Wendlingc3af6792013-02-26 23:08:48 +000071// CHECK:define void @t20() [[NUW]] {
Daniel Dunbar131c9812009-11-11 03:48:34 +000072// CHECK: call void @abort()
Mike Stump31c51412009-10-06 22:58:45 +000073// CHECK-NEXT: unreachable
74void t20(void) {
75 __builtin_abort();
76}
John McCall04a67a62010-02-05 21:31:56 +000077
78void (__attribute__((fastcall)) *fptr)(int);
79void t21(void) {
80 fptr(10);
81}
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070082// CHECK: [[FPTRVAR:%[a-z0-9]+]] = load void (i32)*, void (i32)** @fptr
Rafael Espindolab6932692012-10-24 01:58:58 +000083// CHECK-NEXT: call x86_fastcallcc void [[FPTRVAR]](i32 inreg 10)
Rafael Espindola6565b8a2012-05-13 01:56:10 +000084
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.
88void __attribute__((section(".foo"))) t22(void);
89void __attribute__((section(".bar"))) t22(void) {}
90
Bill Wendlingc3af6792013-02-26 23:08:48 +000091// CHECK: define void @t22() [[NUW]] section ".bar"
Bill Wendlingf7a9da02013-02-20 07:22:19 +000092
Bill Wendlingc3af6792013-02-26 23:08:48 +000093// CHECK: attributes [[NUW]] = { nounwind{{.*}} }
94// CHECK: attributes [[NR]] = { noreturn nounwind{{.*}} }