Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 1 | // RUN: echo "GNU89 tests:" |
David Blaikie | 3de93c8 | 2013-01-05 18:22:42 +0000 | [diff] [blame^] | 2 | // RUN: %clang %s -target i386-unknown-unknown -O1 -emit-llvm -S -o - -std=gnu89 | FileCheck %s --check-prefix=CHECK1 |
| 3 | // CHECK1: define i32 @foo() |
| 4 | // CHECK1: define i32 @bar() |
| 5 | // CHECK1: define void @unreferenced1() |
| 6 | // CHECK1-NOT: unreferenced2 |
| 7 | // CHECK1: define void @gnu_inline() |
| 8 | // CHECK1: define i32 @test1 |
| 9 | // CHECK1: define i32 @test2 |
| 10 | // CHECK1: define void @test3() |
| 11 | // CHECK1: define available_externally i32 @test4 |
| 12 | // CHECK1: define available_externally i32 @test5 |
| 13 | // CHECK1: define i32 @test6 |
| 14 | // CHECK1: define void @test7 |
| 15 | // CHECK1: define i{{..}} @strlcpy |
| 16 | // CHECK1-NOT: test9 |
| 17 | // CHECK1: define void @testA |
| 18 | // CHECK1: define void @testB |
| 19 | // CHECK1: define void @testC |
| 20 | // CHECK1: define available_externally void @gnu_ei_inline() |
| 21 | // CHECK1: define available_externally i32 @ei() |
Chris Lattner | d9d049a | 2009-04-14 06:27:57 +0000 | [diff] [blame] | 22 | |
Eli Friedman | a3b9fa2 | 2012-02-07 03:50:18 +0000 | [diff] [blame] | 23 | // RUN: echo "C99 tests:" |
David Blaikie | 3de93c8 | 2013-01-05 18:22:42 +0000 | [diff] [blame^] | 24 | // RUN: %clang %s -target i386-unknown-unknown -O1 -emit-llvm -S -o - -std=gnu99 | FileCheck %s --check-prefix=CHECK2 |
| 25 | // CHECK2: define i32 @ei() |
| 26 | // CHECK2: define i32 @bar() |
| 27 | // CHECK2-NOT: unreferenced1 |
| 28 | // CHECK2: define void @unreferenced2() |
| 29 | // CHECK2: define void @gnu_inline() |
| 30 | // CHECK2: define i32 @test1 |
| 31 | // CHECK2: define i32 @test2 |
| 32 | // CHECK2: define void @test3 |
| 33 | // CHECK2: define available_externally i32 @test4 |
| 34 | // CHECK2: define available_externally i32 @test5 |
| 35 | // CHECK2: define i32 @test6 |
| 36 | // CHECK2: define void @test7 |
| 37 | // CHECK2: define available_externally i{{..}} @strlcpy |
| 38 | // CHECK2: define void @test9 |
| 39 | // CHECK2: define void @testA |
| 40 | // CHECK2: define void @testB |
| 41 | // CHECK2: define void @testC |
| 42 | // CHECK2: define available_externally void @gnu_ei_inline() |
| 43 | // CHECK2: define available_externally i32 @foo() |
Chris Lattner | d9d049a | 2009-04-14 06:27:57 +0000 | [diff] [blame] | 44 | |
Eli Friedman | a3b9fa2 | 2012-02-07 03:50:18 +0000 | [diff] [blame] | 45 | // RUN: echo "C++ tests:" |
David Blaikie | 3de93c8 | 2013-01-05 18:22:42 +0000 | [diff] [blame^] | 46 | // RUN: %clang -x c++ %s -target i386-unknown-unknown -O1 -emit-llvm -S -o - -std=c++98 | FileCheck %s --check-prefix=CHECK3 |
| 47 | // CHECK3: define i32 @_Z3barv() |
| 48 | // CHECK3: define linkonce_odr i32 @_Z3foov() |
| 49 | // CHECK3-NOT: unreferenced |
| 50 | // CHECK3: define void @_Z10gnu_inlinev() |
| 51 | // CHECK3: define available_externally void @_Z13gnu_ei_inlinev() |
| 52 | // CHECK3: define linkonce_odr i32 @_Z2eiv() |
Chris Lattner | d9d049a | 2009-04-14 06:27:57 +0000 | [diff] [blame] | 53 | |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 54 | extern __inline int ei() { return 123; } |
Chris Lattner | d9d049a | 2009-04-14 06:27:57 +0000 | [diff] [blame] | 55 | |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 56 | __inline int foo() { |
Chris Lattner | d9d049a | 2009-04-14 06:27:57 +0000 | [diff] [blame] | 57 | return ei(); |
| 58 | } |
| 59 | |
| 60 | int bar() { return foo(); } |
| 61 | |
| 62 | |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 63 | __inline void unreferenced1() {} |
| 64 | extern __inline void unreferenced2() {} |
Chris Lattner | d9d049a | 2009-04-14 06:27:57 +0000 | [diff] [blame] | 65 | |
Chris Lattner | cf2a721 | 2009-04-20 19:12:28 +0000 | [diff] [blame] | 66 | __inline __attribute((__gnu_inline__)) void gnu_inline() {} |
Chris Lattner | d55a71d | 2009-04-22 00:03:30 +0000 | [diff] [blame] | 67 | |
| 68 | // PR3988 |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 69 | extern __inline __attribute__((gnu_inline)) void gnu_ei_inline() {} |
Chris Lattner | d55a71d | 2009-04-22 00:03:30 +0000 | [diff] [blame] | 70 | void (*P)() = gnu_ei_inline; |
| 71 | |
Douglas Gregor | b3efa98 | 2009-04-23 18:22:55 +0000 | [diff] [blame] | 72 | // <rdar://problem/6818429> |
| 73 | int test1(); |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 74 | __inline int test1() { return 4; } |
| 75 | __inline int test2() { return 5; } |
| 76 | __inline int test2(); |
Douglas Gregor | b3efa98 | 2009-04-23 18:22:55 +0000 | [diff] [blame] | 77 | int test2(); |
| 78 | |
| 79 | void test_test1() { test1(); } |
| 80 | void test_test2() { test2(); } |
| 81 | |
| 82 | // PR3989 |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 83 | extern __inline void test3() __attribute__((gnu_inline)); |
Douglas Gregor | 1fc09a9 | 2009-09-13 07:46:26 +0000 | [diff] [blame] | 84 | __inline void __attribute__((gnu_inline)) test3() {} |
Douglas Gregor | 9f9bf25 | 2009-04-28 06:37:30 +0000 | [diff] [blame] | 85 | |
| 86 | extern int test4(void); |
| 87 | extern __inline __attribute__ ((__gnu_inline__)) int test4(void) |
| 88 | { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 89 | return 0; |
Douglas Gregor | 9f9bf25 | 2009-04-28 06:37:30 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void test_test4() { test4(); } |
| 93 | |
Douglas Gregor | 1fc09a9 | 2009-09-13 07:46:26 +0000 | [diff] [blame] | 94 | extern __inline int test5(void) __attribute__ ((__gnu_inline__)); |
Douglas Gregor | 9f9bf25 | 2009-04-28 06:37:30 +0000 | [diff] [blame] | 95 | extern __inline int __attribute__ ((__gnu_inline__)) test5(void) |
| 96 | { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 97 | return 0; |
Douglas Gregor | 9f9bf25 | 2009-04-28 06:37:30 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | void test_test5() { test5(); } |
Nick Lewycky | dce67a7 | 2011-07-18 05:26:13 +0000 | [diff] [blame] | 101 | |
| 102 | // PR10233 |
| 103 | |
| 104 | __inline int test6() { return 0; } |
| 105 | extern int test6(); |
Nick Lewycky | f57ef05 | 2011-07-18 07:11:55 +0000 | [diff] [blame] | 106 | |
Anton Yartsev | 3a5aca8 | 2012-02-02 06:06:34 +0000 | [diff] [blame] | 107 | |
| 108 | // No PR#, but this once crashed clang in C99 mode due to buggy extern inline |
| 109 | // redeclaration detection. |
| 110 | void test7() { } |
Nick Lewycky | f57ef05 | 2011-07-18 07:11:55 +0000 | [diff] [blame] | 111 | void test7(); |
Eli Friedman | 8a1d6a5 | 2011-10-11 22:09:24 +0000 | [diff] [blame] | 112 | |
| 113 | // PR11062; the fact that the function is named strlcpy matters here. |
| 114 | inline __typeof(sizeof(int)) strlcpy(char *dest, const char *src, __typeof(sizeof(int)) size) { return 3; } |
| 115 | void test8() { strlcpy(0,0,0); } |
Eli Friedman | a3b9fa2 | 2012-02-07 03:50:18 +0000 | [diff] [blame] | 116 | |
| 117 | // PR10657; the test crashed in C99 mode |
| 118 | extern inline void test9() { } |
| 119 | void test9(); |
| 120 | |
| 121 | inline void testA() {} |
| 122 | void testA(); |
| 123 | |
| 124 | void testB(); |
| 125 | inline void testB() {} |
| 126 | extern void testB(); |
| 127 | |
| 128 | extern inline void testC() {} |
| 129 | inline void testC(); |