You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[BoundsSafety] Fix missing bounds check when indexing into a buffer of aggregates
Previously bounds checks where missing for a case like:
```
struct F {int x;};
struct F access(struct F* __bidi_indexable f, size_t idx) {
// the index operation should be bounds checked.
return f[idx];
```
Note this only happened specifically for ArraySubscriptExpr and **only**
when the whole aggregate was being loaded with no further operations.
E.g. `f[idx].x` was already correctly bounds checked.
The missing bounds check is guarded using
`-fbounds-safety-bringup-missing-checks=array_subscript_agg` to avoid
breaking existing users.
The bug occured because when `AggExprEmitter::VisitArraySubscriptExpr`
calls `EmitAggLoadOfLValue`, `EmitAggLoadOfLValue` didn't call
`EmitCheckedLValue` and instead called `EmitLValue`.
In this patch the value of `Checked` even when the `array_subscript_agg`
is enabled it still does
```
Checked |= E->getType()->isPointerTypeWithBounds();
```
which was the previous condition for calling `EmitCheckedLValue`. This
is because there's an interaction with UBSan there that we might
accidently change if setting `Checked` in this way was removed. We
should investigate this in the future and this is tracked by
rdar://145257962.
rdar://145020583
(cherry picked from commit 3d6f063)
HelpText<"Enable a set of new -fbounds-safety run-time checks, (option: access_size, indirect_count_update, return_size, ended_by_lower_bound, compound_literal_init, libc_attributes, all)">;
2007
+
HelpText<"Enable a set of new -fbounds-safety run-time checks, (option: access_size, indirect_count_update, return_size, ended_by_lower_bound, compound_literal_init, libc_attributes, array_subscript_agg, all)">;
HelpText<"Disable a set of new -fbounds-safety run-time checks, (option: access_size, indirect_count_update, return_size, ended_by_lower_bound, compound_literal_init, libc_attributes, all)">;
2012
+
HelpText<"Disable a set of new -fbounds-safety run-time checks, (option: access_size, indirect_count_update, return_size, ended_by_lower_bound, compound_literal_init, libc_attributes, array_subscript_agg, all)">;
0 commit comments