llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Anonmiraj (AnonMiraj)

<details>
<summary>Changes</summary>

While benchmarking I noticed that Boost.MPL compiles with ~1.2% more 
instructions
after #<!-- -->140629.
clang spends a fair amount of time computing typo-correction
suggestions for diagnostics that are never emitted, for example Boost doesn't 
contain any
typos, so all of this work produces nothing.

We can easily avoid this overhead by checking `isIgnored()` before computing
suggestions, and by not treating known non-conditional directives as typos.

You can see the improvement here:
https://llvm-compile-time-tracker.com/compare.php?from=49de424f45389cb757c3cc8c50daf38d024e2314&amp;to=89a68cd24f9fabf15897d7b20b77bb5b0bfb9c16&amp;stat=instructions%3Au


---
Full diff: https://github.com/llvm/llvm-project/pull/209694.diff


2 Files Affected:

- (modified) clang/lib/Lex/PPDirectives.cpp (+15) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+6) 


``````````diff
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);

``````````

</details>


https://github.com/llvm/llvm-project/pull/209694
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to