https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/209694
>From 89a68cd24f9fabf15897d7b20b77bb5b0bfb9c16 Mon Sep 17 00:00:00 2001 From: Anonmiraj <[email protected]> Date: Wed, 15 Jul 2026 06:44:23 +0300 Subject: [PATCH 1/2] Do not compute typo-correction suggestions for disabled diagnostics --- clang/lib/Lex/PPDirectives.cpp | 15 +++++++++++++++ clang/lib/Sema/SemaDeclAttr.cpp | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index eb21a510dcf83..418f450ba470b 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -515,6 +515,21 @@ void Preprocessor::SuggestTypoedDirective(const Token &Tok, // directives. if (getLangOpts().AsmPreprocessor) return; + // A known non-conditional directive (e.g. #include or #define inside a + // skipped conditional block) is not a typo of a conditional don't scan + // it. #elifdef/#elifndef stay eligible so that pre-C23/C++23 code still + // gets the "did you mean #elif" suggestion. + if (tok::PPKeywordKind K = getIdentifierInfo(Directive)->getPPKeywordID(); + K != tok::pp_not_keyword && K != tok::pp_elifdef && + K != tok::pp_elifndef) + return; + + // The scan only feeds this diagnostic; skip it when the diagnostic is + // disabled at this location (e.g. -w). + if (getDiagnostics().isIgnored(diag::warn_pp_invalid_directive, + Tok.getLocation())) + return; + std::vector<StringRef> Candidates = { "if", "ifdef", "ifndef", "elif", "else", "endif" }; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 2159c586e5738..f781dc489ed2b 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -8637,6 +8637,12 @@ void Sema::checkUnusedDeclAttributes(Declarator &D) { void Sema::DiagnoseUnknownAttribute(const ParsedAttr &AL) { SourceRange NR = AL.getNormalizedRange(); + // Skip the expensive spelling-list typo-correction scan when the + // diagnostics it feeds are disabled at this location. + if (Diags.isIgnored(diag::warn_unknown_attribute_ignored, NR.getBegin()) && + Diags.isIgnored(diag::warn_unknown_attribute_ignored_suggestion, + NR.getBegin())) + return; StringRef ScopeName = AL.getNormalizedScopeName(); std::optional<StringRef> CorrectedScopeName = AL.tryGetCorrectedScopeName(ScopeName); >From fd7a20179d9455d771fec81d0364c3fc472718b4 Mon Sep 17 00:00:00 2001 From: Anonmiraj <[email protected]> Date: Wed, 15 Jul 2026 10:53:16 +0300 Subject: [PATCH 2/2] fix formatting --- clang/lib/Lex/PPDirectives.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 418f450ba470b..43805a91cf9d8 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -520,8 +520,7 @@ void Preprocessor::SuggestTypoedDirective(const Token &Tok, // it. #elifdef/#elifndef stay eligible so that pre-C23/C++23 code still // gets the "did you mean #elif" suggestion. if (tok::PPKeywordKind K = getIdentifierInfo(Directive)->getPPKeywordID(); - K != tok::pp_not_keyword && K != tok::pp_elifdef && - K != tok::pp_elifndef) + K != tok::pp_not_keyword && K != tok::pp_elifdef && K != tok::pp_elifndef) return; // The scan only feeds this diagnostic; skip it when the diagnostic is _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
