[clang] [analyzer] Prevent triplicate warnings for `sarif-html` (PR #158112)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 11 09:39:42 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions c,cpp,h -- clang/lib/StaticAnalyzer/Core/PlistDiagnostics.h clang/lib/StaticAnalyzer/Core/SarifDiagnostics.h clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp clang/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index 4318bce7f..4c9c619f2 100644
--- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -10,6 +10,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "PlistDiagnostics.h"
+#include "SarifDiagnostics.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/Stmt.h"
@@ -36,8 +38,6 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
-#include "PlistDiagnostics.h"
-#include "SarifDiagnostics.h"
 #include <cassert>
 #include <map>
 #include <memory>
@@ -177,14 +177,13 @@ static void createHTMLDiagnosticConsumerImpl(
     PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
     const std::string &OutputDir, const Preprocessor &PP,
     bool SupportMultipleFiles) {
-    
-    // TODO: Emit an error here.
+
+  // TODO: Emit an error here.
   if (OutputDir.empty())
     return;
-    
-  C.emplace_back(std::make_unique<HTMLDiagnostics>(std::move(DiagOpts),
-                                                   OutputDir, PP,
-                                                   SupportMultipleFiles));
+
+  C.emplace_back(std::make_unique<HTMLDiagnostics>(
+      std::move(DiagOpts), OutputDir, PP, SupportMultipleFiles));
 }
 
 void ento::createHTMLDiagnosticConsumer(
@@ -236,7 +235,8 @@ void ento::createSarifHTMLDiagnosticConsumer(
     const cross_tu::CrossTranslationUnitContext &CTU,
     const MacroExpansionContext &MacroExpansions) {
   createHTMLDiagnosticConsumerImpl(
-      DiagOpts, C, std::string(llvm::sys::path::parent_path(sarif_file)), PP, true);
+      DiagOpts, C, std::string(llvm::sys::path::parent_path(sarif_file)), PP,
+      true);
   createSarifDiagnosticConsumerImpl(DiagOpts, C, sarif_file, PP);
 
   createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, sarif_file,
diff --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index b5f292a27..f4b08e265 100644
--- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -10,6 +10,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "PlistDiagnostics.h"
 #include "clang/Analysis/IssueHash.h"
 #include "clang/Analysis/MacroExpansionContext.h"
 #include "clang/Analysis/PathDiagnostic.h"
@@ -24,7 +25,6 @@
 #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
-#include "PlistDiagnostics.h"
 #include <memory>
 #include <optional>
 
@@ -535,16 +535,14 @@ void ento::createPlistDiagnosticConsumerImpl(
     PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
     const std::string &OutputFile, const Preprocessor &PP,
     const cross_tu::CrossTranslationUnitContext &CTU,
-    const MacroExpansionContext &MacroExpansions,
-    bool SupportsMultipleFiles) {
+    const MacroExpansionContext &MacroExpansions, bool SupportsMultipleFiles) {
 
   // TODO: Emit an error here.
   if (OutputFile.empty())
     return;
 
   C.push_back(std::make_unique<PlistDiagnostics>(
-      DiagOpts, OutputFile, PP, CTU, MacroExpansions,
-      SupportsMultipleFiles));
+      DiagOpts, OutputFile, PP, CTU, MacroExpansions, SupportsMultipleFiles));
 }
 
 void ento::createPlistDiagnosticConsumer(
diff --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.h b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.h
index 248daf596..44586ec75 100644
--- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.h
+++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.h
@@ -13,15 +13,12 @@ namespace clang {
 namespace ento {
 
 void createPlistDiagnosticConsumerImpl(
-    PathDiagnosticConsumerOptions DiagOpts,
-    PathDiagnosticConsumers &C,
-    const std::string &Output,
-    const Preprocessor &PP,
+    PathDiagnosticConsumerOptions DiagOpts, PathDiagnosticConsumers &C,
+    const std::string &Output, const Preprocessor &PP,
     const cross_tu::CrossTranslationUnitContext &CTU,
-    const MacroExpansionContext &MacroExpansions,
-    bool SupportsMultipleFiles);
+    const MacroExpansionContext &MacroExpansions, bool SupportsMultipleFiles);
 
-} // end ento namespace
-} // end clang namespace
+} // namespace ento
+} // namespace clang
 
 #endif
diff --git a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
index 87985bf93..d2c46cf00 100644
--- a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
@@ -10,6 +10,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "SarifDiagnostics.h"
 #include "clang/Analysis/MacroExpansionContext.h"
 #include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Basic/Sarif.h"
@@ -20,7 +21,6 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/JSON.h"
-#include "SarifDiagnostics.h"
 #include <memory>
 
 using namespace llvm;
@@ -56,7 +56,7 @@ void ento::createSarifDiagnosticConsumer(
     const MacroExpansionContext &MacroExpansions) {
 
   createSarifDiagnosticConsumerImpl(DiagOpts, C, Output, PP);
-    
+
   createTextMinimalPathDiagnosticConsumer(std::move(DiagOpts), C, Output, PP,
                                           CTU, MacroExpansions);
 }
diff --git a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.h b/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.h
index aa470358c..bfbb995fe 100644
--- a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.h
+++ b/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.h
@@ -12,13 +12,12 @@
 namespace clang {
 namespace ento {
 
-void createSarifDiagnosticConsumerImpl(
-    PathDiagnosticConsumerOptions DiagOpts,
-    PathDiagnosticConsumers &C,
-    const std::string &Output,
-    const Preprocessor &PP);
+void createSarifDiagnosticConsumerImpl(PathDiagnosticConsumerOptions DiagOpts,
+                                       PathDiagnosticConsumers &C,
+                                       const std::string &Output,
+                                       const Preprocessor &PP);
 
-} // end ento namespace
-} // end clang namespace
+} // namespace ento
+} // namespace clang
 
 #endif

``````````

</details>


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


More information about the cfe-commits mailing list