[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / inline.c
blob9c4043f843fe4f91d7d7226505e2d89ce2febf93
1 // REQUIRES: x86-registered-target
2 //
3 // RUN: echo "GNU89 tests:"
4 // RUN: %clang_cc1 %s -triple i386-unknown-unknown -Wno-strict-prototypes -O1 -disable-llvm-passes -emit-llvm -o - -std=gnu89 | FileCheck %s --check-prefix=CHECK1
5 // CHECK1-LABEL: define{{.*}} i32 @foo()
6 // CHECK1-LABEL: define{{.*}} i32 @bar()
7 // CHECK1-LABEL: define{{.*}} void @unreferenced1()
8 // CHECK1-NOT: unreferenced2
9 // CHECK1-LABEL: define{{.*}} void @gnu_inline()
10 // CHECK1-LABEL: define{{.*}} i32 @test1
11 // CHECK1-LABEL: define{{.*}} i32 @test2
12 // CHECK1-LABEL: define{{.*}} void @test3()
13 // CHECK1-LABEL: define available_externally i32 @test4
14 // CHECK1-LABEL: define available_externally i32 @test5
15 // CHECK1-LABEL: define{{.*}} i32 @test6
16 // CHECK1-LABEL: define{{.*}} void @test7
17 // CHECK1: define{{.*}} i{{..}} @strlcpy
18 // CHECK1-NOT: test9
19 // CHECK1-LABEL: define{{.*}} void @testA
20 // CHECK1-LABEL: define{{.*}} void @testB
21 // CHECK1-LABEL: define{{.*}} void @testC
22 // CHECK1-LABEL: define available_externally i32 @ei()
23 // CHECK1-LABEL: define available_externally void @gnu_ei_inline()
25 // RUN: echo "C99 tests:"
26 // RUN: %clang_cc1 %s -triple i386-unknown-unknown -Wno-strict-prototypes -O1 -disable-llvm-passes -emit-llvm -o - -std=gnu99 | FileCheck %s --check-prefix=CHECK2
27 // CHECK2-LABEL: define{{.*}} i32 @ei()
28 // CHECK2-LABEL: define{{.*}} i32 @bar()
29 // CHECK2-NOT: unreferenced1
30 // CHECK2-LABEL: define{{.*}} void @unreferenced2()
31 // CHECK2-LABEL: define{{.*}} void @gnu_inline()
32 // CHECK2-LABEL: define{{.*}} i32 @test1
33 // CHECK2-LABEL: define{{.*}} i32 @test2
34 // CHECK2-LABEL: define{{.*}} void @test3
35 // CHECK2-LABEL: define available_externally i32 @test4
36 // CHECK2-LABEL: define available_externally i32 @test5
37 // CHECK2-LABEL: define{{.*}} i32 @test6
38 // CHECK2-LABEL: define{{.*}} void @test7
39 // CHECK2: define available_externally i{{..}} @strlcpy
40 // CHECK2-LABEL: define{{.*}} void @test9
41 // CHECK2-LABEL: define{{.*}} void @testA
42 // CHECK2-LABEL: define{{.*}} void @testB
43 // CHECK2-LABEL: define{{.*}} void @testC
44 // CHECK2-LABEL: define available_externally i32 @foo()
45 // CHECK2-LABEL: define available_externally void @gnu_ei_inline()
47 // RUN: echo "C++ tests:"
48 // RUN: %clang_cc1 -x c++ %s -triple i386-unknown-unknown -O1 -disable-llvm-passes -emit-llvm -o - -std=c++98 | FileCheck %s --check-prefix=CHECK3
49 // CHECK3-LABEL: define{{.*}} i32 @_Z3barv()
50 // CHECK3-LABEL: define linkonce_odr noundef i32 @_Z3foov()
51 // CHECK3-NOT: unreferenced
52 // CHECK3-LABEL: define available_externally void @_Z10gnu_inlinev()
53 // CHECK3-LABEL: define available_externally void @_Z13gnu_ei_inlinev()
54 // CHECK3-NOT: @_Z5testCv
55 // CHECK3-LABEL: define linkonce_odr noundef i32 @_Z2eiv()
57 // RUN: echo "MS C Mode tests:"
58 // RUN: %clang_cc1 %s -triple i386-pc-win32 -Wno-strict-prototypes -O1 -disable-llvm-passes -emit-llvm -o - -std=c99 | FileCheck %s --check-prefix=CHECK4
59 // CHECK4-NOT: define weak_odr void @_Exit(
60 // CHECK4-LABEL: define weak_odr dso_local i32 @ei()
61 // CHECK4-LABEL: define dso_local i32 @bar()
62 // CHECK4-NOT: unreferenced1
63 // CHECK4-LABEL: define weak_odr dso_local void @unreferenced2()
64 // CHECK4-LABEL: define dso_local void @gnu_inline()
65 // CHECK4-LABEL: define linkonce_odr dso_local i32 @foo()
66 // CHECK4-LABEL: define available_externally dso_local void @gnu_ei_inline()
68 __attribute__((noreturn)) void __cdecl _exit(int _Code);
69 __inline void __cdecl _Exit(int status) { _exit(status); }
71 extern __inline int ei() { return 123; }
73 __inline int foo() {
74 return ei();
77 int bar() { return foo(); }
80 __inline void unreferenced1() {}
81 extern __inline void unreferenced2() {}
83 __inline __attribute((__gnu_inline__)) void gnu_inline() {}
84 void (*P1)() = gnu_inline;
86 // PR3988
87 extern __inline __attribute__((gnu_inline)) void gnu_ei_inline() {}
88 void (*P)() = gnu_ei_inline;
90 int test1();
91 __inline int test1() { return 4; }
92 __inline int test2() { return 5; }
93 __inline int test2();
94 int test2();
96 void test_test1() { test1(); }
97 void test_test2() { test2(); }
99 // PR3989
100 extern __inline void test3() __attribute__((gnu_inline));
101 __inline void __attribute__((gnu_inline)) test3() {}
103 extern int test4(void);
104 extern __inline __attribute__ ((__gnu_inline__)) int test4(void)
106 return 0;
109 void test_test4() { test4(); }
111 extern __inline int test5(void) __attribute__ ((__gnu_inline__));
112 extern __inline int __attribute__ ((__gnu_inline__)) test5(void)
114 return 0;
117 void test_test5() { test5(); }
119 // PR10233
121 __inline int test6() { return 0; }
122 extern int test6();
125 // No PR#, but this once crashed clang in C99 mode due to buggy extern inline
126 // redeclaration detection.
127 void test7() { }
128 void test7();
130 // PR11062; the fact that the function is named strlcpy matters here.
131 inline __typeof(sizeof(int)) strlcpy(char *dest, const char *src, __typeof(sizeof(int)) size) { return 3; }
132 void test8() { strlcpy(0,0,0); }
134 // PR10657; the test crashed in C99 mode
135 extern inline void test9() { }
136 void test9();
138 inline void testA() {}
139 void testA();
141 void testB();
142 inline void testB() {}
143 extern void testB();
145 extern inline void testC() {}
146 inline void testC();