blob: 1d685c246559a4e03f4eaa0156bd8379af5a4f74 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -Os -o - %s | FileCheck %s
Bill Wendlingf7a9da02013-02-20 07:22:19 +00002// 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
Daniel Dunbar3a9a3e12008-09-05 00:57:45 +000010
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
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000027// CHECK: define void @f8()
Bill Wendlingf7a9da02013-02-20 07:22:19 +000028// CHECK: #1
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000029// CHECK: {
Daniel Dunbaraf668b02008-10-28 00:17:57 +000030void __attribute__((always_inline)) f8(void) { }
Daniel Dunbarc0ef9f52009-02-20 18:06:48 +000031
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000032// CHECK: call void @f9_t()
33// CHECK: noreturn
Richard Smith7586a6e2013-01-30 05:45:05 +000034// CHECK: }
Daniel Dunbarc0ef9f52009-02-20 18:06:48 +000035void __attribute__((noreturn)) f9_t(void);
36void f9(void) { f9_t(); }
37
Richard Smith7586a6e2013-01-30 05:45:05 +000038// CHECK: call void @f9a()
39// CHECK: noreturn
40// CHECK: }
41_Noreturn void f9a(void);
42void f9b(void) { f9a(); }
43
Daniel Dunbarc0ef9f52009-02-20 18:06:48 +000044// FIXME: We should be setting nounwind on calls.
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000045// CHECK: call i32 @f10_t()
46// CHECK: readnone
47// CHECK: {
Daniel Dunbarc0ef9f52009-02-20 18:06:48 +000048int __attribute__((const)) f10_t(void);
49int f10(void) { return f10_t(); }
Daniel Dunbar0334a4e2009-02-25 20:59:29 +000050int f11(void) {
51 exit:
52 return f10_t();
53}
54int f12(int arg) {
55 return arg ? 0 : f10_t();
56}
Daniel Dunbarc0ef9f52009-02-20 18:06:48 +000057
Bill Wendlingf7a9da02013-02-20 07:22:19 +000058// CHECK: define void @f13() #0
Daniel Dunbar64c2e072009-04-10 22:14:52 +000059void f13(void) __attribute__((pure)) __attribute__((const));
60void f13(void){}
61
Chris Lattnerbdb01322009-05-05 06:16:31 +000062
63// Ensure that these get inlined: rdar://6853279
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000064// CHECK: define void @f14
Daniel Dunbar0aa94242009-10-27 19:48:00 +000065// CHECK-NOT: @ai_
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000066// CHECK: call void @f14_end
Chris Lattnerbdb01322009-05-05 06:16:31 +000067static __inline__ __attribute__((always_inline))
68int ai_1() { return 4; }
69
70static __inline__ __attribute__((always_inline))
71struct {
72 int a, b, c, d, e;
Mike Stumpc36541e2009-07-21 20:52:43 +000073} ai_2() { while (1) {} }
Chris Lattnerbdb01322009-05-05 06:16:31 +000074
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000075void 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
Bill Wendlingf7a9da02013-02-20 07:22:19 +000085// CHECK: #0
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000086// CHECK: {
87void f15(void) {
Chris Lattnerbdb01322009-05-05 06:16:31 +000088}
Charles Davis74f72932010-02-13 15:54:06 +000089
90// PR5254
91// CHECK: define void @f16
Bill Wendlingf7a9da02013-02-20 07:22:19 +000092// CHECK: #6
Charles Davis74f72932010-02-13 15:54:06 +000093// CHECK: {
94void __attribute__((force_align_arg_pointer)) f16(void) {
95}
96
Rafael Espindolaf87cced2011-10-03 14:59:42 +000097// PR11038
98// CHECK: define void @f18()
Bill Wendlingf7a9da02013-02-20 07:22:19 +000099// CHECK: #7
Rafael Espindolaf87cced2011-10-03 14:59:42 +0000100// 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}
Rafael Espindola67004152011-10-12 19:51:18 +0000108
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}
Bill Wendlingf7a9da02013-02-20 07:22:19 +0000119
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"={{.*}}