function-attributes.c revision f7a9da053f5bd6c18450c1796d953b42c3b7ad3a
1// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -Os -o - %s | FileCheck %s
2// CHECK: define signext i8 @f0(i32 %x) #0
3// CHECK: define zeroext i8 @f1(i32 %x) #0
4// CHECK: define void @f2(i8 signext %x) #0
5// CHECK: define void @f3(i8 zeroext %x) #0
6// CHECK: define signext i16 @f4(i32 %x) #0
7// CHECK: define zeroext i16 @f5(i32 %x) #0
8// CHECK: define void @f6(i16 signext %x) #0
9// CHECK: define void @f7(i16 zeroext %x) #0
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: #1
29// CHECK: {
30void __attribute__((always_inline)) f8(void) { }
31
32// CHECK: call void @f9_t()
33// CHECK: noreturn
34// CHECK: }
35void __attribute__((noreturn)) f9_t(void);
36void f9(void) { f9_t(); }
37
38// CHECK: call void @f9a()
39// CHECK: noreturn
40// CHECK: }
41_Noreturn void f9a(void);
42void f9b(void) { f9a(); }
43
44// FIXME: We should be setting nounwind on calls.
45// CHECK: call i32 @f10_t()
46// CHECK: readnone
47// CHECK: {
48int __attribute__((const)) f10_t(void);
49int f10(void) { return f10_t(); }
50int f11(void) {
51 exit:
52  return f10_t();
53}
54int f12(int arg) {
55  return arg ? 0 : f10_t();
56}
57
58// CHECK: define void @f13() #0
59void f13(void) __attribute__((pure)) __attribute__((const));
60void f13(void){}
61
62
63// Ensure that these get inlined: rdar://6853279
64// CHECK: define void @f14
65// CHECK-NOT: @ai_
66// CHECK: call void @f14_end
67static __inline__ __attribute__((always_inline))
68int ai_1() {  return 4; }
69
70static __inline__ __attribute__((always_inline))
71struct {
72  int a, b, c, d, e;
73} ai_2() { while (1) {} }
74
75void 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: define void @f15
85// CHECK: #0
86// CHECK: {
87void f15(void) {
88}
89
90// PR5254
91// CHECK: define void @f16
92// CHECK: #6
93// CHECK: {
94void __attribute__((force_align_arg_pointer)) f16(void) {
95}
96
97// PR11038
98// CHECK: define void @f18()
99// CHECK: #7
100// CHECK: {
101// CHECK: call void @f17()
102// CHECK: returns_twice
103// CHECK: ret void
104__attribute__ ((returns_twice)) void f17(void);
105__attribute__ ((returns_twice)) void f18(void) {
106        f17();
107}
108
109// CHECK: define void @f19()
110// CHECK: {
111// CHECK: call i32 @setjmp(i32* null)
112// CHECK: returns_twice
113// CHECK: ret void
114typedef int jmp_buf[((9 * 2) + 3 + 16)];
115int setjmp(jmp_buf);
116void f19(void) {
117  setjmp(0);
118}
119
120// CHECK: attributes #0 = { nounwind optsize readnone "target-features"={{.*}} }
121// CHECK: attributes #1 = { alwaysinline nounwind optsize readnone "target-features"={{.*}} }
122// CHECK: attributes #2 = { noreturn nounwind optsize "target-features"={{.*}} }
123// CHECK: attributes #3 = { noreturn optsize "target-features"={{.*}} }
124// CHECK: attributes #4 = { nounwind optsize "target-features"={{.*}} }
125// CHECK: attributes #5 = { optsize "target-features"={{.*}} }
126// CHECK: attributes #6 = { nounwind optsize readnone alignstack=16 "target-features"={{.*}} }
127// CHECK: attributes #7 = { nounwind optsize returns_twice "target-features"={{.*}} }
128// CHECK: attributes #8 = { optsize returns_twice "target-features"={{.*}}
129