Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -11782,11 +11782,18 @@ "does not perform bounds checks}1">, InGroup, DefaultIgnore; def warn_unsafe_buffer_operation : Warning< - "%select{unsafe pointer operation|unsafe pointer arithmetic|" - "unsafe buffer access|function introduces unsafe buffer manipulation}0">, - InGroup, DefaultIgnore; + "%select{" + "unsafe operation on raw pointer in expression|" + "unsafe arithmetic on raw pointer|" + "unsafe buffer access through raw pointer|" + "function call introduces unsafe buffer manipulation" + "}0">, InGroup, DefaultIgnore; def note_unsafe_buffer_operation : Note< - "used%select{| in pointer arithmetic| in buffer access}0 here">; + "used %select{" + "|" + "in pointer arithmetic|" + "in buffer access" + "}0 here">; def note_unsafe_buffer_variable_fixit : Note< "change type of '%0' to '%select{std::span|std::array|std::span::iterator}1' to preserve bounds information">; def note_safe_buffer_usage_suggestions_disabled : Note< Index: clang/test/SemaCXX/unsafe-buffer-usage-diag-type.cpp =================================================================== --- clang/test/SemaCXX/unsafe-buffer-usage-diag-type.cpp +++ clang/test/SemaCXX/unsafe-buffer-usage-diag-type.cpp @@ -48,8 +48,8 @@ void testRefersPtrStructFieldDecl(int i) { Struct1 s1; - s1.ptr + i; // expected-warning{{unsafe pointer arithmetic}} - s1.ptr[i]; // expected-warning{{unsafe buffer access}} + s1.ptr + i; // expected-warning{{unsafe arithmetic on raw pointer}} + s1.ptr[i]; // expected-warning{{unsafe buffer access through raw pointer}} } struct Struct2 { @@ -58,7 +58,7 @@ void testRefersArrayStructFieldDecl(int i) { Struct2 s2; - s2.array[i/2]; // expected-warning{{unsafe buffer access}} + s2.array[i/2]; // expected-warning{{unsafe buffer access through raw pointer}} } } @@ -67,8 +67,8 @@ int * ptr; // FIXME: per-declaration warning aggregated at the struct definition void testRefersPtrStructFieldDecl(int i) { - ptr + i; // expected-warning{{unsafe pointer arithmetic}} - ptr[i]; // expected-warning{{unsafe buffer access}} + ptr + i; // expected-warning{{unsafe arithmetic on raw pointer}} + ptr[i]; // expected-warning{{unsafe buffer access through raw pointer}} } }; @@ -77,7 +77,7 @@ void testRefersArrayStructFieldDecl(int i) { Struct2 s2; - s2.array[i/2]; // expected-warning{{unsafe buffer access}} + s2.array[i/2]; // expected-warning{{unsafe buffer access through raw pointer}} } }; } @@ -104,6 +104,6 @@ int * return_ptr(); void testNoDeclRef(int i) { - return_ptr() + i; // expected-warning{{unsafe pointer arithmetic}} - return_ptr()[i]; // expected-warning{{unsafe buffer access}} + return_ptr() + i; // expected-warning{{unsafe arithmetic on raw pointer}} + return_ptr()[i]; // expected-warning{{unsafe buffer access through raw pointer}} } Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-function-attr.cpp =================================================================== --- clang/test/SemaCXX/warn-unsafe-buffer-usage-function-attr.cpp +++ clang/test/SemaCXX/warn-unsafe-buffer-usage-function-attr.cpp @@ -19,11 +19,11 @@ void deprecatedFunction4(int z); void caller(int z, int* x, int size, char c[]) { - deprecatedFunction3(); // expected-warning{{function introduces unsafe buffer manipulation}} - deprecatedFunction4(z); // expected-warning{{function introduces unsafe buffer manipulation}} + deprecatedFunction3(); // expected-warning{{function call introduces unsafe buffer manipulation}} + deprecatedFunction4(z); // expected-warning{{function call introduces unsafe buffer manipulation}} someFunction(); - overloading(x); // expected-warning{{function introduces unsafe buffer manipulation}} + overloading(x); // expected-warning{{function call introduces unsafe buffer manipulation}} overloading(x, size); overloading(c); } @@ -47,12 +47,12 @@ void foo(int *t) {} void caller1(int *p, int *q) { - testVariadics(p, q); // expected-warning{{function introduces unsafe buffer manipulation}} - adder(p, q); // expected-warning{{function introduces unsafe buffer manipulation}} + testVariadics(p, q); // expected-warning{{function call introduces unsafe buffer manipulation}} + adder(p, q); // expected-warning{{function call introduces unsafe buffer manipulation}} int x; foo(x); - foo(&x); // expected-warning{{function introduces unsafe buffer manipulation}} + foo(&x); // expected-warning{{function call introduces unsafe buffer manipulation}} } // Test virtual functions @@ -75,13 +75,13 @@ void testInheritance() { DerivedClass DC; DC.func(); - DC.func1(); // expected-warning{{function introduces unsafe buffer manipulation}} + DC.func1(); // expected-warning{{function call introduces unsafe buffer manipulation}} BaseClass *BC; - BC->func(); // expected-warning{{function introduces unsafe buffer manipulation}} + BC->func(); // expected-warning{{function call introduces unsafe buffer manipulation}} BC->func1(); BC = &DC; - BC->func(); // expected-warning{{function introduces unsafe buffer manipulation}} + BC->func(); // expected-warning{{function call introduces unsafe buffer manipulation}} BC->func1(); } Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-suggestions-flag.cpp =================================================================== --- clang/test/SemaCXX/warn-unsafe-buffer-usage-suggestions-flag.cpp +++ clang/test/SemaCXX/warn-unsafe-buffer-usage-suggestions-flag.cpp @@ -48,19 +48,18 @@ void foo(int *x) { // \ // ON-warning{{'x' is an unsafe pointer used for buffer access}} - // FIXME: Better "OFF" warning? x[5] = 10; // \ // ON-note {{used in buffer access here}} \ - // OFF-warning{{unsafe buffer access}} \ + // OFF-warning{{unsafe buffer access through raw pointer}} \ // OFF-note {{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}} x += 5; // \ // ON-note {{used in pointer arithmetic here}} \ - // OFF-warning{{unsafe pointer arithmetic}} \ + // OFF-warning{{unsafe arithmetic on raw pointer}} \ // OFF-note {{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}} bar(x); // \ - // ON-warning{{function introduces unsafe buffer manipulation}} \ - // OFF-warning{{function introduces unsafe buffer manipulation}} \ + // ON-warning {{function call introduces unsafe buffer manipulation}} \ + // OFF-warning{{function call introduces unsafe buffer manipulation}} \ // OFF-note {{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}} } Index: clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp =================================================================== --- clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp +++ clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp @@ -41,34 +41,34 @@ // expected-warning@-2{{'pp' is an unsafe pointer used for buffer access}} foo(p[1], // expected-note{{used in buffer access here}} pp[1][1], // expected-note{{used in buffer access here}} - // expected-warning@-1{{unsafe buffer access}} + // expected-warning@-1{{unsafe buffer access through raw pointer}} 1[1[pp]], // expected-note{{used in buffer access here}} - // expected-warning@-1{{unsafe buffer access}} + // expected-warning@-1{{unsafe buffer access through raw pointer}} 1[pp][1] // expected-note{{used in buffer access here}} - // expected-warning@-1{{unsafe buffer access}} + // expected-warning@-1{{unsafe buffer access through raw pointer}} ); if (p[3]) { // expected-note{{used in buffer access here}} void * q = p; - foo(((int*)q)[10]); // expected-warning{{unsafe buffer access}} + foo(((int*)q)[10]); // expected-warning{{unsafe buffer access through raw pointer}} } - foo(((int*)voidPtrCall())[3], // expected-warning{{unsafe buffer access}} - 3[(int*)voidPtrCall()], // expected-warning{{unsafe buffer access}} - charPtrCall()[3], // expected-warning{{unsafe buffer access}} - 3[charPtrCall()] // expected-warning{{unsafe buffer access}} + foo(((int*)voidPtrCall())[3], // expected-warning{{unsafe buffer access through raw pointer}} + 3[(int*)voidPtrCall()], // expected-warning{{unsafe buffer access through raw pointer}} + charPtrCall()[3], // expected-warning{{unsafe buffer access through raw pointer}} + 3[charPtrCall()] // expected-warning{{unsafe buffer access through raw pointer}} ); int a[10]; // expected-warning{{'a' is an unsafe buffer that does not perform bounds checks}} int b[10][10]; // expected-warning{{'b' is an unsafe buffer that does not perform bounds checks}} foo(a[1], 1[a], // expected-note2{{used in buffer access here}} - b[3][4], // expected-warning{{unsafe buffer access}} + b[3][4], // expected-warning{{unsafe buffer access through raw pointer}} // expected-note@-1{{used in buffer access here}} - 4[b][3], // expected-warning{{unsafe buffer access}} + 4[b][3], // expected-warning{{unsafe buffer access through raw pointer}} // expected-note@-1{{used in buffer access here}} - 4[3[b]]); // expected-warning{{unsafe buffer access}} + 4[3[b]]); // expected-warning{{unsafe buffer access through raw pointer}} // expected-note@-1{{used in buffer access here}} // Not to warn when index is zero @@ -96,7 +96,7 @@ expected-note{{change type of 'ap3' to 'std::span' to preserve bounds information}} foo(ap3[1][1]); // expected-note{{used in buffer access here}} - // expected-warning@-1{{unsafe buffer access}} + // expected-warning@-1{{unsafe buffer access through raw pointer}} auto ap4 = *pp; // expected-warning{{'ap4' is an unsafe pointer used for buffer access}} \ expected-note{{change type of 'ap4' to 'std::span' to preserve bounds information}} @@ -120,7 +120,7 @@ q[1], 1[q], q[-1], // expected-note3{{used in buffer access here}} a[1], // expected-note{{used in buffer access here}} `a` is of pointer type b[1][2] // expected-note{{used in buffer access here}} `b[1]` is of array type - // expected-warning@-1{{unsafe buffer access}} + // expected-warning@-1{{unsafe buffer access through raw pointer}} ); } @@ -139,32 +139,32 @@ T_t * funRetTStar(); void testStructMembers(struct T * sp, struct T s, T_t * sp2, T_t s2) { - foo(sp->a[1], // expected-warning{{unsafe buffer access}} - sp->b[1], // expected-warning{{unsafe buffer access}} - sp->c.a[1], // expected-warning{{unsafe buffer access}} - sp->c.b[1], // expected-warning{{unsafe buffer access}} - s.a[1], // expected-warning{{unsafe buffer access}} - s.b[1], // expected-warning{{unsafe buffer access}} - s.c.a[1], // expected-warning{{unsafe buffer access}} - s.c.b[1], // expected-warning{{unsafe buffer access}} - sp2->a[1], // expected-warning{{unsafe buffer access}} - sp2->b[1], // expected-warning{{unsafe buffer access}} - sp2->c.a[1], // expected-warning{{unsafe buffer access}} - sp2->c.b[1], // expected-warning{{unsafe buffer access}} - s2.a[1], // expected-warning{{unsafe buffer access}} - s2.b[1], // expected-warning{{unsafe buffer access}} - s2.c.a[1], // expected-warning{{unsafe buffer access}} - s2.c.b[1], // expected-warning{{unsafe buffer access}} - funRetT().a[1], // expected-warning{{unsafe buffer access}} - funRetT().b[1], // expected-warning{{unsafe buffer access}} - funRetTStar()->a[1], // expected-warning{{unsafe buffer access}} - funRetTStar()->b[1] // expected-warning{{unsafe buffer access}} + foo(sp->a[1], // expected-warning{{unsafe buffer access through raw pointer}} + sp->b[1], // expected-warning{{unsafe buffer access through raw pointer}} + sp->c.a[1], // expected-warning{{unsafe buffer access through raw pointer}} + sp->c.b[1], // expected-warning{{unsafe buffer access through raw pointer}} + s.a[1], // expected-warning{{unsafe buffer access through raw pointer}} + s.b[1], // expected-warning{{unsafe buffer access through raw pointer}} + s.c.a[1], // expected-warning{{unsafe buffer access through raw pointer}} + s.c.b[1], // expected-warning{{unsafe buffer access through raw pointer}} + sp2->a[1], // expected-warning{{unsafe buffer access through raw pointer}} + sp2->b[1], // expected-warning{{unsafe buffer access through raw pointer}} + sp2->c.a[1], // expected-warning{{unsafe buffer access through raw pointer}} + sp2->c.b[1], // expected-warning{{unsafe buffer access through raw pointer}} + s2.a[1], // expected-warning{{unsafe buffer access through raw pointer}} + s2.b[1], // expected-warning{{unsafe buffer access through raw pointer}} + s2.c.a[1], // expected-warning{{unsafe buffer access through raw pointer}} + s2.c.b[1], // expected-warning{{unsafe buffer access through raw pointer}} + funRetT().a[1], // expected-warning{{unsafe buffer access through raw pointer}} + funRetT().b[1], // expected-warning{{unsafe buffer access through raw pointer}} + funRetTStar()->a[1], // expected-warning{{unsafe buffer access through raw pointer}} + funRetTStar()->b[1] // expected-warning{{unsafe buffer access through raw pointer}} ); } int garray[10]; // expected-warning{{'garray' is an unsafe buffer that does not perform bounds checks}} int * gp = garray; // expected-warning{{'gp' is an unsafe pointer used for buffer access}} -int gvar = gp[1]; // FIXME: file scope unsafe buffer access is not warned +int gvar = gp[1]; // FIXME: file scope unsafe buffer access through raw pointer is not warned // FIXME: Add test for lambda capture with initializer. E. g. auto Lam = [new_p = p]() {... void testLambdaCaptureAndGlobal(int * p) { @@ -184,9 +184,9 @@ // expected-warning@-1{{'p' is an unsafe pointer used for buffer access}} foo(p[1], // expected-note{{used in buffer access here}} p[1].a[1], // expected-note{{used in buffer access here}} - // expected-warning@-1{{unsafe buffer access}} + // expected-warning@-1{{unsafe buffer access through raw pointer}} p[1].b[1] // expected-note{{used in buffer access here}} - // expected-warning@-1{{unsafe buffer access}} + // expected-warning@-1{{unsafe buffer access through raw pointer}} ); } @@ -213,21 +213,21 @@ auto y = &a[0]; // expected-warning{{'y' is an unsafe pointer used for buffer access}} foo(p + 1, 1 + p, p - 1, // expected-note3{{used in pointer arithmetic here}} - *q + 1, 1 + *q, *q - 1, // expected-warning3{{unsafe pointer arithmetic}} + *q + 1, 1 + *q, *q - 1, // expected-warning3{{unsafe arithmetic on raw pointer}} x + 1, 1 + x, x - 1, // expected-note3{{used in pointer arithmetic here}} y + 1, 1 + y, y - 1, // expected-note3{{used in pointer arithmetic here}} - getPtr() + 1, 1 + getPtr(), getPtr() - 1 // expected-warning3{{unsafe pointer arithmetic}} + getPtr() + 1, 1 + getPtr(), getPtr() - 1 // expected-warning3{{unsafe arithmetic on raw pointer}} ); p += 1; p -= 1; // expected-note2{{used in pointer arithmetic here}} - *q += 1; *q -= 1; // expected-warning2{{unsafe pointer arithmetic}} + *q += 1; *q -= 1; // expected-warning2{{unsafe arithmetic on raw pointer}} y += 1; y -= 1; // expected-note2{{used in pointer arithmetic here}} x += 1; x -= 1; // expected-note2{{used in pointer arithmetic here}} } void testTemplate(int * p) { int *a[10]; - foo(f(p, &p, a, a)[1]); // expected-warning{{unsafe buffer access}} + foo(f(p, &p, a, a)[1]); // expected-warning{{unsafe buffer access through raw pointer}} // expected-note@-1{{in instantiation of function template specialization 'f' requested here}} const int **q = const_cast(&p); @@ -245,7 +245,7 @@ int * S_t::* q = &S_t::y; foo(S.*p, - (S.*q)[1]); // expected-warning{{unsafe buffer access}} + (S.*q)[1]); // expected-warning{{unsafe buffer access through raw pointer}} } // test that nested callable definitions are scanned only once @@ -337,9 +337,9 @@ int d = cArr[0][0]; foo(cArr[0][0]); foo(cArr[1][2]); // expected-note{{used in buffer access here}} - // expected-warning@-1{{unsafe buffer access}} + // expected-warning@-1{{unsafe buffer access through raw pointer}} auto cPtr = cArr[1][2]; // expected-note{{used in buffer access here}} - // expected-warning@-1{{unsafe buffer access}} + // expected-warning@-1{{unsafe buffer access through raw pointer}} foo(cPtr); // Typdefs @@ -347,7 +347,7 @@ const A tArr = {4, 5, 6}; // expected-warning@-1{{'tArr' is an unsafe buffer that does not perform bounds checks}} foo(tArr[0], tArr[1]); // expected-note{{used in buffer access here}} - return cArr[0][1]; // expected-warning{{unsafe buffer access}} + return cArr[0][1]; // expected-warning{{unsafe buffer access through raw pointer}} } void testArrayPtrArithmetic(int x[]) { // expected-warning{{'x' is an unsafe pointer used for buffer access}}