Skip to content

Conversation

@patrykstefanski
Copy link

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)

…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)
@patrykstefanski patrykstefanski self-assigned this Nov 5, 2025
@patrykstefanski patrykstefanski added the clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang label Nov 5, 2025
@patrykstefanski
Copy link
Author

@swift-ci test

@patrykstefanski
Copy link
Author

@swift-ci test llvm

@patrykstefanski
Copy link
Author

@swift-ci test macOS platform

@patrykstefanski
Copy link
Author

Timed out...

@patrykstefanski patrykstefanski merged commit 6466fd2 into swiftlang:stable/21.x Nov 6, 2025
5 checks passed
@patrykstefanski patrykstefanski deleted the eng/pstefanski/PR-161608319-21.x branch November 6, 2025 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant