Commit 3d6f063
committed
[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://1450205831 parent af46dfa commit 3d6f063
File tree
8 files changed
+1765
-12
lines changed- clang
- include/clang
- Basic
- Driver
- lib
- CodeGen
- Driver
- Frontend
- test/BoundsSafety/CodeGen
- unittests/Tooling
8 files changed
+1765
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
548 | 548 | | |
549 | 549 | | |
550 | 550 | | |
551 | | - | |
| 551 | + | |
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
| 457 | + | |
457 | 458 | | |
458 | 459 | | |
459 | 460 | | |
460 | | - | |
| 461 | + | |
| 462 | + | |
461 | 463 | | |
462 | 464 | | |
463 | | - | |
| 465 | + | |
| 466 | + | |
464 | 467 | | |
465 | 468 | | |
466 | 469 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1964 | 1964 | | |
1965 | 1965 | | |
1966 | 1966 | | |
1967 | | - | |
| 1967 | + | |
1968 | 1968 | | |
1969 | 1969 | | |
1970 | 1970 | | |
1971 | 1971 | | |
1972 | | - | |
| 1972 | + | |
1973 | 1973 | | |
1974 | 1974 | | |
1975 | 1975 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
85 | 87 | | |
86 | 88 | | |
87 | 89 | | |
| |||
171 | 173 | | |
172 | 174 | | |
173 | 175 | | |
174 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
175 | 179 | | |
176 | 180 | | |
177 | 181 | | |
| |||
372 | 376 | | |
373 | 377 | | |
374 | 378 | | |
375 | | - | |
| 379 | + | |
376 | 380 | | |
377 | | - | |
378 | | - | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
379 | 403 | | |
380 | 404 | | |
381 | 405 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4056 | 4056 | | |
4057 | 4057 | | |
4058 | 4058 | | |
| 4059 | + | |
| 4060 | + | |
4059 | 4061 | | |
4060 | 4062 | | |
4061 | 4063 | | |
| |||
0 commit comments