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