You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[BoundsSafety][Attempt 2] Add warning diagnostics for uses of legacy bounds checks
** This is the second attempt landing this patch. This first (#108004c8f6e7) failed because there was a bug. **
The bug was in `ParseBoundsSafetyNewChecksMaskFromArgs` where the call to
`DiagnoseDisabledBoundsSafetyChecks` was not guarded with
`DiagnoseMissingChecks`. This missing check caused diagnostics to appear
when they shouldn't and caused crashes in cases where the `Diags`
pointer was nullptr. To fix this the missing guard has been added and
an assert that `Diags` is not null has been added.
Unfortunately it isn't possible to write a regression test for this
because the behavior depends on having at least some bounds checks
disabled by default, which is not desirable behavior. While techinically
we could add a hidden flag to change the default for the purposes of
testing the added complexity of doing this doesn't really justify the
added test coverage.
This version of the patch also guards assigning to
`Opts.BoundsSafetyBringUpMissingChecks` in
`CompilerInvocation::ParseLangArgs` so that it is only assigned to
when `-fbounds-safety` is enabled. This is done for several reasons
* It avoids unnecessarily parsing the `-fbounds-safety-bringup-missing-checks=` flags
when `-fbounds-safety` is disabled.
* Isolates code built without `-fbounds-safety` from bugs in
`ParseBoundsSafetyNewChecksMaskFromArgs`.
* It is more consistent with `CompilerInvocationBase::GenerateLangArgs`
which only emits `-fbounds-safety-bring-checks=` when
`-fbounds-safety` is enabled.
---
This adds warning diagnostics when any of the new bounds checks that can
be enabled with `-fbounds-safety-bringup-missing-checks=batch_0` are
disabled.
If all bounds checks in the batch are disabled a single diagnostic is
emitted. If only some of the bounds checks in the batch are disabled
then a diagnostic is emitted for each disabled bounds check. The
implementation will either suggest enabling a batch of checks (e.g.
`-fbounds-safety-bringup-missing-checks=batch_0`) or will suggest
removing a flag that is explicitly disabling a check (e.g.
`-fno-bounds-safety-bringup-missing-checks=access_size`).
The current implementation supports there being multple batches of
checks. However, there is currently only one batch (`batch_0`).
I originally tried to emit these warnings in the frontend. Unfortunately
it turns out warning suppression (i.e.
`-Wno-bounds-safety-legacy-checks-enabled`) and `-Werror` don't work
correctly if warnings are emitted from the frontend (rdar://152730261).
To workaround this the `-fbounds-safety-bringup-missing-checks=` flags
are now also parsed in the Driver and at this point (and only this
point) diagnostics for missing checks are emitted.
The intention is to make these warnings be errors eventually.
rdar://150805550
0 commit comments