Skip to content

[BoundsSafety][APINotes] Add support for bounds safety annotations #10728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 22, 2025

Conversation

delcypher
Copy link

This cherry-picks e5e04cd (#9942) and 013acca (#9901) which were landed in stable/20240723 but not the main branch.

@delcypher delcypher self-assigned this May 22, 2025
@delcypher delcypher added the clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang label May 22, 2025
@delcypher
Copy link
Author

@swift-ci test

@delcypher
Copy link
Author

@swift-ci test llvm

@delcypher
Copy link
Author

I'm going to assume these failures are unrelated.

20:48:10  ********************
20:48:10  Failed Tests (3):
20:48:10    Clang :: CodeGen/ptrauth-restricted-intptr-qualifier.c
20:48:10    LLVM :: Transforms/ConstraintElimination/loops-bottom-tested-pointer-cmps.ll
20:48:10    LLVM :: Transforms/ConstraintElimination/loops-header-tested-pointer-cmps.ll

@delcypher
Copy link
Author

Ah the tests fail on Linux:

18:58:16  Failed Tests (5):
18:58:16    Clang :: APINotes/boundssafety.c
18:58:16    Clang :: APINotes/boundssafety.m

@delcypher
Copy link
Author

I probably need to cherry-pick.

commit 9fbb19c83c25a6d8efbe8741a4902008d09631bd
Author: Henrik G. Olsson <[email protected]>
Date:   Wed Feb 5 18:12:12 2025 -0800

    Disable bounds safety APINotes tests on non-darwin platforms
    
    These test cases use clang modules. TypeCoupledDeclRefInfo
    serialization/deserialization is currently broken on Linux, so disable
    these tests until it's been resolved.

hnrklssn and others added 3 commits May 22, 2025 14:13
This cherry-picks

```
commit e5e04cd
Author: Henrik G. Olsson <[email protected]>
Date:   Mon Feb 3 10:25:30 2025 -0800

    Revert "Revert "[APINotes] Add support for bounds safety annotations""

    This reverts commit 7cbd1e7.
```

from the `swift/release/6.2` branch (landed in
swiftlang#9942).

Conflicts:
	clang/include/clang/Parse/Parser.h
	clang/include/clang/Sema/Sema.h
	clang/lib/APINotes/APINotesFormat.h

Below is the original commit message.

rdar://151820159

---
[APINotes] Add support for bounds safety annotations

This adds support for annotating function parameters with __counted_by,
__sized_by, __counted_by_or_null, __sized_by_or_null, and __ended_by,
using API notes. The main content of handlePtrCountedByEndedByAttr is
extracted to applyPtrCountedByEndedByAttr and decoupled from ParsedAttr.
The helper function ParseBoundsAttributeArgFromString is added to make
it possible to parse count expressions from SemaAPINotes.

The current implementation of __terminated_by/__null_terminated makes it
harder to extract from the iterative type processing, but since it
doesn't require any extra context to parse the attribute, it can be
applied using the normal Type override instead.

rdar://139830881
This was originally landed in `stable/20240723`
(swiftlang#9901) and this patch
cherry-picks it to `main`.

rdar://143701027
(cherry picked from commit 013acca)
These test cases use clang modules. TypeCoupledDeclRefInfo
serialization/deserialization is currently broken on Linux, so disable
these tests until it's been resolved.

This a cherry-pick of a change that was originally landed in
swiftlang#10009 origianlly.

rdar://144275431

(cherry picked from commit 9fbb19c)
@delcypher delcypher force-pushed the dliew/rdar-139830881-main branch from 3c968ed to 6936f54 Compare May 22, 2025 21:27
@delcypher
Copy link
Author

@swift-ci test llvm

* Unguard tests that were crashing on Linux

* Fix TypeCoupledDeclRefInfo (de-)serialization bug

There were two issues here:

1) Deserialization relied on a specific argument evaluation order,
which is unspecified.
2) IsMember was not (de-)serialized.

This problem was originally tracked by rdar://144275431 and
rdar://151820159 tracks landing the missing cherry-pick to the
`next` branch.

(cherry picked from commit aeb1272)
@delcypher
Copy link
Author

@swift-ci test llvm

@delcypher
Copy link
Author

Adding this missing change:

commit aeb127206fcb1ccd7cab529e3c161869f3cb1d2c
Author: Yeoul Na <[email protected]>
Date:   Wed Feb 12 12:33:34 2025 -0800

    Fix TypeCoupledDeclRefInfo (de-)serialization bug (#10009)
    
    * Unguard tests that were crashing on Linux
    
    * Fix TypeCoupledDeclRefInfo (de-)serialization bug
    
    There were two issues here:
    
    1) Deserialization relied on a specific argument evaluation order,
    which is unspecified.
    2) IsMember was not (de-)serialized.

@delcypher
Copy link
Author

Linux has these tests failures.

********************
15:30:38  Failed Tests (3):
15:30:38    Clang :: CodeGen/ptrauth-restricted-intptr-qualifier.c
15:30:38    LLVM :: Transforms/ConstraintElimination/loops-bottom-tested-pointer-cmps.ll
15:30:38    LLVM :: Transforms/ConstraintElimination/loops-header-tested-pointer-cmps.ll

I'm going to assume these are unrelated.

@delcypher
Copy link
Author

I'm going to land now to unblock myself from landing more changes. The macOS tests pass for me locally so that's fairly strong signal that this PR is ok.

@delcypher delcypher merged commit d13646b into swiftlang:next May 22, 2025
0 of 2 checks passed
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.

3 participants