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