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