Skip to content

Commit 4acf830

Browse files
authored
Merge pull request #10853 from swiftlang/revert-10800-dliew/rdar-150805550
Revert "[BoundsSafety] Add warning diagnostics for uses of legacy bounds checks"
2 parents 75b0846 + d6de4bb commit 4acf830

File tree

9 files changed

+11
-450
lines changed

9 files changed

+11
-450
lines changed

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -402,36 +402,6 @@ def warn_bounds_safety_adoption_mode_ignored : Warning<
402402
"-fbounds-safety-adoption-mode without -fbounds-safety is "
403403
"ignored">,
404404
InGroup<BoundsSafetyAdoptionModeIgnored>;
405-
406-
def warn_bounds_safety_new_checks_none : Warning<
407-
"compiling with legacy -fbounds-safety bounds checks is deprecated;"
408-
" compile with -fbounds-safety-bringup-missing-checks=%0 to use the "
409-
"new bound checks">,
410-
InGroup<BoundsSafetyLegacyChecksEnabled>;
411-
def warn_bounds_safety_new_checks_mixed : Warning<
412-
"compiling with \"%select{"
413-
"access_size|" // BS_CHK_AccessSize
414-
"indirect_count_update|" // BS_CHK_IndirectCountUpdate
415-
"return_size|" // BS_CHK_ReturnSize
416-
"ended_by_lower_bound|" // BS_CHK_EndedByLowerBound
417-
"compound_literal_init|" // BS_CHK_CompoundLiteralInit
418-
"libc_attributes|" // BS_CHK_LibCAttributes
419-
"array_subscript_agg" // BS_CHK_ArraySubscriptAgg
420-
"}0\" bounds check disabled is deprecated;"
421-
" %select{"
422-
"compile with -fbounds-safety-bringup-missing-checks=%2|"
423-
"remove -fno-bounds-safety-bringup-missing-checks=%select{"
424-
"access_size|" // BS_CHK_AccessSize
425-
"indirect_count_update|" // BS_CHK_IndirectCountUpdate
426-
"return_size|" // BS_CHK_ReturnSize
427-
"ended_by_lower_bound|" // BS_CHK_EndedByLowerBound
428-
"compound_literal_init|" // BS_CHK_CompoundLiteralInit
429-
"libc_attributes|" // BS_CHK_LibCAttributes
430-
"array_subscript_agg" // BS_CHK_ArraySubscriptAgg
431-
"}0"
432-
"|}1"
433-
" to enable the new bound checks">,
434-
InGroup<BoundsSafetyLegacyChecksEnabled>;
435405
// TO_UPSTREAM(BoundsSafety) OFF
436406

437407
let CategoryName = "Instrumentation Issue" in {

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,8 +1677,6 @@ def BoundsSafetyStrictTerminatedByCast
16771677
: DiagGroup<"bounds-safety-strict-terminated-by-cast">;
16781678
def BoundsSafetyCountAttrArithConstantCount :
16791679
DiagGroup<"bounds-safety-externally-counted-ptr-arith-constant-count">;
1680-
def BoundsSafetyLegacyChecksEnabled :
1681-
DiagGroup<"bounds-safety-legacy-checks-enabled">;
16821680
// TO_UPSTREAM(BoundsSafety) OFF
16831681

16841682
// -fbounds-safety and bounds annotation related warnings

clang/include/clang/Basic/LangOptions.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,6 @@ class LangOptionsBase {
454454
BS_CHK_CompoundLiteralInit = 1 << 4, // rdar://110871666
455455
BS_CHK_LibCAttributes = 1 << 5, // rdar://84733153
456456
BS_CHK_ArraySubscriptAgg = 1 << 6, // rdar://145020583
457-
458-
BS_CHK_MaxMask = BS_CHK_ArraySubscriptAgg,
459457
};
460458
using BoundsSafetyNewChecksMaskIntTy =
461459
std::underlying_type_t<BoundsSafetyNewChecks>;

clang/include/clang/Driver/BoundsSafetyArgs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ namespace driver {
1616

1717
LangOptions::BoundsSafetyNewChecksMaskIntTy
1818
ParseBoundsSafetyNewChecksMaskFromArgs(const llvm::opt::ArgList &Args,
19-
DiagnosticsEngine *Diags,
20-
bool DiagnoseMissingChecks);
19+
DiagnosticsEngine *Diags);
2120
} // namespace driver
2221
} // namespace clang
2322

clang/lib/Driver/BoundsSafetyArgs.cpp

Lines changed: 7 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
//===----------------------------------------------------------------------===//
88
#include "clang/Driver/BoundsSafetyArgs.h"
99
#include "clang/Basic/DiagnosticDriver.h"
10-
#include "clang/Basic/DiagnosticFrontend.h"
1110
#include "clang/Driver/Options.h"
12-
#include "llvm/ADT/StringSet.h"
13-
#include "llvm/ADT/bit.h"
14-
#include <array>
1511

1612
using namespace llvm::opt;
1713
using namespace clang::driver::options;
@@ -20,103 +16,15 @@ namespace clang {
2016

2117
namespace driver {
2218

23-
static void DiagnoseDisabledBoundsSafetyChecks(
24-
LangOptions::BoundsSafetyNewChecksMaskIntTy EnabledChecks,
25-
DiagnosticsEngine *Diags,
26-
LangOptions::BoundsSafetyNewChecksMaskIntTy
27-
IndividualChecksExplicitlyDisabled) {
28-
struct BoundsCheckBatch {
29-
const char *Name;
30-
LangOptionsBase::BoundsSafetyNewChecksMaskIntTy Checks;
31-
};
32-
33-
// Batches of checks should be ordered with newest first
34-
std::array<BoundsCheckBatch, 2> Batches = {
35-
{// We deliberately don't include `all` here because that batch
36-
// isn't stable over time (unlike batches like `batch_0`) so we
37-
// don't want to suggest users start using it.
38-
{"batch_0",
39-
LangOptions::getBoundsSafetyNewChecksMaskForGroup("batch_0")},
40-
{"none", LangOptions::BS_CHK_None}}};
41-
42-
LangOptionsBase::BoundsSafetyNewChecksMaskIntTy DiagnosedDisabledChecks =
43-
LangOptions::BS_CHK_None;
44-
45-
// Loop over all batches except "none"
46-
for (size_t BatchIdx = 0; BatchIdx < Batches.size() - 1; ++BatchIdx) {
47-
auto ChecksInCurrentBatch = Batches[BatchIdx].Checks;
48-
auto ChecksInOlderBatch = Batches[BatchIdx + 1].Checks;
49-
auto ChecksInCurrentBatchOnly = ChecksInCurrentBatch & ~ChecksInOlderBatch;
50-
const auto *CurrentBatchName = Batches[BatchIdx].Name;
51-
52-
if ((EnabledChecks & ChecksInCurrentBatchOnly) == ChecksInCurrentBatchOnly)
53-
continue; // All checks in batch are enabled. Nothing to diagnose.
54-
55-
// Diagnose disabled bounds checks
56-
57-
if ((EnabledChecks & ChecksInCurrentBatchOnly) == 0) {
58-
// None of the checks in the current batch are enabled. Diagnose this
59-
// once for all the checks in the batch.
60-
if ((DiagnosedDisabledChecks & ChecksInCurrentBatchOnly) !=
61-
ChecksInCurrentBatchOnly) {
62-
Diags->Report(diag::warn_bounds_safety_new_checks_none)
63-
<< CurrentBatchName;
64-
DiagnosedDisabledChecks |= ChecksInCurrentBatchOnly;
65-
}
66-
continue;
67-
}
68-
69-
// Some (but not all) checks are disabled in the current batch. Iterate over
70-
// each check in the batch and emit a diagnostic for each disabled check
71-
// in the batch.
72-
assert(ChecksInCurrentBatch > 0);
73-
auto FirstCheckInBatch = 1 << llvm::countr_zero(ChecksInCurrentBatch);
74-
for (size_t CheckBit = FirstCheckInBatch;
75-
CheckBit <= LangOptions::BS_CHK_MaxMask; CheckBit <<= 1) {
76-
assert(CheckBit != 0);
77-
if ((CheckBit & ChecksInCurrentBatch) == 0)
78-
continue; // Check not in batch
79-
80-
if (EnabledChecks & CheckBit)
81-
continue; // Check is active
82-
83-
// Diagnose disabled check
84-
if (!(DiagnosedDisabledChecks & CheckBit)) {
85-
size_t CheckNumber = llvm::countr_zero(CheckBit);
86-
// If we always suggested enabling the current batch that
87-
// could be confusing if the user passed something like
88-
// `-fbounds-safety-bringup-missing-checks=batch_0
89-
// -fno-bounds-safety-bringup-missing-checks=access_size`. To avoid
90-
// this we detect when the check corresponding to `CheckBit` has been
91-
// explicitly disabled on the command line and in that case we suggeset
92-
// removing the flag.
93-
bool SuggestRemovingFlag =
94-
CheckBit & IndividualChecksExplicitlyDisabled;
95-
Diags->Report(diag::warn_bounds_safety_new_checks_mixed)
96-
<< CheckNumber << SuggestRemovingFlag << CurrentBatchName;
97-
DiagnosedDisabledChecks |= CheckBit;
98-
}
99-
}
100-
}
101-
}
102-
10319
LangOptions::BoundsSafetyNewChecksMaskIntTy
10420
ParseBoundsSafetyNewChecksMaskFromArgs(const llvm::opt::ArgList &Args,
105-
DiagnosticsEngine *Diags,
106-
bool DiagnoseMissingChecks) {
107-
assert((!DiagnoseMissingChecks || Diags) &&
108-
"Cannot diagnose missing checks when Diags is a nullptr");
109-
LangOptions::BoundsSafetyNewChecksMaskIntTy
110-
IndividualChecksExplicitlyDisabled = LangOptions::BS_CHK_None;
21+
DiagnosticsEngine *Diags) {
11122
auto FilteredArgs =
11223
Args.filtered(OPT_fbounds_safety_bringup_missing_checks_EQ,
11324
OPT_fno_bounds_safety_bringup_missing_checks_EQ);
11425
if (FilteredArgs.empty()) {
11526
// No flags present. Use the default
116-
auto Result = LangOptions::getDefaultBoundsSafetyNewChecksMask();
117-
DiagnoseDisabledBoundsSafetyChecks(Result, Diags,
118-
IndividualChecksExplicitlyDisabled);
119-
return Result;
27+
return LangOptions::getDefaultBoundsSafetyNewChecksMask();
12028
}
12129

12230
// If flags are present then start with BS_CHK_None as the initial mask and
@@ -127,11 +35,6 @@ ParseBoundsSafetyNewChecksMaskFromArgs(const llvm::opt::ArgList &Args,
12735
// All the options will be applied as masks in the command line order, to make
12836
// it easier to enable all but certain checks (or disable all but certain
12937
// checks).
130-
const auto Batch0Checks =
131-
LangOptions::getBoundsSafetyNewChecksMaskForGroup("batch_0");
132-
const auto AllChecks =
133-
LangOptions::getBoundsSafetyNewChecksMaskForGroup("all");
134-
bool Errors = false;
13538
for (const Arg *A : FilteredArgs) {
13639
for (const char *Value : A->getValues()) {
13740
std::optional<LangOptions::BoundsSafetyNewChecksMaskIntTy> Mask =
@@ -148,16 +51,17 @@ ParseBoundsSafetyNewChecksMaskFromArgs(const llvm::opt::ArgList &Args,
14851
.Case("libc_attributes", LangOptions::BS_CHK_LibCAttributes)
14952
.Case("array_subscript_agg",
15053
LangOptions::BS_CHK_ArraySubscriptAgg)
151-
.Case("all", AllChecks)
152-
.Case("batch_0", Batch0Checks)
54+
.Case("all",
55+
LangOptions::getBoundsSafetyNewChecksMaskForGroup("all"))
56+
.Case(
57+
"batch_0",
58+
LangOptions::getBoundsSafetyNewChecksMaskForGroup("batch_0"))
15359
.Case("none", LangOptions::BS_CHK_None)
15460
.Default(std::nullopt);
155-
15661
if (!Mask) {
15762
if (Diags)
15863
Diags->Report(diag::err_drv_invalid_value)
15964
<< A->getSpelling() << Value;
160-
Errors = true;
16165
break;
16266
}
16367

@@ -177,7 +81,6 @@ ParseBoundsSafetyNewChecksMaskFromArgs(const llvm::opt::ArgList &Args,
17781
<< A->getSpelling() << Value
17882
<< (IsPosFlag ? "-fno-bounds-safety-bringup-missing-checks"
17983
: "-fbounds-safety-bringup-missing-checks");
180-
Errors = true;
18184
break;
18285
}
18386

@@ -188,25 +91,8 @@ ParseBoundsSafetyNewChecksMaskFromArgs(const llvm::opt::ArgList &Args,
18891
OPT_fno_bounds_safety_bringup_missing_checks_EQ));
18992
Result &= ~(*Mask);
19093
}
191-
192-
// Update which checks have been explicitly disabled. E.g.
193-
// `-fno-bounds-safety-bringup-missing-checks=access_size`.
194-
if (llvm::has_single_bit(*Mask)) {
195-
// A single check was enabled/disabled
196-
if (IsPosFlag)
197-
IndividualChecksExplicitlyDisabled &= ~(*Mask);
198-
else
199-
IndividualChecksExplicitlyDisabled |= *Mask;
200-
} else {
201-
// A batch of checks were enabled/disabled. Any checks in that batch
202-
// are no longer explicitly set.
203-
IndividualChecksExplicitlyDisabled &= ~(*Mask);
204-
}
20594
}
20695
}
207-
if (DiagnoseMissingChecks && Diags && !Errors)
208-
DiagnoseDisabledBoundsSafetyChecks(Result, Diags,
209-
IndividualChecksExplicitlyDisabled);
21096
return Result;
21197
}
21298

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "clang/Basic/Version.h"
2626
#include "clang/Config/config.h"
2727
#include "clang/Driver/Action.h"
28-
#include "clang/Driver/BoundsSafetyArgs.h" // TO_UPSTREAM(BoundsSafety)
2928
#include "clang/Driver/CommonArgs.h"
3029
#include "clang/Driver/Distro.h"
3130
#include "clang/Driver/InputInfo.h"
@@ -7612,15 +7611,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &Job,
76127611
Args.addAllArgs(
76137612
CmdArgs, {options::OPT_fbounds_safety_bringup_missing_checks_EQ,
76147613
options::OPT_fno_bounds_safety_bringup_missing_checks_EQ});
7615-
7616-
// Validate the `-fbounds-safety-bringup-missing-checks` flags and emit
7617-
// warnings for disabled checks. We do this here because if we emit
7618-
// warnings in CC1 (where `ParseBoundsSafetyNewChecksMaskFromArgs` is also
7619-
// called) they cannot be suppressed and ignore `-Werror`
7620-
// (rdar://152730261).
7621-
(void)ParseBoundsSafetyNewChecksMaskFromArgs(
7622-
Args, &D.getDiags(),
7623-
/*DiagnoseMissingChecks=*/true);
76247614
}
76257615
}
76267616

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,8 +1336,7 @@ void DarwinClang::addClangTargetOptions(
13361336
options::OPT_fno_bounds_safety, false)) {
13371337
LangOptions::BoundsSafetyNewChecksMaskIntTy NewChecks =
13381338
ParseBoundsSafetyNewChecksMaskFromArgs(DriverArgs,
1339-
/*DiagnosticsEngine=*/nullptr,
1340-
/*DiagnoseMissingChecks=*/false);
1339+
/*DiagnosticsEngine=*/nullptr);
13411340
if (NewChecks & LangOptions::BS_CHK_LibCAttributes) {
13421341
bool TargetWithoutUserspaceLibc = false;
13431342
if (getTriple().isOSDarwin() && !TargetWithoutUserspaceLibc) {

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4575,13 +4575,9 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
45754575
Args.hasFlag(OPT_ftrigraphs, OPT_fno_trigraphs, Opts.Trigraphs);
45764576

45774577
/*TO_UPSTREAM(BoundsSafety) ON*/
4578-
// Parse the enabled checks and emit any necessary diagnostics.
4579-
// We do not diagnose missing checks here because warnings emitted in this
4580-
// context cannot be surpressed and don't respect `-Werror`
4581-
// (rdar://152730261). Instead we warn about missing checks in the driver.
4578+
// Parse the enabled checks and emit any necessary diagnostics
45824579
Opts.BoundsSafetyBringUpMissingChecks =
4583-
ParseBoundsSafetyNewChecksMaskFromArgs(Args, &Diags,
4584-
/*DiagnoseMissingChecks=*/false);
4580+
ParseBoundsSafetyNewChecksMaskFromArgs(Args, &Diags);
45854581

45864582
// -fbounds-safety should be automatically marshalled into `Opts` in
45874583
// GenerateFrontendArgs() via `LangOpts<"BoundsSafety">` on

0 commit comments

Comments
 (0)