1 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -Os -o - %s | FileCheck %s
2 // CHECK: define signext i8 @f0(i32 %x) [[NUW:#[0-9]+]]
3 // CHECK: define zeroext i8 @f1(i32 %x) [[NUW]]
4 // CHECK: define void @f2(i8 signext %x) [[NUW]]
5 // CHECK: define void @f3(i8 zeroext %x) [[NUW]]
6 // CHECK: define signext i16 @f4(i32 %x) [[NUW]]
7 // CHECK: define zeroext i16 @f5(i32 %x) [[NUW]]
8 // CHECK: define void @f6(i16 signext %x) [[NUW]]
9 // CHECK: define void @f7(i16 zeroext %x) [[NUW]]
10 
11 signed char f0(int x) { return x; }
12 
13 unsigned char f1(int x) { return x; }
14 
15 void f2(signed char x) { }
16 
17 void f3(unsigned char x) { }
18 
19 signed short f4(int x) { return x; }
20 
21 unsigned short f5(int x) { return x; }
22 
23 void f6(signed short x) { }
24 
25 void f7(unsigned short x) { }
26 
27 // CHECK-LABEL: define void @f8()
28 // CHECK: [[AI:#[0-9]+]]
29 // CHECK: {
30 void __attribute__((always_inline)) f8(void) { }
31 
32 // CHECK: call void @f9_t()
33 // CHECK: [[NR:#[0-9]+]]
34 // CHECK: }
35 void __attribute__((noreturn)) f9_t(void);
36 void f9(void) { f9_t(); }
37 
38 // CHECK: call void @f9a()
39 // CHECK: [[NR]]
40 // CHECK: }
41 _Noreturn void f9a(void);
42 void f9b(void) { f9a(); }
43 
44 // FIXME: We should be setting nounwind on calls.
45 // CHECK: call i32 @f10_t()
46 // CHECK: [[NUW_RN:#[0-9]+]]
47 // CHECK: {
48 int __attribute__((const)) f10_t(void);
49 int f10(void) { return f10_t(); }
50 int f11(void) {
51  exit:
52   return f10_t();
53 }
54 int f12(int arg) {
55   return arg ? 0 : f10_t();
56 }
57 
58 // CHECK: define void @f13() [[NUW]]
59 void f13(void) __attribute__((pure)) __attribute__((const));
60 void f13(void){}
61 
62 
63 // Ensure that these get inlined: rdar://6853279
64 // CHECK-LABEL: define void @f14
65 // CHECK-NOT: @ai_
66 // CHECK: call void @f14_end
67 static __inline__ __attribute__((always_inline))
68 int ai_1() {  return 4; }
69 
70 static __inline__ __attribute__((always_inline))
71 struct {
72   int a, b, c, d, e;
73 } ai_2() { while (1) {} }
74 
75 void f14(int a) {
76   extern void f14_end(void);
77   if (a)
78     ai_2();
79   ai_1();
80   f14_end();
81 }
82 
83 // <rdar://problem/7102668> [irgen] clang isn't setting the optsize bit on functions
84 // CHECK-LABEL: define void @f15
85 // CHECK: [[NUW]]
86 // CHECK: {
87 void f15(void) {
88 }
89 
90 // PR5254
91 // CHECK-LABEL: define void @f16
92 // CHECK: [[ALIGN:#[0-9]+]]
93 // CHECK: {
94 void __attribute__((force_align_arg_pointer)) f16(void) {
95 }
96 
97 // PR11038
98 // CHECK-LABEL: define void @f18()
99 // CHECK: [[RT:#[0-9]+]]
100 // CHECK: {
101 // CHECK: call void @f17()
102 // CHECK: [[RT_CALL:#[0-9]+]]
103 // CHECK: ret void
104 __attribute__ ((returns_twice)) void f17(void);
105 __attribute__ ((returns_twice)) void f18(void) {
106         f17();
107 }
108 
109 // CHECK-LABEL: define void @f19()
110 // CHECK: {
111 // CHECK: call i32 @setjmp(i32* null)
112 // CHECK: [[RT_CALL]]
113 // CHECK: ret void
114 typedef int jmp_buf[((9 * 2) + 3 + 16)];
115 int setjmp(jmp_buf);
116 void f19(void) {
117   setjmp(0);
118 }
119 
120 // CHECK: attributes [[NUW]] = { nounwind optsize readnone{{.*}} }
121 // CHECK: attributes [[AI]] = { alwaysinline nounwind optsize readnone{{.*}} }
122 // CHECK: attributes [[ALIGN]] = { nounwind optsize readnone alignstack=16{{.*}} }
123 // CHECK: attributes [[RT]] = { nounwind optsize returns_twice{{.*}} }
124 // CHECK: attributes [[NR]] = { noreturn nounwind optsize }
125 // CHECK: attributes [[NUW_RN]] = { nounwind optsize readnone }
126 // CHECK: attributes [[RT_CALL]] = { nounwind optsize returns_twice }
127