Skip to content

Commit 849f643

Browse files
committed
[-Wnsafe-buffer-usage][NFC] Fix and refactor tests
1 parent d19a2c3 commit 849f643

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-array.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
typedef int * Int_ptr_t;
55
typedef int Int_t;
66

7-
void local_array(unsigned idx) {
7+
void simple(unsigned idx) {
88
int buffer[10];
99
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:17}:"std::array<int, 10> buffer"
1010
buffer[idx] = 0;
@@ -22,15 +22,19 @@ void comments_in_declaration(unsigned idx) {
2222
buffer_w[idx] = 0;
2323
}
2424

25-
void unsupported_multi_decl1(unsigned idx) {
25+
void multi_decl1(unsigned idx) {
2626
int a, buffer[10];
27-
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
27+
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
28+
// FIXME: implement support
29+
2830
buffer[idx] = 0;
2931
}
3032

31-
void unsupported_multi_decl2(unsigned idx) {
33+
void multi_decl2(unsigned idx) {
3234
int buffer[10], b;
3335
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]
36+
// FIXME: implement support
37+
3438
buffer[idx] = 0;
3539
}
3640

@@ -42,40 +46,44 @@ void local_array_ptr_to_const(unsigned idx, const int*& a) {
4246

4347
void local_array_const_ptr(unsigned idx, int*& a) {
4448
int * const buffer[10] = {a};
45-
// FIXME: implement support
4649
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:.*-[[@LINE-1]]:.*}
50+
// FIXME: implement support
51+
4752
a = buffer[idx];
4853

4954
}
5055

5156
void local_array_const_ptr_to_const(unsigned idx, const int*& a) {
5257
const int * const buffer[10] = {a};
53-
// FIXME: implement support
5458
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:.*-[[@LINE-1]]:.*}
59+
// FIXME: implement support
60+
5561
a = buffer[idx];
5662

5763
}
5864

5965
template<typename T>
60-
void local_array_in_template(unsigned idx) {
66+
void unsupported_local_array_in_template(unsigned idx) {
6167
T buffer[10];
6268
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:.*-[[@LINE-1]]:.*}
6369
buffer[idx] = 0;
6470
}
6571
// Instantiate the template function to force its analysis.
66-
template void local_array_in_template<int>(unsigned); // FIXME: expected note {{in instantiation of}}
72+
template void unsupported_local_array_in_template<int>(unsigned);
6773

68-
typedef unsigned int uint;
74+
typedef unsigned int my_uint;
6975
void typedef_as_elem_type(unsigned idx) {
70-
uint buffer[10];
71-
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:18}:"std::array<uint, 10> buffer"
76+
my_uint buffer[10];
77+
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:21}:"std::array<my_uint, 10> buffer"
7278
buffer[idx] = 0;
7379
}
7480

7581
void macro_as_elem_type(unsigned idx) {
7682
#define MY_INT int
7783
MY_INT buffer[10];
84+
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:.*-[[@LINE-1]]:.*}
7885
// FIXME: implement support
86+
7987
buffer[idx] = 0;
8088
#undef MY_INT
8189
}
@@ -119,6 +127,6 @@ void subscript_signed(int signed_idx) {
119127

120128
// For constant-size arrays any negative index will lead to buffer underflow.
121129
// std::array::operator[] has unsigned parameter so the value will be casted to unsigned.
122-
// This will very likely be buffer overflow but hardened std::array catch these at runtime.
130+
// This will very likely be buffer overflow but hardened std::array catches these at runtime.
123131
buffer[signed_idx] = 0;
124132
}

0 commit comments

Comments
 (0)