-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[-Wunsafe-buffer-usage] Add unique_ptr <T[]> accesses #156773
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
fmayer
merged 21 commits into
llvm:main
from
shreya-jain:add-uniqueptr-to-unsafe-buffer-usage
Oct 8, 2025
Merged
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
927b2f6
Update UnsafeBufferUsage.h
shreya-jain bae5f2e
Update UnsafeBufferUsageGadgets.def
shreya-jain 284c262
Update DiagnosticGroups.td
shreya-jain 980a75e
Update DiagnosticSemaKinds.td
shreya-jain 11fc596
Update UnsafeBufferUsage.cpp
shreya-jain 800d393
Update AnalysisBasedWarnings.cpp
shreya-jain 4c95972
Update warn-unsafe-buffer-usage-debug-unclaimed.cpp
shreya-jain 38a2d44
fix compilation issues and test
shreya-jain dd1ab78
Merge branch 'main' into add-uniqueptr-to-unsafe-buffer-usage
shreya-jain aacc510
Merge branch 'main' into add-uniqueptr-to-unsafe-buffer-usage
shreya-jain f074fd0
Merge branch 'main' into add-uniqueptr-to-unsafe-buffer-usage
shreya-jain 5bc6580
address review comments
shreya-jain 766be17
Merge branch 'add-uniqueptr-to-unsafe-buffer-usage' of github.com:shr…
shreya-jain eb9afef
Merge branch 'main' into add-uniqueptr-to-unsafe-buffer-usage
shreya-jain efb19b6
[-Wunsafe-buffer-usage] Add unique_ptr <T[]> accesses
shreya-jain 7cefe30
[-Wunsafe-buffer-usage] Add unique_ptr <T[]> accesses
shreya-jain 6cf2c9f
[-Wunsafe-buffer-usage] Add unique_ptr <T[]> accesses
shreya-jain f805faf
[-Wunsafe-buffer-usage] Add unique_ptr <T[]> accesses
shreya-jain db8a2bc
Merge branch 'main' into add-uniqueptr-to-unsafe-buffer-usage
shreya-jain 9d597ed
Merge branch 'main' into add-uniqueptr-to-unsafe-buffer-usage
shreya-jain 2b823cb
Merge branch 'main' into add-uniqueptr-to-unsafe-buffer-usage
shreya-jain 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
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
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
62 changes: 62 additions & 0 deletions
62
clang/test/SemaCXX/warn-unsafe-buffer-usage-unique-ptr.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,62 @@ | ||
// RUN: %clang_cc1 -Wno-unused-value -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions -std=c++20 -verify=expected %s | ||
|
||
// This debugging facility is only available in debug builds. | ||
shreya-jain marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// | ||
// REQUIRES: asserts | ||
|
||
namespace std { | ||
inline namespace __1 { | ||
template <class T> class unique_ptr { | ||
public: | ||
T &operator[](long long i) const; | ||
}; | ||
} // namespace __1 | ||
} // namespace std | ||
|
||
int get_index() { | ||
return 4; | ||
} | ||
|
||
void basic_unique_ptr() { | ||
std::unique_ptr<int[]> p1; | ||
int i = 2; | ||
const int j = 3; | ||
int k = 0; | ||
|
||
p1[0]; // This is allowed | ||
|
||
p1[k]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
|
||
p1[1]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
|
||
p1[1L]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
|
||
p1[1LL]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
|
||
p1[3 * 5]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
|
||
p1[i]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
|
||
p1[j]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
|
||
p1[i + 5]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
|
||
p1[get_index()]; // expected-warning{{direct access using operator[] on std::unique_ptr<T[]> is unsafe due to lack of bounds checking}} | ||
|
||
} | ||
|
||
// CHECK: Root # 1 | ||
shreya-jain marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// CHECK: |- DeclRefExpr # 4 | ||
// CHECK: |-- UnaryOperator(++) # 1 | ||
// CHECK: |--- CompoundStmt # 1 | ||
// CHECK: |-- ImplicitCastExpr(LValueToRValue) # 1 | ||
// CHECK: |--- BinaryOperator(+) # 1 | ||
// CHECK: |---- ParenExpr # 1 | ||
// CHECK: |----- BinaryOperator(+) # 1 | ||
// CHECK: |------ ParenExpr # 1 | ||
// CHECK: |------- UnaryOperator(*) # 1 | ||
// CHECK: |-------- CompoundStmt # 1 | ||
// CHECK: |-- BinaryOperator(-=) # 1 | ||
// CHECK: |--- CompoundStmt # 1 | ||
// CHECK: |-- UnaryOperator(--) # 1 | ||
// CHECK: |--- CompoundStmt # 1 |
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.
Uh oh!
There was an error while loading. Please reload this page.