Check that variables and member expressions used in return bounds are unmodified#1170
Conversation
…ons, and set the ReturnBounds member to the expanded return bounds (cherry picked from commit ec74226)
|
|
||
| // Account for uses of LValue in the declared return bounds (if any) | ||
| // for the enclosing function. | ||
| UpdateReturnBoundsAfterAssignment(LValue, E, Src, CSS); |
There was a problem hiding this comment.
The name UpdateRetunrBoundsAfterAssignment may be misleading. There is really no "update" happening - my understanding is that this function checks if LValue occurs in ReturnBounds.
| // TODO: track an observed return bounds expression as a global property | ||
| // of the function body so that invertibility of lvalue expressions can | ||
| // be taken into account. | ||
| void UpdateReturnBoundsAfterAssignment(Expr *LValue, Expr *E, Expr *Src, |
There was a problem hiding this comment.
It looks like the third parameter Src is not used anywhere in this function.
|
|
||
| SourceLocation DeclaredLoc = FunctionDeclaration->getLocation(); | ||
| S.Diag(DeclaredLoc, diag::note_declared_return_bounds) | ||
| << ReturnBounds << ReturnBounds->getSourceRange(); |
There was a problem hiding this comment.
Suppose there were multiple program points in a function where a variable or a member expression used in ReturnBounds got modified, then would multiple error messages be emitted?
There was a problem hiding this comment.
Yes, there would be an error emitted at each assignment to a variable or member expression that is used in ReturnBounds.
In unchecked scopes, it may probably be more consistent with our discussed policy to perform this check whenever the return bounds are checked (i.e. when the return expression has a checked pointer type, or the return expression has an unchecked pointer type because of implicit casting from checked to unchecked pointer types). In other words, in unchecked scopes, either:
|
In the following example: The assignment In an analogous example for checking the bounds of a variable with a bounds-safe interface: The assignment As I understand it, our current policy for checking the bounds of a variable
I would propose the following policy for checking the bounds of a function
I'd like to discuss these policies further. |
|
Yes, let's discuss it tomorrow. |
|
Per offline discussion, we have the following policy for checking that variable or member expressions used in declared return bounds are unmodified:
This is commented on line 4603 of SemaBounds.cpp in this PR. |
…into exprs-used-in-return-bounds
After each assignment expression to a variable or member expression
e, this PR checks thateis not used in the declared return bounds (if any) for the enclosing function.In unchecked scopes, if the enclosing function has a bounds-safe interface, this checking is not performed (regardless of the type of
eor the type of the RHS expression that was assigned toe).