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