Commit 6466fd2
committed
[-Wunsafe-buffer-usage] Check count-attributed objects that are used and assigned in the same group
Check if the bounds-attributed group has assignments to objects that are
also used in the same group. In those cases, the correctness of the
group might depend on the order of assignments. We conservatively
disallow such assignments.
In the example below, the bounds-check in `sp.first()` uses the value of
`b` before the later update, which can lead to OOB if `b` was less than
42.
```
void foo(int *__counted_by(a + b) p, int a, int b, std::span<int> sp) {
p = sp.first(b + 42).data();
b = 42; // b is assigned and used
a = b;
}
```
rdar://161608319
(cherry picked from commit 7e4ad9d)1 parent 81c6606 commit 6466fd2
File tree
5 files changed
+113
-1
lines changed- clang
- include/clang
- Analysis/Analyses
- Basic
- lib
- Analysis
- Sema
- test/SemaCXX
5 files changed
+113
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
183 | 189 | | |
184 | 190 | | |
185 | 191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14127 | 14127 | | |
14128 | 14128 | | |
14129 | 14129 | | |
| 14130 | + | |
| 14131 | + | |
| 14132 | + | |
14130 | 14133 | | |
14131 | 14134 | | |
14132 | 14135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5457 | 5457 | | |
5458 | 5458 | | |
5459 | 5459 | | |
| 5460 | + | |
| 5461 | + | |
| 5462 | + | |
| 5463 | + | |
| 5464 | + | |
| 5465 | + | |
| 5466 | + | |
| 5467 | + | |
| 5468 | + | |
| 5469 | + | |
5460 | 5470 | | |
5461 | 5471 | | |
5462 | 5472 | | |
| |||
5500 | 5510 | | |
5501 | 5511 | | |
5502 | 5512 | | |
5503 | | - | |
| 5513 | + | |
5504 | 5514 | | |
5505 | 5515 | | |
5506 | 5516 | | |
| |||
5512 | 5522 | | |
5513 | 5523 | | |
5514 | 5524 | | |
| 5525 | + | |
5515 | 5526 | | |
5516 | 5527 | | |
5517 | 5528 | | |
| |||
5653 | 5664 | | |
5654 | 5665 | | |
5655 | 5666 | | |
| 5667 | + | |
| 5668 | + | |
| 5669 | + | |
| 5670 | + | |
| 5671 | + | |
| 5672 | + | |
| 5673 | + | |
| 5674 | + | |
| 5675 | + | |
| 5676 | + | |
| 5677 | + | |
| 5678 | + | |
| 5679 | + | |
| 5680 | + | |
| 5681 | + | |
| 5682 | + | |
5656 | 5683 | | |
5657 | 5684 | | |
5658 | 5685 | | |
| |||
5784 | 5811 | | |
5785 | 5812 | | |
5786 | 5813 | | |
| 5814 | + | |
| 5815 | + | |
| 5816 | + | |
| 5817 | + | |
| 5818 | + | |
| 5819 | + | |
| 5820 | + | |
| 5821 | + | |
| 5822 | + | |
| 5823 | + | |
| 5824 | + | |
| 5825 | + | |
| 5826 | + | |
| 5827 | + | |
| 5828 | + | |
| 5829 | + | |
| 5830 | + | |
| 5831 | + | |
| 5832 | + | |
| 5833 | + | |
| 5834 | + | |
| 5835 | + | |
| 5836 | + | |
| 5837 | + | |
| 5838 | + | |
| 5839 | + | |
| 5840 | + | |
| 5841 | + | |
| 5842 | + | |
| 5843 | + | |
| 5844 | + | |
| 5845 | + | |
| 5846 | + | |
| 5847 | + | |
| 5848 | + | |
| 5849 | + | |
| 5850 | + | |
| 5851 | + | |
| 5852 | + | |
| 5853 | + | |
| 5854 | + | |
| 5855 | + | |
| 5856 | + | |
| 5857 | + | |
| 5858 | + | |
| 5859 | + | |
5787 | 5860 | | |
5788 | 5861 | | |
5789 | 5862 | | |
| |||
5793 | 5866 | | |
5794 | 5867 | | |
5795 | 5868 | | |
| 5869 | + | |
| 5870 | + | |
5796 | 5871 | | |
5797 | 5872 | | |
5798 | 5873 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2675 | 2675 | | |
2676 | 2676 | | |
2677 | 2677 | | |
| 2678 | + | |
| 2679 | + | |
| 2680 | + | |
| 2681 | + | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + | |
| 2685 | + | |
| 2686 | + | |
| 2687 | + | |
2678 | 2688 | | |
2679 | 2689 | | |
2680 | 2690 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
342 | 360 | | |
343 | 361 | | |
344 | 362 | | |
| |||
0 commit comments