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