-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[-Wunsafe-buffer-usage] Add FixableGadget for AddAssign in UnspecifiedUntypedContext #71862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6636745
[-Wunsafe-buffer-usage][WIP] Fixable gadget for AddAssign
t-rasmud d5f00a5
[-Wunsafe-buffer-usage][WIP] Fixable gadget for AddAssign: handle int…
t-rasmud ec71495
[-Wunsafe-buffer-usage][WIP] Fixable gadget for AddAssign: handle Dec…
t-rasmud b040dcb
[-Wunsafe-buffer-usage] Fixable gadget for AddAssign: handle DeclRefE…
t-rasmud 65ae8a8
[-Wunsafe-buffer-usage] Fixable gadget for AddAssign: fix formatting
t-rasmud 4ccd7e1
[-Wunsafe-buffer-usage] Fixable gadget for AddAssign: fix formatting
t-rasmud 19083c1
[-Wunsafe-buffer-usage] Fixable gadget for AddAssign: Address comments
t-rasmud 432a8d3
[-Wunsafe-buffer-usage] Fixable gadget for AddAssign: Fix formatting
t-rasmud 6217e3d
[-Wunsafe-buffer-usage] Fixable gadget for AddAssign: Fix formatting
t-rasmud 7236e8e
[-Wunsafe-buffer-usage][WIP] Fixable gadget for AddAssign: Address pa…
t-rasmud 0cbf6f3
[-Wunsafe-buffer-usage][WIP] Fixable gadget for AddAssign: Clean-up
t-rasmud b21e329
[-Wunsafe-buffer-usage][WIP] Fixable gadget for AddAssign: Clean-up
t-rasmud efc5790
[-Wunsafe-buffer-usage][WIP] Fixable gadget for AddAssign: Clean-up
t-rasmud db8cbde
[-Wunsafe-buffer-usage][WIP] Fixable gadget for AddAssign: Address co…
t-rasmud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
59 changes: 59 additions & 0 deletions
59
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-add-assign.cpp
This file contains hidden or 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,59 @@ | ||
// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \ | ||
// RUN: -fsafe-buffer-usage-suggestions \ | ||
// RUN: -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s | ||
void foo(int * , int *); | ||
|
||
void add_assign_test(unsigned int n, int *a, int y) { | ||
int *p = new int[10]; | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> p" | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{" | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}" | ||
p += 2; | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:7}:"p = p.subspan(" | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:9-[[@LINE-2]]:9}:")" | ||
|
||
int *r = p; | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span<int> r" | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{" | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:13-[[@LINE-3]]:13}:", <# placeholder #>}" | ||
while (*r != 0) { | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:11}:"" | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"[0]" | ||
r += 2; | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:5-[[@LINE-1]]:9}:"r = r.subspan(" | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:11}:")" | ||
} | ||
|
||
if (*p == 0) { | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"" | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:9-[[@LINE-2]]:9}:"[0]" | ||
p += n; | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:5-[[@LINE-1]]:9}:"p = p.subspan(" | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:11}:")" | ||
} | ||
|
||
if (*p == 1) | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"" | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:9-[[@LINE-2]]:9}:"[0]" | ||
p += 3; | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:5-[[@LINE-1]]:9}:"p = p.subspan(" | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:11}:")" | ||
|
||
a += -9; | ||
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:5-[[@LINE-1]]:9}:"p = p.subspan(" | ||
|
||
a += y; | ||
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:5-[[@LINE-1]]:9}:"p = p.subspan(" | ||
} | ||
|
||
int expr_test(unsigned x, int *q, int y) { | ||
char *p = new char[8]; | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::span<char> p" | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:13}:"{" | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:24-[[@LINE-3]]:24}:", 8}" | ||
p += (x + 1); | ||
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:7}:"p = p.subspan" | ||
|
||
q += (y + 7); | ||
// CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:7}:"q = q.subspan" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm starting to like how these checks live in
getFixits()
, as opposed to the matcher. It's not like we'll ever be able to fix the signed case, but this way they'll show up in debug statistics as "gadget refused to produce a fix", which is better than the generic "it never matched". We could even make a dedicated debug message for this failure specifically!