-
Notifications
You must be signed in to change notification settings - Fork 349
[-Wunsafe-buffer-usage] Add support for dependent values with deref #11522
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
[-Wunsafe-buffer-usage] Add support for dependent values with deref #11522
Conversation
This is taken from the original PR: #11490 |
What happens with something like |
We don't have plans to support C++ refs. If any of this works, we should file a bug and fix it. |
// This function will be repeatedly called on the "Other" Expr, because the | ||
// kind of "Other" stays unknown during the traversal. | ||
const Expr * | ||
trySubstituteAndSimplify(const Expr *E, bool &hasBeenSubstituted, |
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.
The trySubstituteAndSimplify
function only applies to Other
in the comparator. Do you want to apply such substitution to both comparands?
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 updated VisitUnaryOperator
to try to substitute Self
before comparing the expr with Other
. So, if Self
has deref, it will substitute it first, and then recursively compare to Other
.
What is a motivating example of this? I'm curious where you can extract the information that |
A test case from my original PR: void good_inout_subspan_const(int *__counted_by(*count) *p, size_t *count, std::span<int> sp) {
*p = sp.first(42).data();
*count = 42;
} Here, we would have |
Before this change, we could only map ValueDecl to Expr to model dependent values. This change adds support for mapping ValueDecl with optional dereference to Expr. For example, this allows us to model dependent values with the following mapping: ``` count -> 42 *out_count -> 100 ``` Supporting dereference is necessary in order to check assignments to inout pointer and count in the future.
44efedf
to
0699295
Compare
@swift-ci llvm test |
@swift-ci test llvm |
Before this change, we could only map ValueDecl to Expr to model dependent values. This change adds support for mapping ValueDecl with optional dereference to Expr. For example, this allows us to model dependent values with the following mapping:
Supporting dereference is necessary in order to check assignments to inout pointer and count in the future.