Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -Os -o - %s | FileCheck %s |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 2 | // 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 Dunbar | 3a9a3e1 | 2008-09-05 00:57:45 +0000 | [diff] [blame] | 10 | |
| 11 | signed char f0(int x) { return x; } |
| 12 | |
| 13 | unsigned char f1(int x) { return x; } |
| 14 | |
| 15 | void f2(signed char x) { } |
| 16 | |
| 17 | void f3(unsigned char x) { } |
| 18 | |
| 19 | signed short f4(int x) { return x; } |
| 20 | |
| 21 | unsigned short f5(int x) { return x; } |
| 22 | |
| 23 | void f6(signed short x) { } |
| 24 | |
| 25 | void f7(unsigned short x) { } |
| 26 | |
Daniel Dunbar | 7ab1c3e | 2009-10-27 19:48:08 +0000 | [diff] [blame] | 27 | // CHECK: define void @f8() |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 28 | // CHECK: [[AI:#[0-9]+]] |
Daniel Dunbar | 7ab1c3e | 2009-10-27 19:48:08 +0000 | [diff] [blame] | 29 | // CHECK: { |
Daniel Dunbar | af668b0 | 2008-10-28 00:17:57 +0000 | [diff] [blame] | 30 | void __attribute__((always_inline)) f8(void) { } |
Daniel Dunbar | c0ef9f5 | 2009-02-20 18:06:48 +0000 | [diff] [blame] | 31 | |
Daniel Dunbar | 7ab1c3e | 2009-10-27 19:48:08 +0000 | [diff] [blame] | 32 | // CHECK: call void @f9_t() |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 33 | // CHECK: [[NR:#[0-9]+]] |
Richard Smith | 7586a6e | 2013-01-30 05:45:05 +0000 | [diff] [blame] | 34 | // CHECK: } |
Daniel Dunbar | c0ef9f5 | 2009-02-20 18:06:48 +0000 | [diff] [blame] | 35 | void __attribute__((noreturn)) f9_t(void); |
| 36 | void f9(void) { f9_t(); } |
| 37 | |
Richard Smith | 7586a6e | 2013-01-30 05:45:05 +0000 | [diff] [blame] | 38 | // CHECK: call void @f9a() |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 39 | // CHECK: [[NR]] |
Richard Smith | 7586a6e | 2013-01-30 05:45:05 +0000 | [diff] [blame] | 40 | // CHECK: } |
| 41 | _Noreturn void f9a(void); |
| 42 | void f9b(void) { f9a(); } |
| 43 | |
Daniel Dunbar | c0ef9f5 | 2009-02-20 18:06:48 +0000 | [diff] [blame] | 44 | // FIXME: We should be setting nounwind on calls. |
Daniel Dunbar | 7ab1c3e | 2009-10-27 19:48:08 +0000 | [diff] [blame] | 45 | // CHECK: call i32 @f10_t() |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 46 | // CHECK: [[NUW_RN:#[0-9]+]] |
Daniel Dunbar | 7ab1c3e | 2009-10-27 19:48:08 +0000 | [diff] [blame] | 47 | // CHECK: { |
Daniel Dunbar | c0ef9f5 | 2009-02-20 18:06:48 +0000 | [diff] [blame] | 48 | int __attribute__((const)) f10_t(void); |
| 49 | int f10(void) { return f10_t(); } |
Daniel Dunbar | 0334a4e | 2009-02-25 20:59:29 +0000 | [diff] [blame] | 50 | int f11(void) { |
| 51 | exit: |
| 52 | return f10_t(); |
| 53 | } |
| 54 | int f12(int arg) { |
| 55 | return arg ? 0 : f10_t(); |
| 56 | } |
Daniel Dunbar | c0ef9f5 | 2009-02-20 18:06:48 +0000 | [diff] [blame] | 57 | |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 58 | // CHECK: define void @f13() [[NUW]] |
Daniel Dunbar | 64c2e07 | 2009-04-10 22:14:52 +0000 | [diff] [blame] | 59 | void f13(void) __attribute__((pure)) __attribute__((const)); |
| 60 | void f13(void){} |
| 61 | |
Chris Lattner | bdb0132 | 2009-05-05 06:16:31 +0000 | [diff] [blame] | 62 | |
| 63 | // Ensure that these get inlined: rdar://6853279 |
Daniel Dunbar | 7ab1c3e | 2009-10-27 19:48:08 +0000 | [diff] [blame] | 64 | // CHECK: define void @f14 |
Daniel Dunbar | 0aa9424 | 2009-10-27 19:48:00 +0000 | [diff] [blame] | 65 | // CHECK-NOT: @ai_ |
Daniel Dunbar | 7ab1c3e | 2009-10-27 19:48:08 +0000 | [diff] [blame] | 66 | // CHECK: call void @f14_end |
Chris Lattner | bdb0132 | 2009-05-05 06:16:31 +0000 | [diff] [blame] | 67 | static __inline__ __attribute__((always_inline)) |
| 68 | int ai_1() { return 4; } |
| 69 | |
| 70 | static __inline__ __attribute__((always_inline)) |
| 71 | struct { |
| 72 | int a, b, c, d, e; |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 73 | } ai_2() { while (1) {} } |
Chris Lattner | bdb0132 | 2009-05-05 06:16:31 +0000 | [diff] [blame] | 74 | |
Daniel Dunbar | 7ab1c3e | 2009-10-27 19:48:08 +0000 | [diff] [blame] | 75 | void 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 Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 85 | // CHECK: [[NUW]] |
Daniel Dunbar | 7ab1c3e | 2009-10-27 19:48:08 +0000 | [diff] [blame] | 86 | // CHECK: { |
| 87 | void f15(void) { |
Chris Lattner | bdb0132 | 2009-05-05 06:16:31 +0000 | [diff] [blame] | 88 | } |
Charles Davis | 74f7293 | 2010-02-13 15:54:06 +0000 | [diff] [blame] | 89 | |
| 90 | // PR5254 |
| 91 | // CHECK: define void @f16 |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 92 | // CHECK: [[ALIGN:#[0-9]+]] |
Charles Davis | 74f7293 | 2010-02-13 15:54:06 +0000 | [diff] [blame] | 93 | // CHECK: { |
| 94 | void __attribute__((force_align_arg_pointer)) f16(void) { |
| 95 | } |
| 96 | |
Rafael Espindola | f87cced | 2011-10-03 14:59:42 +0000 | [diff] [blame] | 97 | // PR11038 |
| 98 | // CHECK: define void @f18() |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 99 | // CHECK: [[RT:#[0-9]+]] |
Rafael Espindola | f87cced | 2011-10-03 14:59:42 +0000 | [diff] [blame] | 100 | // CHECK: { |
| 101 | // CHECK: call void @f17() |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 102 | // CHECK: [[RT_CALL:#[0-9]+]] |
Rafael Espindola | f87cced | 2011-10-03 14:59:42 +0000 | [diff] [blame] | 103 | // CHECK: ret void |
| 104 | __attribute__ ((returns_twice)) void f17(void); |
| 105 | __attribute__ ((returns_twice)) void f18(void) { |
| 106 | f17(); |
| 107 | } |
Rafael Espindola | 6700415 | 2011-10-12 19:51:18 +0000 | [diff] [blame] | 108 | |
| 109 | // CHECK: define void @f19() |
| 110 | // CHECK: { |
| 111 | // CHECK: call i32 @setjmp(i32* null) |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 112 | // CHECK: [[RT_CALL]] |
Rafael Espindola | 6700415 | 2011-10-12 19:51:18 +0000 | [diff] [blame] | 113 | // CHECK: ret void |
| 114 | typedef int jmp_buf[((9 * 2) + 3 + 16)]; |
| 115 | int setjmp(jmp_buf); |
| 116 | void f19(void) { |
| 117 | setjmp(0); |
| 118 | } |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame] | 119 | |
Bill Wendling | c3af679 | 2013-02-26 23:08:48 +0000 | [diff] [blame] | 120 | // CHECK: attributes [[NUW]] = { nounwind optsize readnone{{.*}} } |
| 121 | // CHECK: attributes [[AI]] = { alwaysinline nounwind optsize readnone{{.*}} } |
Bill Wendling | 8992457 | 2013-02-27 00:06:04 +0000 | [diff] [blame] | 122 | // CHECK: attributes [[ALIGN]] = { nounwind optsize readnone alignstack=16{{.*}} } |
Bill Wendling | be9e8bf | 2013-02-28 22:49:57 +0000 | [diff] [blame] | 123 | // 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 } |