-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[-Wunsafe-buffer-usage] Improving insertion of the [[clang::unsafe_bu…
…ffer_usage]] attribute For a fix-it that inserts the `[[clang::unsafe_buffer_usage]]` attribute, it will lookup existing macros defined for the attribute and use the (last defined such) macro directly. Fix-its will use raw `[[clang::unsafe_buffer_usage]]` if no such macro is defined. The implementation mimics how a similar machine for the `[[fallthrough]]` attribute was implemented. Reviewed by: NoQ (Artem Dergachev) Differential revision: https://reviews.llvm.org/D150338
- Loading branch information
1 parent
2dbc532
commit 5b012bf
Showing
8 changed files
with
153 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-attributes-spelling.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fdiagnostics-parseable-fixits -fsafe-buffer-usage-suggestions -DCMD_UNSAFE_ATTR=[[clang::unsafe_buffer_usage]] %s 2>&1 | FileCheck %s | ||
|
||
|
||
// no need to check fix-its for definition in this test ... | ||
void foo(int *p) { | ||
int tmp = p[5]; | ||
} | ||
|
||
// Will use the macro defined from the command line: | ||
void foo(int *); | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"CMD_UNSAFE_ATTR " | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:";\nvoid foo(std::span<int>)" | ||
|
||
|
||
#undef CMD_UNSAFE_ATTR | ||
void foo(int *); | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"{{\[}}{{\[}}clang::unsafe_buffer_usage{{\]}}{{\]}} " | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:";\nvoid foo(std::span<int>)" | ||
|
||
|
||
#define UNSAFE_ATTR [[clang::unsafe_buffer_usage]] | ||
|
||
void foo(int *); | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"UNSAFE_ATTR " | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:";\nvoid foo(std::span<int>)" | ||
|
||
#undef UNSAFE_ATTR | ||
|
||
#if __has_cpp_attribute(clang::unsafe_buffer_usage) | ||
#define UNSAFE_ATTR [[clang::unsafe_buffer_usage]] | ||
#endif | ||
|
||
void foo(int *); | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"UNSAFE_ATTR " | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:";\nvoid foo(std::span<int>)" | ||
|
||
#undef UNSAFE_ATTR | ||
|
||
#if __has_cpp_attribute(clang::unsafe_buffer_usage) | ||
// we don't know how to use this macro | ||
#define UNSAFE_ATTR(x) [[clang::unsafe_buffer_usage]] | ||
#endif | ||
|
||
void foo(int *); | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"{{\[}}{{\[}}clang::unsafe_buffer_usage{{\]}}{{\]}} " | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-2]]:16-[[@LINE-2]]:16}:";\nvoid foo(std::span<int>)" | ||
|
||
#undef UNSAFE_ATTR | ||
|
||
#define UNSAFE_ATTR_1 [[clang::unsafe_buffer_usage]] | ||
#define UNSAFE_ATTR_2 [[clang::unsafe_buffer_usage]] | ||
#define UNSAFE_ATTR_3 [[clang::unsafe_buffer_usage]] | ||
|
||
// Should use the last defined macro (i.e., UNSAFE_ATTR_3) for | ||
// `[[clang::unsafe_buffer_usage]]` | ||
void foo(int *p); | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"UNSAFE_ATTR_3 " | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-2]]:17-[[@LINE-2]]:17}:";\nvoid foo(std::span<int> p)" | ||
|
||
|
||
#define WRONG_ATTR_1 [clang::unsafe_buffer_usage]] | ||
#define WRONG_ATTR_2 [[clang::unsafe_buffer_usage] | ||
#define WRONG_ATTR_3 [[clang::unsafe_buffer_usag]] | ||
|
||
// The last defined macro for | ||
// `[[clang::unsafe_buffer_usage]]` is still UNSAFE_ATTR_3 | ||
void foo(int *p); | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:1-[[@LINE-1]]:1}:"UNSAFE_ATTR_3 " | ||
// CHECK: fix-it:{{.*}}:{[[@LINE-2]]:17-[[@LINE-2]]:17}:";\nvoid foo(std::span<int> p)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.