Commit 9643fc4
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://145020583
(cherry picked from commit 3d6f063)1 parent c5c47b4 commit 9643fc4
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 | |
|---|---|---|---|
| |||
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
543 | | - | |
| 543 | + | |
544 | 544 | | |
545 | 545 | | |
546 | 546 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
| 421 | + | |
421 | 422 | | |
422 | 423 | | |
423 | 424 | | |
424 | | - | |
| 425 | + | |
| 426 | + | |
425 | 427 | | |
426 | 428 | | |
427 | | - | |
| 429 | + | |
| 430 | + | |
428 | 431 | | |
429 | 432 | | |
430 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2004 | 2004 | | |
2005 | 2005 | | |
2006 | 2006 | | |
2007 | | - | |
| 2007 | + | |
2008 | 2008 | | |
2009 | 2009 | | |
2010 | 2010 | | |
2011 | 2011 | | |
2012 | | - | |
| 2012 | + | |
2013 | 2013 | | |
2014 | 2014 | | |
2015 | 2015 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
| |||
167 | 169 | | |
168 | 170 | | |
169 | 171 | | |
170 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
171 | 175 | | |
172 | 176 | | |
173 | 177 | | |
| |||
368 | 372 | | |
369 | 373 | | |
370 | 374 | | |
371 | | - | |
| 375 | + | |
372 | 376 | | |
373 | | - | |
374 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
375 | 399 | | |
376 | 400 | | |
377 | 401 | | |
| |||
| 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 | |
|---|---|---|---|
| |||
3940 | 3940 | | |
3941 | 3941 | | |
3942 | 3942 | | |
| 3943 | + | |
| 3944 | + | |
3943 | 3945 | | |
3944 | 3946 | | |
3945 | 3947 | | |
| |||
0 commit comments