Skip to content

Commit e1bd974

Browse files
committed
Revert "Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (#108453)"
This reverts commit e7f782e. This had UBSan failures: [----------] 1 test from ConfigCompileTests [ RUN ] ConfigCompileTests.DiagnosticSuppression Config fragment: compiling <unknown>:0 -> 0x00007B8366E2F7D8 (trusted=false) /usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33: runtime error: reference binding to null pointer of type 'clang::DiagnosticIDs' UndefinedBehaviorSanitizer: undefined-behavior /usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33 Pull Request: #108645
1 parent f885e02 commit e1bd974

29 files changed

+225
-546
lines changed

clang-tools-extra/clangd/Diagnostics.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -579,17 +579,7 @@ std::vector<Diag> StoreDiags::take(const clang::tidy::ClangTidyContext *Tidy) {
579579
for (auto &Diag : Output) {
580580
if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) {
581581
// Warnings controlled by -Wfoo are better recognized by that name.
582-
const StringRef Warning = [&] {
583-
if (OrigSrcMgr) {
584-
return OrigSrcMgr->getDiagnostics()
585-
.getDiagnosticIDs()
586-
->getWarningOptionForDiag(Diag.ID);
587-
}
588-
if (!DiagnosticIDs::IsCustomDiag(Diag.ID))
589-
return DiagnosticIDs{}.getWarningOptionForDiag(Diag.ID);
590-
return StringRef{};
591-
}();
592-
582+
StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID);
593583
if (!Warning.empty()) {
594584
Diag.Name = ("-W" + Warning).str();
595585
} else {
@@ -906,23 +896,20 @@ void StoreDiags::flushLastDiag() {
906896
Output.push_back(std::move(*LastDiag));
907897
}
908898

909-
bool isDiagnosticSuppressed(const clang::Diagnostic &Diag,
910-
const llvm::StringSet<> &Suppress,
911-
const LangOptions &LangOpts) {
899+
bool isBuiltinDiagnosticSuppressed(unsigned ID,
900+
const llvm::StringSet<> &Suppress,
901+
const LangOptions &LangOpts) {
912902
// Don't complain about header-only stuff in mainfiles if it's a header.
913903
// FIXME: would be cleaner to suppress in clang, once we decide whether the
914904
// behavior should be to silently-ignore or respect the pragma.
915-
if (Diag.getID() == diag::pp_pragma_sysheader_in_main_file &&
916-
LangOpts.IsHeaderFile)
905+
if (ID == diag::pp_pragma_sysheader_in_main_file && LangOpts.IsHeaderFile)
917906
return true;
918907

919-
if (const char *CodePtr = getDiagnosticCode(Diag.getID())) {
908+
if (const char *CodePtr = getDiagnosticCode(ID)) {
920909
if (Suppress.contains(normalizeSuppressedCode(CodePtr)))
921910
return true;
922911
}
923-
StringRef Warning =
924-
Diag.getDiags()->getDiagnosticIDs()->getWarningOptionForDiag(
925-
Diag.getID());
912+
StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(ID);
926913
if (!Warning.empty() && Suppress.contains(Warning))
927914
return true;
928915
return false;

clang-tools-extra/clangd/Diagnostics.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ class StoreDiags : public DiagnosticConsumer {
181181
};
182182

183183
/// Determine whether a (non-clang-tidy) diagnostic is suppressed by config.
184-
bool isDiagnosticSuppressed(const clang::Diagnostic &Diag,
185-
const llvm::StringSet<> &Suppressed,
186-
const LangOptions &);
184+
bool isBuiltinDiagnosticSuppressed(unsigned ID,
185+
const llvm::StringSet<> &Suppressed,
186+
const LangOptions &);
187187
/// Take a user-specified diagnostic code, and convert it to a normalized form
188-
/// stored in the config and consumed by isDiagnosticsSuppressed.
188+
/// stored in the config and consumed by isBuiltinDiagnosticsSuppressed.
189189
///
190190
/// (This strips err_ and -W prefix so we can match with or without them.)
191191
llvm::StringRef normalizeSuppressedCode(llvm::StringRef);

clang-tools-extra/clangd/ParsedAST.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void applyWarningOptions(llvm::ArrayRef<std::string> ExtraArgs,
340340
if (Enable) {
341341
if (Diags.getDiagnosticLevel(ID, SourceLocation()) <
342342
DiagnosticsEngine::Warning) {
343-
auto Group = Diags.getDiagnosticIDs()->getGroupForDiag(ID);
343+
auto Group = DiagnosticIDs::getGroupForDiag(ID);
344344
if (!Group || !EnabledGroups(*Group))
345345
continue;
346346
Diags.setSeverity(ID, diag::Severity::Warning, SourceLocation());
@@ -583,8 +583,8 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
583583
ASTDiags.setLevelAdjuster([&](DiagnosticsEngine::Level DiagLevel,
584584
const clang::Diagnostic &Info) {
585585
if (Cfg.Diagnostics.SuppressAll ||
586-
isDiagnosticSuppressed(Info, Cfg.Diagnostics.Suppress,
587-
Clang->getLangOpts()))
586+
isBuiltinDiagnosticSuppressed(Info.getID(), Cfg.Diagnostics.Suppress,
587+
Clang->getLangOpts()))
588588
return DiagnosticsEngine::Ignored;
589589

590590
auto It = OverriddenSeverity.find(Info.getID());

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
621621
PreambleDiagnostics.setLevelAdjuster([&](DiagnosticsEngine::Level DiagLevel,
622622
const clang::Diagnostic &Info) {
623623
if (Cfg.Diagnostics.SuppressAll ||
624-
isDiagnosticSuppressed(Info, Cfg.Diagnostics.Suppress,
625-
CI.getLangOpts()))
624+
isBuiltinDiagnosticSuppressed(Info.getID(), Cfg.Diagnostics.Suppress,
625+
CI.getLangOpts()))
626626
return DiagnosticsEngine::Ignored;
627627
switch (Info.getID()) {
628628
case diag::warn_no_newline_eof:

clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -298,41 +298,20 @@ TEST_F(ConfigCompileTests, DiagnosticSuppression) {
298298
"unreachable-code", "unused-variable",
299299
"typecheck_bool_condition",
300300
"unexpected_friend", "warn_alloca"));
301-
clang::DiagnosticsEngine DiagEngine(nullptr, nullptr,
302-
new clang::IgnoringDiagConsumer);
303-
304-
using Diag = clang::Diagnostic;
305-
{
306-
auto D = DiagEngine.Report(diag::warn_unreachable);
307-
EXPECT_TRUE(isDiagnosticSuppressed(
308-
Diag{&DiagEngine}, Conf.Diagnostics.Suppress, LangOptions()));
309-
}
301+
EXPECT_TRUE(isBuiltinDiagnosticSuppressed(
302+
diag::warn_unreachable, Conf.Diagnostics.Suppress, LangOptions()));
310303
// Subcategory not respected/suppressed.
311-
{
312-
auto D = DiagEngine.Report(diag::warn_unreachable_break);
313-
EXPECT_FALSE(isDiagnosticSuppressed(
314-
Diag{&DiagEngine}, Conf.Diagnostics.Suppress, LangOptions()));
315-
}
316-
{
317-
auto D = DiagEngine.Report(diag::warn_unused_variable);
318-
EXPECT_TRUE(isDiagnosticSuppressed(
319-
Diag{&DiagEngine}, Conf.Diagnostics.Suppress, LangOptions()));
320-
}
321-
{
322-
auto D = DiagEngine.Report(diag::err_typecheck_bool_condition);
323-
EXPECT_TRUE(isDiagnosticSuppressed(
324-
Diag{&DiagEngine}, Conf.Diagnostics.Suppress, LangOptions()));
325-
}
326-
{
327-
auto D = DiagEngine.Report(diag::err_unexpected_friend);
328-
EXPECT_TRUE(isDiagnosticSuppressed(
329-
Diag{&DiagEngine}, Conf.Diagnostics.Suppress, LangOptions()));
330-
}
331-
{
332-
auto D = DiagEngine.Report(diag::warn_alloca);
333-
EXPECT_TRUE(isDiagnosticSuppressed(
334-
Diag{&DiagEngine}, Conf.Diagnostics.Suppress, LangOptions()));
335-
}
304+
EXPECT_FALSE(isBuiltinDiagnosticSuppressed(
305+
diag::warn_unreachable_break, Conf.Diagnostics.Suppress, LangOptions()));
306+
EXPECT_TRUE(isBuiltinDiagnosticSuppressed(
307+
diag::warn_unused_variable, Conf.Diagnostics.Suppress, LangOptions()));
308+
EXPECT_TRUE(isBuiltinDiagnosticSuppressed(diag::err_typecheck_bool_condition,
309+
Conf.Diagnostics.Suppress,
310+
LangOptions()));
311+
EXPECT_TRUE(isBuiltinDiagnosticSuppressed(
312+
diag::err_unexpected_friend, Conf.Diagnostics.Suppress, LangOptions()));
313+
EXPECT_TRUE(isBuiltinDiagnosticSuppressed(
314+
diag::warn_alloca, Conf.Diagnostics.Suppress, LangOptions()));
336315

337316
Frag.Diagnostics.Suppress.emplace_back("*");
338317
EXPECT_TRUE(compileAndApply());

clang/include/clang/Basic/Attr.td

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,16 +3358,18 @@ def DiagnoseIf : InheritableAttr {
33583358
let Spellings = [GNU<"diagnose_if">];
33593359
let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
33603360
let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
3361-
EnumArgument<"DefaultSeverity",
3362-
"DefaultSeverity",
3361+
EnumArgument<"DiagnosticType", "DiagnosticType",
33633362
/*is_string=*/true,
3364-
["error", "warning"],
3365-
["DS_error", "DS_warning"]>,
3366-
StringArgument<"WarningGroup", /*optional*/ 1>,
3363+
["error", "warning"],
3364+
["DT_Error", "DT_Warning"]>,
33673365
BoolArgument<"ArgDependent", 0, /*fake*/ 1>,
33683366
DeclArgument<Named, "Parent", 0, /*fake*/ 1>];
33693367
let InheritEvenIfAlreadyPresent = 1;
33703368
let LateParsed = LateAttrParseStandard;
3369+
let AdditionalMembers = [{
3370+
bool isError() const { return diagnosticType == DT_Error; }
3371+
bool isWarning() const { return diagnosticType == DT_Warning; }
3372+
}];
33713373
let TemplateDependent = 1;
33723374
let Documentation = [DiagnoseIfDocs];
33733375
}

clang/include/clang/Basic/Diagnostic.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,10 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
336336
// Map extensions to warnings or errors?
337337
diag::Severity ExtBehavior = diag::Severity::Ignored;
338338

339-
DiagnosticIDs &DiagIDs;
340-
341-
DiagState(DiagnosticIDs &DiagIDs)
339+
DiagState()
342340
: IgnoreAllWarnings(false), EnableAllWarnings(false),
343341
WarningsAsErrors(false), ErrorsAsFatal(false),
344-
SuppressSystemWarnings(false), DiagIDs(DiagIDs) {}
342+
SuppressSystemWarnings(false) {}
345343

346344
using iterator = llvm::DenseMap<unsigned, DiagnosticMapping>::iterator;
347345
using const_iterator =
@@ -872,8 +870,6 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
872870
/// \param FormatString A fixed diagnostic format string that will be hashed
873871
/// and mapped to a unique DiagID.
874872
template <unsigned N>
875-
// TODO: Deprecate this once all uses are removed from LLVM
876-
// [[deprecated("Use a CustomDiagDesc instead of a Level")]]
877873
unsigned getCustomDiagID(Level L, const char (&FormatString)[N]) {
878874
return Diags->getCustomDiagID((DiagnosticIDs::Level)L,
879875
StringRef(FormatString, N - 1));

clang/include/clang/Basic/DiagnosticCategories.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ namespace clang {
2121
};
2222

2323
enum class Group {
24-
#define DIAG_ENTRY(GroupName, FlagNameOffset, Members, SubGroups, Docs) \
25-
GroupName,
24+
#define DIAG_ENTRY(GroupName, FlagNameOffset, Members, SubGroups, Docs) \
25+
GroupName,
2626
#include "clang/Basic/DiagnosticGroups.inc"
2727
#undef CATEGORY
2828
#undef DIAG_ENTRY
29-
NUM_GROUPS
3029
};
3130
} // end namespace diag
3231
} // end namespace clang

0 commit comments

Comments
 (0)