147 lines · c
1// REQUIRES: x86-registered-target2//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=CHECK15// CHECK1-LABEL: define{{.*}} i32 @foo()6// CHECK1-LABEL: define{{.*}} i32 @bar()7// CHECK1-LABEL: define{{.*}} void @unreferenced1()8// CHECK1-NOT: unreferenced29// CHECK1-LABEL: define{{.*}} void @gnu_inline()10// CHECK1-LABEL: define{{.*}} i32 @test111// CHECK1-LABEL: define{{.*}} i32 @test212// CHECK1-LABEL: define{{.*}} void @test3()13// CHECK1-LABEL: define available_externally i32 @test414// CHECK1-LABEL: define available_externally i32 @test515// CHECK1-LABEL: define{{.*}} i32 @test616// CHECK1-LABEL: define{{.*}} void @test717// CHECK1: define{{.*}} i{{..}} @strlcpy18// CHECK1-NOT: test919// CHECK1-LABEL: define{{.*}} void @testA20// CHECK1-LABEL: define{{.*}} void @testB21// CHECK1-LABEL: define{{.*}} void @testC22// 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=CHECK227// CHECK2-LABEL: define{{.*}} i32 @ei()28// CHECK2-LABEL: define{{.*}} i32 @bar()29// CHECK2-NOT: unreferenced130// CHECK2-LABEL: define{{.*}} void @unreferenced2()31// CHECK2-LABEL: define{{.*}} void @gnu_inline()32// CHECK2-LABEL: define{{.*}} i32 @test133// CHECK2-LABEL: define{{.*}} i32 @test234// CHECK2-LABEL: define{{.*}} void @test335// CHECK2-LABEL: define available_externally i32 @test436// CHECK2-LABEL: define available_externally i32 @test537// CHECK2-LABEL: define{{.*}} i32 @test638// CHECK2-LABEL: define{{.*}} void @test739// CHECK2: define available_externally i{{..}} @strlcpy40// CHECK2-LABEL: define{{.*}} void @test941// CHECK2-LABEL: define{{.*}} void @testA42// CHECK2-LABEL: define{{.*}} void @testB43// CHECK2-LABEL: define{{.*}} void @testC44// 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=CHECK349// CHECK3-LABEL: define{{.*}} i32 @_Z3barv()50// CHECK3-LABEL: define linkonce_odr noundef i32 @_Z3foov()51// CHECK3-NOT: unreferenced52// CHECK3-LABEL: define available_externally void @_Z10gnu_inlinev()53// CHECK3-LABEL: define available_externally void @_Z13gnu_ei_inlinev()54// CHECK3-NOT: @_Z5testCv55// 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=CHECK459// 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: unreferenced163// 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 71extern __inline int ei() { return 123; }72 73__inline int foo() {74 return ei();75}76 77int bar() { return foo(); }78 79 80__inline void unreferenced1() {}81extern __inline void unreferenced2() {}82 83__inline __attribute((__gnu_inline__)) void gnu_inline() {}84void (*P1)() = gnu_inline;85 86// PR398887extern __inline __attribute__((gnu_inline)) void gnu_ei_inline() {}88void (*P)() = gnu_ei_inline;89 90int test1();91__inline int test1() { return 4; }92__inline int test2() { return 5; }93__inline int test2();94int test2();95 96void test_test1() { test1(); }97void test_test2() { test2(); }98 99// PR3989100extern __inline void test3() __attribute__((gnu_inline));101__inline void __attribute__((gnu_inline)) test3() {}102 103extern int test4(void);104extern __inline __attribute__ ((__gnu_inline__)) int test4(void)105{106 return 0;107}108 109void test_test4() { test4(); }110 111extern __inline int test5(void) __attribute__ ((__gnu_inline__));112extern __inline int __attribute__ ((__gnu_inline__)) test5(void)113{114 return 0;115}116 117void test_test5() { test5(); }118 119// PR10233120 121__inline int test6() { return 0; }122extern int test6();123 124 125// No PR#, but this once crashed clang in C99 mode due to buggy extern inline126// redeclaration detection.127void test7() { }128void test7();129 130// PR11062; the fact that the function is named strlcpy matters here.131inline __typeof(sizeof(int)) strlcpy(char *dest, const char *src, __typeof(sizeof(int)) size) { return 3; }132void test8() { strlcpy(0,0,0); }133 134// PR10657; the test crashed in C99 mode135extern inline void test9() { }136void test9();137 138inline void testA() {}139void testA();140 141void testB();142inline void testB() {}143extern void testB();144 145extern inline void testC() {}146inline void testC();147