-
Notifications
You must be signed in to change notification settings - Fork 349
[-Wunsafe-buffer-usage] Check for too complex count-attributed assignments #11524
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
base: next
Are you sure you want to change the base?
[-Wunsafe-buffer-usage] Check for too complex count-attributed assignments #11524
Conversation
This is taken from the original PR: #11490 |
Copy-paste from the original PR to continue the discussion:
I agree that my initial diagnostic needs rework. I think your diagnostic is better. Though, does |
3e72540
to
5c2cda7
Compare
I updated the warning to:
|
To be pedantic🧐, the But I think people will understand what we mean there unambiguously. |
Thank you @patrykstefanski , I don't have other major concerns. |
5c2cda7
to
70254e2
Compare
@ziqingluo-90 I update the naming in code to reflect that the assignment must be simple or is too complex (instead of 'standalone'). |
|
||
static std::optional<BoundsAttributedObject> | ||
getBoundsAttributedObject(const Expr *E) { | ||
E = E->IgnoreParenCasts(); |
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.
Do you want IgnoreParenImpCasts
here?
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.
IgnoreParenCasts
lets us see through explicit casts as well, which in turn lets us detect more assignments to bounds-attributed objects.
clang/test/SemaCXX/warn-unsafe-buffer-usage-count-attributed-pointer-assignment.cpp
Show resolved
Hide resolved
70254e2
to
e0ee8ec
Compare
@swift-ci test llvm |
…ments This is an initial part of an analysis of count-attributed assignment groups. This commit adds an AST visitor that is responsible for finding bounds-attributed assignment groups and assignments to bounds-attributed objects (pointers and dependent counts) that are too complex to verify. As a PoC, this commit adds checks for too complex assignments, which are assignments that are not directly inside of a compound statement (like other assignment groups) and modify the pointer or count in some way. Our model rejects those and requires the user to simplify their code. For example: ``` void foo(int *__counted_by(count) p, int count) { q = p = ...; ^ this is rejected n = count = ...; ^ this is rejected // the following is fine: p = ...; count = ...; } ``` rdar://161607826
e0ee8ec
to
ed31544
Compare
@swift-ci test llvm |
This is an initial part of an analysis of count-attributed assignment groups. This commit adds an AST visitor that is responsible for finding bounds-attributed assignment groups and assignments to bounds-attributed objects (pointers and dependent counts) that are too complex to verify.
As a PoC, this commit adds checks for too complex assignments, which are assignments that are not directly inside of a compound statement (like other assignment groups) and modify the pointer or count in some way. Our model rejects those and requires the user to simplify their code.
For example:
rdar://161607826