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