[clang] [clang] Cache the analysis-based warning policy in effect (PR #212213)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 28 07:56:44 PDT 2026
================
@@ -2761,23 +2759,59 @@ sema::AnalysisBasedWarnings::Policy
sema::AnalysisBasedWarnings::getPolicyInEffectAt(SourceLocation Loc) {
using namespace diag;
DiagnosticsEngine &D = S.getDiagnostics();
+
+ // This runs at the end of every function definition, and the checks below
+ // resolve Loc against the pragma diagnostic state (and system header/macro
+ // classification) once per queried diagnostic. Those inputs fully determine
+ // the result, so cache the policy on them instead (PolicyOverrides are
+ // transient per-function state and are applied after the cache lookup).
+ const bool Cacheable = !D.hasDiagSuppressionMapping();
+ const void *StateKey = nullptr;
+ unsigned SysIdx = 0;
+ if (Cacheable) {
+ StateKey = D.getDiagStateKeyForLoc(Loc);
+ if (Loc.isValid() && D.hasSourceManager()) {
----------------
AnonMiraj wrote:
done
https://github.com/llvm/llvm-project/pull/212213
More information about the cfe-commits
mailing list