|
| 1 | +// RUN: 3c -addcr -alltypes %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s |
| 2 | +// RUN: 3c -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s |
| 3 | +// RUN: 3c -addcr -alltypes %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null - |
| 4 | +// RUN: 3c -alltypes -output-postfix=checked %s |
| 5 | +// RUN: 3c -alltypes %S/functionDeclEnd.checked.c | count 0 |
| 6 | +// RUN: rm %S/functionDeclEnd.checked.c |
| 7 | + |
| 8 | + |
| 9 | +// Tests for issue 392. When rewriting function prototypes sometimes code |
| 10 | +// falling between the start of the definition and the end of the prototype |
| 11 | +// could be deleted. |
| 12 | +// NOTE: Tests in this file assume that code in the branch of the preprocessor |
| 13 | +// directive that is not taken will not be rewritten. It might be desirable to |
| 14 | +// eventually rewrite in both branches. See issue 374. |
| 15 | + |
| 16 | +#define FOO |
| 17 | + |
| 18 | +#ifdef FOO |
| 19 | +void test0(int *a) |
| 20 | +// CHECK: void test0(_Ptr<int> a) |
| 21 | +#else |
| 22 | +void test0(int *a) |
| 23 | +#endif |
| 24 | +// CHECK: #else |
| 25 | +// CHECK: void test0(int *a) |
| 26 | +// CHECK: #endif |
| 27 | +{ |
| 28 | +// CHECK: _Checked { |
| 29 | + return; |
| 30 | +} |
| 31 | + |
| 32 | +#ifdef FOO |
| 33 | +int *test1() |
| 34 | +// CHECK: _Ptr<int> test1(void) |
| 35 | +#else |
| 36 | +int *test1() |
| 37 | +#endif |
| 38 | +// CHECK: #else |
| 39 | +// CHECK: int *test1() |
| 40 | +// CHECK: #endif |
| 41 | +{ |
| 42 | +// CHECK: _Checked { |
| 43 | + return 0; |
| 44 | +} |
| 45 | + |
| 46 | +#ifdef FOO |
| 47 | +int *test2() |
| 48 | +// CHECK: int *test2(void) : itype(_Ptr<int>) |
| 49 | +#else |
| 50 | +int *test2() |
| 51 | +#endif |
| 52 | +// CHECK: #else |
| 53 | +// CHECK: int *test2() |
| 54 | +// CHECK: #endif |
| 55 | +{ |
| 56 | +// CHECK: { |
| 57 | + int *a = 1; |
| 58 | + return a; |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +// These test for rewriting with existing itype and bounds expression are |
| 63 | +// particularly important because they break the simplest fix where |
| 64 | +// getRParenLoc is always used. |
| 65 | + |
| 66 | +#ifdef FOO |
| 67 | +int *test3(int *a, int l) : itype(_Array_ptr<int>) count(l) |
| 68 | +// CHECK: int *test3(_Ptr<int> a, int l) : itype(_Array_ptr<int>) count(l) |
| 69 | +#else |
| 70 | +int *test3(int *a, int l) : itype(_Array_ptr<int>) count(l) |
| 71 | +#endif |
| 72 | +// CHECK: #else |
| 73 | +// CHECK: int *test3(int *a, int l) : itype(_Array_ptr<int>) count(l) |
| 74 | +// CHECK: #endif |
| 75 | +{ |
| 76 | +// CHECK: { |
| 77 | + int *b = 1; |
| 78 | + return b; |
| 79 | +} |
| 80 | + |
| 81 | +#ifdef FOO |
| 82 | +int *test4(int *a) : itype(_Ptr<int>) |
| 83 | +// CHECK: int *test4(_Ptr<int> a) : itype(_Ptr<int>) |
| 84 | +#else |
| 85 | +int *test4(int *a) : itype(_Ptr<int>) |
| 86 | +#endif |
| 87 | +// CHECK: #else |
| 88 | +// CHECK: int *test4(int *a) : itype(_Ptr<int>) |
| 89 | +// CHECK: #endif |
| 90 | +{ |
| 91 | +// CHECK: { |
| 92 | + int *b = 1; |
| 93 | + return b; |
| 94 | +} |
| 95 | + |
| 96 | +#ifdef FOO |
| 97 | +_Array_ptr<int> test5(int *a, int l) : count(l) |
| 98 | +// CHECK: _Array_ptr<int> test5(_Ptr<int> a, int l) : count(l) |
| 99 | +#else |
| 100 | +_Array_ptr<int> test5(int *a, int l) : count(l) |
| 101 | +#endif |
| 102 | +// CHECK: #else |
| 103 | +// CHECK: _Array_ptr<int> test5(int *a, int l) : count(l) |
| 104 | +// CHECK: #endif |
| 105 | +{ |
| 106 | +// CHECK: _Checked { |
| 107 | + return 0; |
| 108 | +} |
| 109 | + |
| 110 | +void test6(int *a) |
| 111 | +// A comment ( with parentheses ) that shouldn't be deleted |
| 112 | +// CHECK: void test6(_Ptr<int> a) |
| 113 | +// CHECK: // A comment ( with parentheses ) that shouldn't be deleted |
| 114 | +{ |
| 115 | + *a = 1; |
| 116 | +} |
| 117 | + |
| 118 | +#ifdef FOO |
| 119 | +int *test7(int *a) : count(10) |
| 120 | +//CHECK_NOALL: int *test7(int *a : itype(_Ptr<int>)) : count(10) |
| 121 | +//CHECK_ALL: int *test7(_Array_ptr<int> a) : count(10) |
| 122 | +#else |
| 123 | +int *test7(int *a) : count(10) |
| 124 | +#endif |
| 125 | +; |
| 126 | +//CHECK: #else |
| 127 | +//CHECK: int *test7(int *a) : count(10) |
| 128 | +//CHECK: #endif |
| 129 | +//CHECK: ; |
| 130 | + |
| 131 | +int *test7(int *a) : count(10) { |
| 132 | +//CHECK_ALL: int *test7(_Array_ptr<int> a) : count(10) _Checked { |
| 133 | +//CHECK_NOALL: int *test7(int *a : itype(_Ptr<int>)) : count(10) { |
| 134 | + return a; |
| 135 | +} |
| 136 | + |
| 137 | +// This test cast checks that the itype is overwritten even when it appears |
| 138 | +// after the count. Unfortunately, the count and itype are reversed on |
| 139 | +// rewriting. This isn't great since it's an unnecessary change to the code, |
| 140 | +// but it is still valid. |
| 141 | +#ifdef FOO |
| 142 | +int *test8(int *a, int l) : count(l) itype(_Array_ptr<int>) |
| 143 | +// CHECK: int *test8(_Ptr<int> a, int l) : itype(_Array_ptr<int>) count(l) |
| 144 | +#else |
| 145 | +int *test8(int *a, int l) : count(l) itype(_Array_ptr<int>) |
| 146 | +#endif |
| 147 | +// CHECK: #else |
| 148 | +// CHECK: int *test8(int *a, int l) : count(l) itype(_Array_ptr<int>) |
| 149 | +// CHECK: #endif |
| 150 | +{ |
| 151 | +// CHECK: { |
| 152 | + int *b = 1; |
| 153 | + return b; |
| 154 | +} |
0 commit comments