-
Notifications
You must be signed in to change notification settings - Fork 79
Introduce temporary bindings to BoundsCastExprs #694
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
Conversation
…ounds::CompareImpl
…t compare types on bounds expressions
…alValue (introducing the assumption that E1 and E2 have been evaluated)
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 have a few formatting suggestions. I think that the check in EqualValue needs to be pushed into the lexicographic comparison class.
lib/AST/CanonBounds.cpp
Outdated
if (BoundsValueExpr *BV1 = dyn_cast<BoundsValueExpr>(E1)) | ||
if (BV1->getTemporaryBinding() == E2) | ||
if (BoundsValueExpr *BV1 = dyn_cast<BoundsValueExpr>(E1)) { | ||
CHKCBindTemporaryExpr *Binding = BV1->getTemporaryBinding(); |
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.
Stylisitc issues: I believe the indentation of the declaration of Binding is off by one-space.
Clang/LLVM developers don't put single statements in blocks. So:
if (Binding == E2) {
return Result::Equal;
}
should be
if (Binding == E2)
return Result::Equal
#Resolved
lib/AST/CanonBounds.cpp
Outdated
return Result::Equal; | ||
} | ||
if (Binding) { |
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 indentation seems off here.
#Resolved
lib/Sema/SemaBounds.cpp
Outdated
@@ -2471,6 +2470,12 @@ namespace { | |||
} | |||
|
|||
CHKCBindTemporaryExpr *GetTempBinding(Expr *E) { | |||
// Bounds casts should always have a temporary binding. | |||
if (BoundsCastExpr *BCE = dyn_cast<BoundsCastExpr>(E)) { | |||
CHKCBindTemporaryExpr *Result = dyn_cast<CHKCBindTemporaryExpr>(BCE->getSubExpr()); |
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 indentation should be 2 characters.
#Resolved
lib/Sema/SemaBounds.cpp
Outdated
@@ -2234,7 +2222,18 @@ namespace { | |||
} | |||
|
|||
static bool EqualValue(ASTContext &Ctx, Expr *E1, Expr *E2, EquivExprSets *EquivExprs) { | |||
Lexicographic::Result R = Lexicographic(Ctx, EquivExprs).CompareExpr(E1, E2); | |||
// It is assumed that E1 and E2 have been successfully evaluated, so that dynamic and assume bounds casts can be treated as value preserving 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.
I think you need to push this check into Lexicographic expression comparison. There should be a special mode that answer the questions: if e1 and e2 evaluate to values, are the values guaranteed to be equal? We can assume there that any evaluations of dynamic_bounds_cast in subexpressions of e1 (or 32) will succeed and any bounds checks that depend on bounds changed by *_cast operation will also succeed.
#Resolved
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.
Looks great - nice to see code be deleted and become simpler! I have one suggested comment update. Please run automated testing before committing this,.
Cmp = CompareTypeIgnoreCheckedness(E1ChildExpr->getType(), | ||
E2ChildExpr->getType()); | ||
|
||
if (!isa<BoundsExpr>(E1ChildExpr)) |
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.
It'd be helpful to add a comment "Bounds expressions don't have types".
#Resolved
The automated testing has passed. |
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.
For the methods in the BoundsInference class, can you make InCheckedScope a field, instead of passing it as an additional argument? An expression is always in the same checked scope, I believe.
If we were to add support for statement expressions in GCC (https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html) , an expression might not always be in the same checked scope. |
Cherry-picked from commit 82f665e Author: Katherine Kjeer <[email protected]> Commit: GitHub <[email protected]> Introduce temporary bindings to BoundsCastExprs (#694) * Account for cast kind in StmtProfiler::VisitBoundsCastExpr and CanonBounds::CompareImpl * Don't treat dynamic and assume bounds casts as value preserving; don't compare types on bounds expressions * Introduce a temporary binding expression for all bounds cast expressions * Use the temporary bindings introduced in bounds cast expressions to infer bounds * Remove unused PruneTemporaryBindings * Treat e and the usage of a temporary binding of e as equal * Remove llvm_unreachable from CanonBounds::Compare * Account for bounds cast expressions in GetTempBinding * Treat bounds casts as value preserving in CheckBoundsDelarations::EqualValue (introducing the assumption that E1 and E2 have been evaluated) * Remove function call test from bounds-decl-challenges * Add AST dump tests for bounds cast expression temporaries * Fix indentation * More formatting fixes * Revert treating bounds casts as value preserving in EqualValue * Add comment about lack of bounds expression types * Prune temporary bindings from member expression bounds * Account for checked scope information in PruneTemporaryBindings
This PR adds a temporary binding expression when building a BoundsCastExpr. This helps enable dynamic and assume bounds casts expressions to be treated as non-value-preserving in CanonBounds::CompareExpr (see issue #691).
Changes
PruneTemporaryBindings
. (A follow-up issue Differentiate between Memory and Bounds checked scopes in SemaBounds #698 is opened to use theCheckedScopeSpecifier
enum rather than a boolean here.)Consider BoundsCastExprs to be value-preserving in CheckBoundsDeclarations::EqualValue. Note: this assumes that the expressions E1 and E2 have been successfully evaluated.This change has been removed. This affects the Checked C static_check_bounds_cast.c test (modified in Add tests for bounds cast expression temporary bindings checkedc#385 - opened Improve memory access detection for bounds casts #695 to track remaining work).Tests