Skip to content

[BoundsSafety] Switch new bounds checks on by default and adjust testsuite #10619

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 1 commit into from
May 3, 2025

Conversation

delcypher
Copy link

This makes clang behave as if
-fbounds-safety-bringup-missing-checks=batch_0 was passed by default. This enables all the new bounds check in the batch_0 group by default (which is currently all of them).

Making this change broke a lot of tests. To handle this the following strategy was taken:

  • To avoid losing test coverage for when the legacy bounds checks are a new clang/test/BoundsSafety-legacy-checks directory has been created and all the tests that failed have been copied into this directory. This directory has a lit.local.cfg.py file that means the %clang_cc1 substitution contains -fno-bounds-safety-bringup-missing-checks=all. Doing that means all tests under this directory build with the new bounds checks disabled implicitly which means the copies of the tests didn't need modification to pass. We can delete this directory when we drop support for the legacy bounds checks.
  • All failing tests under clang/test/BoundsSafety have been modified to pass with the new bounds checks enabled. Note I've not removed use of -fbounds-safety-bringup-missing-checks= under this test directory. This is something we should do as a separate clean up step.

This strategy means we haven't lost any test coverage and we have gained much more test coverage for the new bounds checks.

Unfortunately while doing this I discovered that enabling the new bounds checks breaks the experimental C++ support (see
BoundsSafety/AST/value-dependence.cpp and
BoundsSafety/Sema/value-dependence.cpp) (rdar://150044760). Given that this feature isn't currently adopted this seems acceptable and is something we can fix later if we need to.

Unfortunately I also discovered that clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O2.c is broken. I've XFAIL-ed the test and we'll need to fix a separate patch (rdar://150559639).

rdar://148623233

… suite

This makes clang behave as if
`-fbounds-safety-bringup-missing-checks=batch_0` was passed by default.
This enables all the new bounds check in the `batch_0` group by default
(which is currently all of them).

Making this change broke a lot of tests. To handle this the following
strategy was taken:

* To avoid losing test coverage for when the legacy bounds checks are
  a new `clang/test/BoundsSafety-legacy-checks` directory has been
  created and all the tests that failed have been copied into this
  directory. This directory has a `lit.local.cfg.py` file that means
  the `%clang_cc1` substitution contains
  `-fno-bounds-safety-bringup-missing-checks=all`. Doing that means all
  tests under this directory build with the new bounds checks disabled
  implicitly which means the copies of the tests didn't need
  modification to pass. We can delete this directory when we drop
  support for the legacy bounds checks.
* All failing tests under `clang/test/BoundsSafety` have been modified
  to pass with the new bounds checks enabled. Note I've not removed
  use of `-fbounds-safety-bringup-missing-checks=` under this test
  directory. This is something we should do as a separate clean up step.

This strategy means we haven't lost any test coverage and we have gained
much more test coverage for the new bounds checks.

Unfortunately while doing this I discovered that enabling the new bounds
checks breaks the experimental C++ support (see
`BoundsSafety/AST/value-dependence.cpp` and
`BoundsSafety/Sema/value-dependence.cpp`) (rdar://150044760). Given that
this feature isn't currently adopted this seems acceptable and is
something we can fix later if we need to.

Unfortunately I also discovered that `clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O2.c`
is broken. I've XFAIL-ed the test and we'll need to fix a separate patch (rdar://150559639).

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

@swift-ci test llvm

@delcypher delcypher merged commit 34ce74b into swiftlang:next May 3, 2025
2 checks passed
delcypher added a commit to delcypher/apple-llvm-project that referenced this pull request May 6, 2025
… CodeGen tests

When rdar://148623233 (swiftlang#10619) landed the BoundsSafety test directories
now have compiler flags implicitly passed when using the `%clang_cc1`
substitution. This is done using the `lit.local.cfg.py` files under
`clang/test/BoundsSafety` and `clang/test/BoundsSafety-legacy-checks`.

However, the `update_cc_test_checks.py` script doesn't know anything
about the `llvm-lit` configuration. Instead, it hardcodes what `%clang_cc1`
expands to. This can cause problems when using the script because the
script invokes clang differently to how `llvm-lit` will do it.

To avoid these problems the following changes are made

* Tests under `clang/test/BoundsSafety` have
  `-fbounds-safety-bringup-missing-checks=batch_0` implicitly passed
* Tests under `clang/test/BoundsSafety-legacy-checks` have
  `-fno-bounds-safety-bringup-missing-checks=all` passed

We can remove this entirely once support for the legacy bounds safety
checks are removed.

rdar://150800853
delcypher added a commit that referenced this pull request May 6, 2025
… CodeGen tests

When rdar://148623233 (#10619) landed the BoundsSafety test directories
now have compiler flags implicitly passed when using the `%clang_cc1`
substitution. This is done using the `lit.local.cfg.py` files under
`clang/test/BoundsSafety` and `clang/test/BoundsSafety-legacy-checks`.

However, the `update_cc_test_checks.py` script doesn't know anything
about the `llvm-lit` configuration. Instead, it hardcodes what `%clang_cc1`
expands to. This can cause problems when using the script because the
script invokes clang differently to how `llvm-lit` will do it.

To avoid these problems the following changes are made

* Tests under `clang/test/BoundsSafety` have
  `-fbounds-safety-bringup-missing-checks=batch_0` implicitly passed
* Tests under `clang/test/BoundsSafety-legacy-checks` have
  `-fno-bounds-safety-bringup-missing-checks=all` passed

We can remove this entirely once support for the legacy bounds safety
checks are removed.

rdar://150800853
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