Clang Project

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