blob: 177ad848f74389a95f40d36da6ea02c5969bc401 [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
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -Os -std=c99 -o - %s | FileCheck %s
Bill Wendlingc3af6792013-02-26 23:08:48 +00003// CHECK: define signext i8 @f0(i32 %x) [[NUW:#[0-9]+]]
4// CHECK: define zeroext i8 @f1(i32 %x) [[NUW]]
5// CHECK: define void @f2(i8 signext %x) [[NUW]]
6// CHECK: define void @f3(i8 zeroext %x) [[NUW]]
7// CHECK: define signext i16 @f4(i32 %x) [[NUW]]
8// CHECK: define zeroext i16 @f5(i32 %x) [[NUW]]
9// CHECK: define void @f6(i16 signext %x) [[NUW]]
10// CHECK: define void @f7(i16 zeroext %x) [[NUW]]
Daniel Dunbar3a9a3e12008-09-05 00:57:45 +000011
12signed char f0(int x) { return x; }
13
14unsigned char f1(int x) { return x; }
15
16void f2(signed char x) { }
17
18void f3(unsigned char x) { }
19
20signed short f4(int x) { return x; }
21
22unsigned short f5(int x) { return x; }
23
24void f6(signed short x) { }
25
26void f7(unsigned short x) { }
27
Stephen Lin93ab6bf2013-08-15 06:47:53 +000028// CHECK-LABEL: define void @f8()
Bill Wendlingc3af6792013-02-26 23:08:48 +000029// CHECK: [[AI:#[0-9]+]]
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000030// CHECK: {
Daniel Dunbaraf668b02008-10-28 00:17:57 +000031void __attribute__((always_inline)) f8(void) { }
Daniel Dunbarc0ef9f52009-02-20 18:06:48 +000032
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000033// CHECK: call void @f9_t()
Bill Wendlingc3af6792013-02-26 23:08:48 +000034// CHECK: [[NR:#[0-9]+]]
Richard Smith7586a6e2013-01-30 05:45:05 +000035// CHECK: }
Daniel Dunbarc0ef9f52009-02-20 18:06:48 +000036void __attribute__((noreturn)) f9_t(void);
37void f9(void) { f9_t(); }
38
Richard Smith7586a6e2013-01-30 05:45:05 +000039// CHECK: call void @f9a()
Bill Wendlingc3af6792013-02-26 23:08:48 +000040// CHECK: [[NR]]
Richard Smith7586a6e2013-01-30 05:45:05 +000041// CHECK: }
42_Noreturn void f9a(void);
43void f9b(void) { f9a(); }
44
Daniel Dunbarc0ef9f52009-02-20 18:06:48 +000045// FIXME: We should be setting nounwind on calls.
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000046// CHECK: call i32 @f10_t()
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000047// CHECK: [[NUW_RN:#[0-9]+]]
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000048// CHECK: {
Daniel Dunbarc0ef9f52009-02-20 18:06:48 +000049int __attribute__((const)) f10_t(void);
50int f10(void) { return f10_t(); }
Daniel Dunbar0334a4e2009-02-25 20:59:29 +000051int f11(void) {
52 exit:
53 return f10_t();
54}
55int f12(int arg) {
56 return arg ? 0 : f10_t();
57}
Daniel Dunbarc0ef9f52009-02-20 18:06:48 +000058
Bill Wendlingc3af6792013-02-26 23:08:48 +000059// CHECK: define void @f13() [[NUW]]
Daniel Dunbar64c2e072009-04-10 22:14:52 +000060void f13(void) __attribute__((pure)) __attribute__((const));
61void f13(void){}
62
Chris Lattnerbdb01322009-05-05 06:16:31 +000063
64// Ensure that these get inlined: rdar://6853279
Stephen Lin93ab6bf2013-08-15 06:47:53 +000065// CHECK-LABEL: define void @f14
Daniel Dunbar0aa94242009-10-27 19:48:00 +000066// CHECK-NOT: @ai_
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000067// CHECK: call void @f14_end
Chris Lattnerbdb01322009-05-05 06:16:31 +000068static __inline__ __attribute__((always_inline))
69int ai_1() { return 4; }
70
71static __inline__ __attribute__((always_inline))
72struct {
73 int a, b, c, d, e;
Mike Stumpc36541e2009-07-21 20:52:43 +000074} ai_2() { while (1) {} }
Chris Lattnerbdb01322009-05-05 06:16:31 +000075
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000076void f14(int a) {
77 extern void f14_end(void);
78 if (a)
79 ai_2();
80 ai_1();
81 f14_end();
82}
83
84// <rdar://problem/7102668> [irgen] clang isn't setting the optsize bit on functions
Stephen Lin93ab6bf2013-08-15 06:47:53 +000085// CHECK-LABEL: define void @f15
Bill Wendlingc3af6792013-02-26 23:08:48 +000086// CHECK: [[NUW]]
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +000087// CHECK: {
88void f15(void) {
Chris Lattnerbdb01322009-05-05 06:16:31 +000089}
Charles Davis74f72932010-02-13 15:54:06 +000090
91// PR5254
Stephen Lin93ab6bf2013-08-15 06:47:53 +000092// CHECK-LABEL: define void @f16
Bill Wendlingc3af6792013-02-26 23:08:48 +000093// CHECK: [[ALIGN:#[0-9]+]]
Charles Davis74f72932010-02-13 15:54:06 +000094// CHECK: {
95void __attribute__((force_align_arg_pointer)) f16(void) {
96}
97
Rafael Espindolaf87cced2011-10-03 14:59:42 +000098// PR11038
Stephen Lin93ab6bf2013-08-15 06:47:53 +000099// CHECK-LABEL: define void @f18()
Bill Wendlingc3af6792013-02-26 23:08:48 +0000100// CHECK: [[RT:#[0-9]+]]
Rafael Espindolaf87cced2011-10-03 14:59:42 +0000101// CHECK: {
102// CHECK: call void @f17()
Bill Wendlingc3af6792013-02-26 23:08:48 +0000103// CHECK: [[RT_CALL:#[0-9]+]]
Rafael Espindolaf87cced2011-10-03 14:59:42 +0000104// CHECK: ret void
105__attribute__ ((returns_twice)) void f17(void);
106__attribute__ ((returns_twice)) void f18(void) {
107 f17();
108}
Rafael Espindola67004152011-10-12 19:51:18 +0000109
Stephen Lin93ab6bf2013-08-15 06:47:53 +0000110// CHECK-LABEL: define void @f19()
Rafael Espindola67004152011-10-12 19:51:18 +0000111// CHECK: {
112// CHECK: call i32 @setjmp(i32* null)
Bill Wendlingc3af6792013-02-26 23:08:48 +0000113// CHECK: [[RT_CALL]]
Rafael Espindola67004152011-10-12 19:51:18 +0000114// CHECK: ret void
115typedef int jmp_buf[((9 * 2) + 3 + 16)];
116int setjmp(jmp_buf);
117void f19(void) {
118 setjmp(0);
119}
Bill Wendlingf7a9da02013-02-20 07:22:19 +0000120
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700121// CHECK-LABEL: define void @f20()
122// CHECK: {
123// CHECK: call i32 @_setjmp(i32* null)
124// CHECK: [[RT_CALL]]
125// CHECK: ret void
126int _setjmp(jmp_buf);
127void f20(void) {
128 _setjmp(0);
129}
130
Bill Wendlingc3af6792013-02-26 23:08:48 +0000131// CHECK: attributes [[NUW]] = { nounwind optsize readnone{{.*}} }
132// CHECK: attributes [[AI]] = { alwaysinline nounwind optsize readnone{{.*}} }
Bill Wendling89924572013-02-27 00:06:04 +0000133// CHECK: attributes [[ALIGN]] = { nounwind optsize readnone alignstack=16{{.*}} }
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +0000134// CHECK: attributes [[RT]] = { nounwind optsize returns_twice{{.*}} }
135// CHECK: attributes [[NR]] = { noreturn nounwind optsize }
136// CHECK: attributes [[NUW_RN]] = { nounwind optsize readnone }
137// CHECK: attributes [[RT_CALL]] = { nounwind optsize returns_twice }