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