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