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() 24 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() 46 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() 56 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() 67 68 __attribute__((noreturn)) void __cdecl _exit(int _Code); 69 __inline void __cdecl _Exit(int status) { _exit(status); } 70 71 extern __inline int ei() { return 123; } 72 73 __inline int foo() { 74 return ei(); 75 } 76 77 int bar() { return foo(); } 78 79 80 __inline void unreferenced1() {} 81 extern __inline void unreferenced2() {} 82 83 __inline __attribute((__gnu_inline__)) void gnu_inline() {} 84 void (*P1)() = gnu_inline; 85 86 // PR3988 87 extern __inline __attribute__((gnu_inline)) void gnu_ei_inline() {} 88 void (*P)() = gnu_ei_inline; 89 90 // <rdar://problem/6818429> 91 int test1(); 92 __inline int test1() { return 4; } 93 __inline int test2() { return 5; } 94 __inline int test2(); 95 int test2(); 96 97 void test_test1() { test1(); } 98 void test_test2() { test2(); } 99 100 // PR3989 101 extern __inline void test3() __attribute__((gnu_inline)); 102 __inline void __attribute__((gnu_inline)) test3() {} 103 104 extern int test4(void); 105 extern __inline __attribute__ ((__gnu_inline__)) int test4(void) 106 { 107 return 0; 108 } 109 110 void test_test4() { test4(); } 111 112 extern __inline int test5(void) __attribute__ ((__gnu_inline__)); 113 extern __inline int __attribute__ ((__gnu_inline__)) test5(void) 114 { 115 return 0; 116 } 117 118 void test_test5() { test5(); } 119 120 // PR10233 121 122 __inline int test6() { return 0; } 123 extern int test6(); 124 125 126 // No PR#, but this once crashed clang in C99 mode due to buggy extern inline 127 // redeclaration detection. 128 void test7() { } 129 void test7(); 130 131 // PR11062; the fact that the function is named strlcpy matters here. 132 inline __typeof(sizeof(int)) strlcpy(char *dest, const char *src, __typeof(sizeof(int)) size) { return 3; } 133 void test8() { strlcpy(0,0,0); } 134 135 // PR10657; the test crashed in C99 mode 136 extern inline void test9() { } 137 void test9(); 138 139 inline void testA() {} 140 void testA(); 141 142 void testB(); 143 inline void testB() {} 144 extern void testB(); 145 146 extern inline void testC() {} 147 inline void testC(); 148