[clang] [SafeBuffers] Check if unsafe-buffers* warnings are enabled earlier (PR #128603)

kadir çetinkaya via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 25 07:47:21 PST 2025


================
@@ -2625,14 +2636,10 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
 
     // More analysis ...
   };
+
   // Emit per-function analysis-based warnings that require the whole-TU
-  // reasoning. Check if any of them is enabled at all before scanning the AST:
-  if (!Diags.isIgnored(diag::warn_unsafe_buffer_operation, SourceLocation()) ||
-      !Diags.isIgnored(diag::warn_unsafe_buffer_variable, SourceLocation()) ||
-      !Diags.isIgnored(diag::warn_unsafe_buffer_usage_in_container,
-                       SourceLocation()) ||
-      (!Diags.isIgnored(diag::warn_unsafe_buffer_libc_call, SourceLocation()) &&
-       S.getLangOpts().CPlusPlus /* only warn about libc calls in C++ */)) {
+  // reasoning.
+  if (DefaultPolicy.enableUnsafeBufferUsage) {
----------------
kadircet wrote:

i know this is going to sound ugly, but by preserving the enabled-ness check here, in addition to doing it in the beginning ensures we won't regress behavior.
leaving a fixme, similar to the one in the test file below should be good enough.

https://github.com/llvm/llvm-project/pull/128603


More information about the cfe-commits mailing list