blob: 25ca9163a19178632a38c18a093c2a6e3e93a3d4 [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 Wendlingc3af6792013-02-26 23:08:48 +00002// 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]]
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 Wendlingc3af6792013-02-26 23:08:48 +000028// CHECK: [[AI:#[0-9]+]]
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()
Bill Wendlingc3af6792013-02-26 23:08:48 +000033// CHECK: [[NR:#[0-9]+]]
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()
Bill Wendlingc3af6792013-02-26 23:08:48 +000039// CHECK: [[NR]]
Richard Smith7586a6e2013-01-30 05:45:05 +000040// 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()
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000046// CHECK: [[NUW_RN:#[0-9]+]]
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000047// 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 Wendlingc3af6792013-02-26 23:08:48 +000058// CHECK: define void @f13() [[NUW]]
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 Wendlingc3af6792013-02-26 23:08:48 +000085// CHECK: [[NUW]]
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 Wendlingc3af6792013-02-26 23:08:48 +000092// CHECK: [[ALIGN:#[0-9]+]]
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 Wendlingc3af6792013-02-26 23:08:48 +000099// CHECK: [[RT:#[0-9]+]]
Rafael Espindolaf87cced2011-10-03 14:59:42 +0000100// CHECK: {
101// CHECK: call void @f17()
Bill Wendlingc3af6792013-02-26 23:08:48 +0000102// CHECK: [[RT_CALL:#[0-9]+]]
Rafael Espindolaf87cced2011-10-03 14:59:42 +0000103// 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)
Bill Wendlingc3af6792013-02-26 23:08:48 +0000112// CHECK: [[RT_CALL]]
Rafael Espindola67004152011-10-12 19:51:18 +0000113// 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
Bill Wendlingc3af6792013-02-26 23:08:48 +0000120// CHECK: attributes [[NUW]] = { nounwind optsize readnone{{.*}} }
121// CHECK: attributes [[AI]] = { alwaysinline nounwind optsize readnone{{.*}} }
Bill Wendling89924572013-02-27 00:06:04 +0000122// CHECK: attributes [[ALIGN]] = { nounwind optsize readnone alignstack=16{{.*}} }
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +0000123// 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 }