Skip to content

Commit 5540d7b

Browse files
committed
[-Wunsafe-buffer-usage] Enable fixits for const ptr array declarations
1 parent 04abb73 commit 5540d7b

File tree

3 files changed

+3
-29
lines changed

3 files changed

+3
-29
lines changed

clang/lib/Analysis/UnsafeBufferUsage.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,22 +2478,6 @@ static FixItList fixVarDeclWithArray(const VarDecl *D, const ASTContext &Ctx,
24782478
const QualType &ArrayEltT = CAT->getElementType();
24792479
assert(!ArrayEltT.isNull() && "Trying to fix a non-array type variable!");
24802480

2481-
// For most types the transformation is simple:
2482-
// T foo[10]; => std::array<T, 10> foo;
2483-
// Cv-specifiers are straigtforward:
2484-
// const T foo[10]; => std::array<const T, 10> foo;
2485-
// Pointers are straightforward:
2486-
// T * foo[10]; => std::array<T *, 10> foo;
2487-
//
2488-
// However, for const pointers the transformation is different:
2489-
// T * const foo[10]; => const std::array<T *, 10> foo;
2490-
if (ArrayEltT->isPointerType() && ArrayEltT.isConstQualified()) {
2491-
DEBUG_NOTE_DECL_FAIL(D, " : const size array of const pointers");
2492-
// FIXME: implement the support
2493-
// FIXME: bail if the const pointer is a typedef
2494-
return {};
2495-
}
2496-
24972481
const SourceLocation IdentifierLoc = getVarDeclIdentifierLoc(D);
24982482

24992483
// Get the spelling of the element type as written in the source file

clang/test/SemaCXX/warn-unsafe-buffer-usage-debug.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ void foo() {
3232
// debug-note{{safe buffers debug: gadget 'ULCArraySubscript' refused to produce a fix}}
3333
}
3434

35-
void failed_decl(const int* out, unsigned idx) {
36-
const int* const a[10] = {nullptr}; // expected-warning{{'a' is an unsafe buffer that does not perform bounds checks}} \
37-
// debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : const size array of const pointers}}
38-
39-
out = a[idx]; // expected-note{{used in buffer access here}}
40-
}
41-
4235
void failed_multiple_decl() {
4336
int *a = new int[4], b; // expected-warning{{'a' is an unsafe pointer used for buffer access}} \
4437
// debug-note{{safe buffers debug: failed to produce fixit for declaration 'a' : multiple VarDecls}}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,22 @@ void local_array_ptr_to_const(unsigned idx, const int*& a) {
7373

7474
void local_array_const_ptr(unsigned idx, int*& a) {
7575
int * const buffer[10] = {a};
76-
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:.*-[[@LINE-1]]:.*}
77-
// FIXME: implement support
76+
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:25}:"std::array<int * const, 10> buffer"
7877

7978
a = buffer[idx];
8079
}
8180

8281
void local_array_const_ptr_via_typedef(unsigned idx, int*& a) {
8382
typedef int * const my_const_ptr;
8483
my_const_ptr buffer[10] = {a};
85-
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:.*-[[@LINE-1]]:.*}
86-
// FIXME: implement support
84+
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:26}:"std::array<my_const_ptr, 10> buffer"
8785

8886
a = buffer[idx];
8987
}
9088

9189
void local_array_const_ptr_to_const(unsigned idx, const int*& a) {
9290
const int * const buffer[10] = {a};
93-
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:.*-[[@LINE-1]]:.*}
94-
// FIXME: implement support
91+
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:31}:"std::array<const int * const, 10> buffer"
9592

9693
a = buffer[idx];
9794

0 commit comments

Comments
 (0)