Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 1 | // RUN: echo "GNU89 tests:" |
Douglas Gregor | 44eac33 | 2010-07-13 06:02:28 +0000 | [diff] [blame] | 2 | // RUN: %clang %s -O1 -emit-llvm -S -o %t -std=gnu89 |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 3 | // RUN: grep "define available_externally i32 @ei()" %t |
| 4 | // RUN: grep "define i32 @foo()" %t |
| 5 | // RUN: grep "define i32 @bar()" %t |
| 6 | // RUN: grep "define void @unreferenced1()" %t |
| 7 | // RUN: not grep unreferenced2 %t |
| 8 | // RUN: grep "define void @gnu_inline()" %t |
| 9 | // RUN: grep "define available_externally void @gnu_ei_inline()" %t |
| 10 | // RUN: grep "define i32 @test1" %t |
| 11 | // RUN: grep "define i32 @test2" %t |
| 12 | // RUN: grep "define void @test3()" %t |
| 13 | // RUN: grep "define available_externally i32 @test4" %t |
| 14 | // RUN: grep "define available_externally i32 @test5" %t |
Nick Lewycky | dce67a7 | 2011-07-18 05:26:13 +0000 | [diff] [blame] | 15 | // RUN: grep "define i32 @test6" %t |
Chris Lattner | d9d049a | 2009-04-14 06:27:57 +0000 | [diff] [blame] | 16 | |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 17 | // RUN: echo "\nC99 tests:" |
Douglas Gregor | 44eac33 | 2010-07-13 06:02:28 +0000 | [diff] [blame] | 18 | // RUN: %clang %s -O1 -emit-llvm -S -o %t -std=c99 |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 19 | // RUN: grep "define i32 @ei()" %t |
| 20 | // RUN: grep "define available_externally i32 @foo()" %t |
| 21 | // RUN: grep "define i32 @bar()" %t |
| 22 | // RUN: not grep unreferenced1 %t |
| 23 | // RUN: grep "define void @unreferenced2()" %t |
| 24 | // RUN: grep "define void @gnu_inline()" %t |
| 25 | // RUN: grep "define available_externally void @gnu_ei_inline()" %t |
| 26 | // RUN: grep "define i32 @test1" %t |
| 27 | // RUN: grep "define i32 @test2" %t |
| 28 | // RUN: grep "define void @test3" %t |
| 29 | // RUN: grep "define available_externally i32 @test4" %t |
| 30 | // RUN: grep "define available_externally i32 @test5" %t |
Nick Lewycky | dce67a7 | 2011-07-18 05:26:13 +0000 | [diff] [blame] | 31 | // RUN: grep "define i32 @test6" %t |
Chris Lattner | d9d049a | 2009-04-14 06:27:57 +0000 | [diff] [blame] | 32 | |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 33 | // RUN: echo "\nC++ tests:" |
Chad Rosier | 02a444d | 2011-05-02 20:39:21 +0000 | [diff] [blame] | 34 | // RUN: %clang -x c++ %s -O1 -emit-llvm -S -o %t -std=c++98 |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 35 | // RUN: grep "define linkonce_odr i32 @_Z2eiv()" %t |
| 36 | // RUN: grep "define linkonce_odr i32 @_Z3foov()" %t |
| 37 | // RUN: grep "define i32 @_Z3barv()" %t |
| 38 | // RUN: not grep unreferenced %t |
| 39 | // RUN: grep "define void @_Z10gnu_inlinev()" %t |
Chris Lattner | d55a71d | 2009-04-22 00:03:30 +0000 | [diff] [blame] | 40 | // RUN: grep "define available_externally void @_Z13gnu_ei_inlinev()" %t |
Chris Lattner | d9d049a | 2009-04-14 06:27:57 +0000 | [diff] [blame] | 41 | |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 42 | extern __inline int ei() { return 123; } |
Chris Lattner | d9d049a | 2009-04-14 06:27:57 +0000 | [diff] [blame] | 43 | |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 44 | __inline int foo() { |
Chris Lattner | d9d049a | 2009-04-14 06:27:57 +0000 | [diff] [blame] | 45 | return ei(); |
| 46 | } |
| 47 | |
| 48 | int bar() { return foo(); } |
| 49 | |
| 50 | |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 51 | __inline void unreferenced1() {} |
| 52 | extern __inline void unreferenced2() {} |
Chris Lattner | d9d049a | 2009-04-14 06:27:57 +0000 | [diff] [blame] | 53 | |
Chris Lattner | cf2a721 | 2009-04-20 19:12:28 +0000 | [diff] [blame] | 54 | __inline __attribute((__gnu_inline__)) void gnu_inline() {} |
Chris Lattner | d55a71d | 2009-04-22 00:03:30 +0000 | [diff] [blame] | 55 | |
| 56 | // PR3988 |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 57 | extern __inline __attribute__((gnu_inline)) void gnu_ei_inline() {} |
Chris Lattner | d55a71d | 2009-04-22 00:03:30 +0000 | [diff] [blame] | 58 | void (*P)() = gnu_ei_inline; |
| 59 | |
Douglas Gregor | b3efa98 | 2009-04-23 18:22:55 +0000 | [diff] [blame] | 60 | // <rdar://problem/6818429> |
| 61 | int test1(); |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 62 | __inline int test1() { return 4; } |
| 63 | __inline int test2() { return 5; } |
| 64 | __inline int test2(); |
Douglas Gregor | b3efa98 | 2009-04-23 18:22:55 +0000 | [diff] [blame] | 65 | int test2(); |
| 66 | |
| 67 | void test_test1() { test1(); } |
| 68 | void test_test2() { test2(); } |
| 69 | |
| 70 | // PR3989 |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 71 | extern __inline void test3() __attribute__((gnu_inline)); |
Douglas Gregor | 1fc09a9 | 2009-09-13 07:46:26 +0000 | [diff] [blame] | 72 | __inline void __attribute__((gnu_inline)) test3() {} |
Douglas Gregor | 9f9bf25 | 2009-04-28 06:37:30 +0000 | [diff] [blame] | 73 | |
| 74 | extern int test4(void); |
| 75 | extern __inline __attribute__ ((__gnu_inline__)) int test4(void) |
| 76 | { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 77 | return 0; |
Douglas Gregor | 9f9bf25 | 2009-04-28 06:37:30 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void test_test4() { test4(); } |
| 81 | |
Douglas Gregor | 1fc09a9 | 2009-09-13 07:46:26 +0000 | [diff] [blame] | 82 | extern __inline int test5(void) __attribute__ ((__gnu_inline__)); |
Douglas Gregor | 9f9bf25 | 2009-04-28 06:37:30 +0000 | [diff] [blame] | 83 | extern __inline int __attribute__ ((__gnu_inline__)) test5(void) |
| 84 | { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 85 | return 0; |
Douglas Gregor | 9f9bf25 | 2009-04-28 06:37:30 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void test_test5() { test5(); } |
Nick Lewycky | dce67a7 | 2011-07-18 05:26:13 +0000 | [diff] [blame] | 89 | |
| 90 | // PR10233 |
| 91 | |
| 92 | __inline int test6() { return 0; } |
| 93 | extern int test6(); |
Nick Lewycky | f57ef05 | 2011-07-18 07:11:55 +0000 | [diff] [blame^] | 94 | |
| 95 | |
| 96 | // No PR#, but this once crashed clang in C99 mode due to buggy extern inline |
| 97 | // redeclaration detection. |
| 98 | void test7() { } |
| 99 | void test7(); |