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