You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[-Wunsafe-buffer-usage] Refactor and improve for parameter fix-its
- Factor out the code that will be shared by both parameter and local variable fix-its
- Add a check to ensure that a TypeLoc::isNull is false before using the TypeLoc
- Remove the special check for whether a fixing variable involves unnamed types. This check is unnecessary now.
- Move tests for cv-qualified parameters and unnamed types out of the "...-unsupported.cpp" test file.
Reviewed by: NoQ (Artem Dergachev)
Differential revision: https://reviews.llvm.org/D156188
//Make sure we do not generate fixes for the following cases:
150
+
//Tests parameters with cv-qualifiers
151
151
152
-
#defineMACRO_NAME MyName
152
+
voidconst_ptr(int * const x) { // expected-warning{{'x' is an unsafe pointer used for buffer access}} expected-note{{change type of 'x' to 'std::span' to preserve bounds information}}
voidmacroIdentifier(int *MACRO_NAME) { // The fix-it ends with a macro. It will be discarded due to overlap with macros.
155
-
// CHECK-NOT: fix-it:{{.*}}:{[[@LINE-1]]
156
-
if (++MyName){}
158
+
voidconst_ptr_to_const(constint * const x) {// expected-warning{{'x' is an unsafe pointer used for buffer access}} expected-note{{change type of 'x' to 'std::span' to preserve bounds information}}
voidconst_volatile_ptr(int * constvolatile x) { // expected-warning{{'x' is an unsafe pointer used for buffer access}} expected-note{{change type of 'x' to 'std::span' to preserve bounds information}}
voidvolatile_const_ptr(int * volatileconst x) { // expected-warning{{'x' is an unsafe pointer used for buffer access}} expected-note{{change type of 'x' to 'std::span' to preserve bounds information}}
voidconst_volatile_ptr_to_const_volatile(constvolatileint * constvolatile x) {// expected-warning{{'x' is an unsafe pointer used for buffer access}} expected-note{{change type of 'x' to 'std::span' to preserve bounds information}}
voidconst_ptr(int * const x) { // expected-warning{{'x' is an unsafe pointer used for buffer access}} expected-note{{change type of 'x' to 'std::span' to preserve bounds information}}
voidconst_ptr_to_const(constint * const x) {// expected-warning{{'x' is an unsafe pointer used for buffer access}} expected-note{{change type of 'x' to 'std::span' to preserve bounds information}}
typedefstruct {int x;} NAMED_UNNAMED_STRUCT; // an unnamed struct type named by a typedef
17
-
typedefstruct {int x;} * PTR_TO_ANON; // pointer to an unnamed struct
18
-
typedef NAMED_UNNAMED_STRUCT * PTR_TO_NAMED; //pointer to a named type
7
+
// We CANNOT fix a pointer whose type is defined in a typedef or a
8
+
// macro. Because if the typedef is changed after the fix, the fix
9
+
//becomes incorrect and may not be noticed.
19
10
20
-
// We can fix a pointer to a named type
21
-
voidnamedPointeeType(NAMED_UNNAMED_STRUCT * p) { // expected-warning{{'p' is an unsafe pointer used for buffer access}}\ expected-note{{change type of 'p' to 'std::span' to preserve bounds information}}
0 commit comments