[clang] [clang][-Wunsafe-buffer-usage] Cache the analysis gate per diagnostic state (PR #240433)
Ilyas Mallah via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 9 12:58:29 PST 2026
================
@@ -3116,6 +3118,25 @@ static bool shouldRunUnsafeBufferUsageAnalysis(const Sema &S,
!Diags.isIgnored(diag::warn_unsafe_buffer_format_attr_call, Loc)));
}
+// This runs at the end of every function definition, so the answer is cached
+// on the diagnostic state at Loc like getPolicyInEffectAt().
+bool sema::AnalysisBasedWarnings::shouldRunUnsafeBufferUsageAnalysis(
+ SourceLocation Loc) {
+ DiagnosticsEngine &D = S.getDiagnostics();
+ if (D.hasDiagSuppressionMapping() || Loc.isInvalid())
+ return isUnsafeBufferUsageAnalysisEnabledAt(S, Loc);
+
+ const void *StateKey = D.getDiagStateKeyForLoc(Loc);
+ auto &Cache = UnsafeBufferUsageCache[static_cast<unsigned>(
+ D.getDiagStateSystemClassForLoc(Loc))];
+ auto It = Cache.find(StateKey);
+ if (It != Cache.end())
+ return It->second;
+ bool Enabled = isUnsafeBufferUsageAnalysisEnabledAt(S, Loc);
+ Cache[StateKey] = Enabled;
+ return Enabled;
----------------
ilyas-mallah wrote:
Done!
https://github.com/llvm/llvm-project/pull/240433
More information about the cfe-commits
mailing list