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