]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGen/inline.c
Vendor import of clang release_34 branch r197841 (effectively, 3.4 RC3):
[FreeBSD/FreeBSD.git] / test / CodeGen / inline.c
1 // RUN: echo "GNU89 tests:"
2 // RUN: %clang_cc1 %s -triple i386-unknown-unknown -O1 -disable-llvm-optzns -emit-llvm -o - -std=gnu89 | FileCheck %s --check-prefix=CHECK1
3 // CHECK1-LABEL: define i32 @foo()
4 // CHECK1-LABEL: define i32 @bar()
5 // CHECK1-LABEL: define void @unreferenced1()
6 // CHECK1-NOT: unreferenced2
7 // CHECK1-LABEL: define void @gnu_inline()
8 // CHECK1-LABEL: define i32 @test1
9 // CHECK1-LABEL: define i32 @test2
10 // CHECK1-LABEL: define void @test3()
11 // CHECK1-LABEL: define available_externally i32 @test4
12 // CHECK1-LABEL: define available_externally i32 @test5
13 // CHECK1-LABEL: define i32 @test6
14 // CHECK1-LABEL: define void @test7
15 // CHECK1: define i{{..}} @strlcpy
16 // CHECK1-NOT: test9
17 // CHECK1-LABEL: define void @testA
18 // CHECK1-LABEL: define void @testB
19 // CHECK1-LABEL: define void @testC
20 // CHECK1-LABEL: define available_externally void @gnu_ei_inline()
21 // CHECK1-LABEL: define available_externally i32 @ei()
22
23 // RUN: echo "C99 tests:"
24 // RUN: %clang_cc1 %s -triple i386-unknown-unknown -O1 -disable-llvm-optzns -emit-llvm -o - -std=gnu99 | FileCheck %s --check-prefix=CHECK2
25 // CHECK2-LABEL: define i32 @ei()
26 // CHECK2-LABEL: define i32 @bar()
27 // CHECK2-NOT: unreferenced1
28 // CHECK2-LABEL: define void @unreferenced2()
29 // CHECK2-LABEL: define void @gnu_inline()
30 // CHECK2-LABEL: define i32 @test1
31 // CHECK2-LABEL: define i32 @test2
32 // CHECK2-LABEL: define void @test3
33 // CHECK2-LABEL: define available_externally i32 @test4
34 // CHECK2-LABEL: define available_externally i32 @test5
35 // CHECK2-LABEL: define i32 @test6
36 // CHECK2-LABEL: define void @test7
37 // CHECK2: define available_externally i{{..}} @strlcpy
38 // CHECK2-LABEL: define void @test9
39 // CHECK2-LABEL: define void @testA
40 // CHECK2-LABEL: define void @testB
41 // CHECK2-LABEL: define void @testC
42 // CHECK2-LABEL: define available_externally void @gnu_ei_inline()
43 // CHECK2-LABEL: define available_externally i32 @foo()
44
45 // RUN: echo "C++ tests:"
46 // RUN: %clang_cc1 -x c++ %s -triple i386-unknown-unknown -O1 -disable-llvm-optzns -emit-llvm -o - -std=c++98 | FileCheck %s --check-prefix=CHECK3
47 // CHECK3-LABEL: define i32 @_Z3barv()
48 // CHECK3-LABEL: define linkonce_odr i32 @_Z3foov()
49 // CHECK3-NOT: unreferenced
50 // CHECK3-LABEL: define void @_Z10gnu_inlinev()
51 // CHECK3-LABEL: define available_externally void @_Z13gnu_ei_inlinev()
52 // CHECK3-LABEL: define linkonce_odr i32 @_Z2eiv()
53
54 // RUN: echo "MS C Mode tests:"
55 // RUN: %clang_cc1 %s -triple i386-unknown-unknown -O1 -disable-llvm-optzns -emit-llvm -o - -std=c99 -fms-compatibility | FileCheck %s --check-prefix=CHECK4
56 // CHECK4-LABEL: define i32 @bar()
57 // CHECK4-LABEL: define void @gnu_inline()
58 // CHECK4-LABEL: define available_externally void @gnu_ei_inline()
59 // CHECK4-LABEL: define linkonce_odr i32 @foo()
60 // CHECK4-NOT: unreferenced
61 // CHECK4-LABEL: define linkonce_odr i32 @ei()
62
63 extern __inline int ei() { return 123; }
64
65 __inline int foo() {
66   return ei();
67 }
68
69 int bar() { return foo(); }
70
71
72 __inline void unreferenced1() {}
73 extern __inline void unreferenced2() {}
74
75 __inline __attribute((__gnu_inline__)) void gnu_inline() {}
76
77 // PR3988
78 extern __inline __attribute__((gnu_inline)) void gnu_ei_inline() {}
79 void (*P)() = gnu_ei_inline;
80
81 // <rdar://problem/6818429>
82 int test1();
83 __inline int test1() { return 4; }
84 __inline int test2() { return 5; }
85 __inline int test2();
86 int test2();
87
88 void test_test1() { test1(); }
89 void test_test2() { test2(); }
90
91 // PR3989
92 extern __inline void test3() __attribute__((gnu_inline));
93 __inline void __attribute__((gnu_inline)) test3() {}
94
95 extern int test4(void);
96 extern __inline __attribute__ ((__gnu_inline__)) int test4(void)
97 {
98   return 0;
99 }
100
101 void test_test4() { test4(); }
102
103 extern __inline int test5(void)  __attribute__ ((__gnu_inline__));
104 extern __inline int __attribute__ ((__gnu_inline__)) test5(void)
105 {
106   return 0;
107 }
108
109 void test_test5() { test5(); }
110
111 // PR10233
112
113 __inline int test6() { return 0; }
114 extern int test6();
115
116
117 // No PR#, but this once crashed clang in C99 mode due to buggy extern inline
118 // redeclaration detection.
119 void test7() { }
120 void test7();
121
122 // PR11062; the fact that the function is named strlcpy matters here.
123 inline __typeof(sizeof(int)) strlcpy(char *dest, const char *src, __typeof(sizeof(int)) size) { return 3; }
124 void test8() { strlcpy(0,0,0); }
125
126 // PR10657; the test crashed in C99 mode
127 extern inline void test9() { }
128 void test9();
129
130 inline void testA() {}
131 void testA();
132
133 void testB();
134 inline void testB() {}
135 extern void testB();
136
137 extern inline void testC() {}
138 inline void testC();