Skip to content

Commit 04abb73

Browse files
committed
[-Wunsafe-buffer-usage] Fix note message suggesting to use std::array
1 parent 9183a63 commit 04abb73

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12113,9 +12113,9 @@ def warn_unsafe_buffer_operation : Warning<
1211312113
def note_unsafe_buffer_operation : Note<
1211412114
"used%select{| in pointer arithmetic| in buffer access}0 here">;
1211512115
def note_unsafe_buffer_variable_fixit_group : Note<
12116-
"change type of %0 to '%select{std::span|std::array|std::span::iterator}1' to preserve bounds information%select{|, and change %2 to '%select{std::span|std::array|std::span::iterator}1' to propagate bounds information between them}3">;
12116+
"change type of %0 to '%select{std::span' to preserve bounds information|std::array' to harden it|std::span::iterator' to preserve bounds information}1%select{|, and change %2 to '%select{std::span|std::array|std::span::iterator}1' to propagate bounds information between them}3">;
1211712117
def note_unsafe_buffer_variable_fixit_together : Note<
12118-
"change type of %0 to '%select{std::span|std::array|std::span::iterator}1' to preserve bounds information"
12118+
"change type of %0 to '%select{std::span' to preserve bounds information|std::array' to harden it|std::span::iterator' to preserve bounds information}1"
1211912119
"%select{|, and change %2 to safe types to make function %4 bounds-safe}3">;
1212012120
def note_safe_buffer_usage_suggestions_disabled : Note<
1212112121
"pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions">;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77

88
void foo(unsigned idx) {
9-
int buffer[10]; // expected-warning{{'buffer' is an unsafe buffer that does not perform bounds}}
10-
// expected-note@-1{{change type of 'buffer' to 'std::array' to preserve bounds information}}
9+
int buffer[10]; // expected-warning{{'buffer' is an unsafe buffer that does not perform bounds checks}}
10+
// expected-note@-1{{change type of 'buffer' to 'std::array' to harden it}}
1111
buffer[idx] = 0; // expected-note{{used in buffer access here}}
1212
}
1313

14-
int global_buffer[10]; // expected-warning{{'global_buffer' is an unsafe buffer that does not perform bounds}}
14+
int global_buffer[10]; // expected-warning{{'global_buffer' is an unsafe buffer that does not perform bounds checks}}
1515
void foo2(unsigned idx) {
1616
global_buffer[idx] = 0; // expected-note{{used in buffer access here}}
1717
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void testArraySubscripts(int *p, int **pp) {
6161
);
6262

6363
int a[10]; // expected-warning{{'a' is an unsafe buffer that does not perform bounds checks}}
64-
// expected-note@-1{{change type of 'a' to 'std::array' to preserve bounds information}}
64+
// expected-note@-1{{change type of 'a' to 'std::array' to harden it}}
6565
int b[10][10]; // expected-warning{{'b' is an unsafe buffer that does not perform bounds checks}}
6666

6767
foo(a[1], 1[a], // expected-note2{{used in buffer access here}}
@@ -175,7 +175,7 @@ auto file_scope_lambda = [](int *ptr) {
175175
void testLambdaCapture() {
176176
int a[10]; // expected-warning{{'a' is an unsafe buffer that does not perform bounds checks}}
177177
int b[10]; // expected-warning{{'b' is an unsafe buffer that does not perform bounds checks}}
178-
// expected-note@-1{{change type of 'b' to 'std::array' to preserve bounds information}}
178+
// expected-note@-1{{change type of 'b' to 'std::array' to harden it}}
179179
int c[10];
180180

181181
auto Lam1 = [a]() {
@@ -193,9 +193,9 @@ void testLambdaCapture() {
193193

194194
void testLambdaImplicitCapture() {
195195
int a[10]; // expected-warning{{'a' is an unsafe buffer that does not perform bounds checks}}
196-
// expected-note@-1{{change type of 'a' to 'std::array' to preserve bounds information}}
196+
// expected-note@-1{{change type of 'a' to 'std::array' to harden it}}
197197
int b[10]; // expected-warning{{'b' is an unsafe buffer that does not perform bounds checks}}
198-
// expected-note@-1{{change type of 'b' to 'std::array' to preserve bounds information}}
198+
// expected-note@-1{{change type of 'b' to 'std::array' to harden it}}
199199

200200
auto Lam1 = [=]() {
201201
return a[1]; // expected-note{{used in buffer access here}}
@@ -348,7 +348,7 @@ template<typename T> void fArr(T t[]) {
348348
// expected-warning@-1{{'t' is an unsafe pointer used for buffer access}}
349349
foo(t[1]); // expected-note{{used in buffer access here}}
350350
T ar[8]; // expected-warning{{'ar' is an unsafe buffer that does not perform bounds checks}}
351-
// expected-note@-1{{change type of 'ar' to 'std::array' to preserve bounds information}}
351+
// expected-note@-1{{change type of 'ar' to 'std::array' to harden it}}
352352
foo(ar[5]); // expected-note{{used in buffer access here}}
353353
}
354354

0 commit comments

Comments
 (0)