[clang-tools-extra] 67e94c9 - [include-cleaner] Ignore the layering-violation errors for the standalone tool

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 5 04:33:47 PDT 2023


Author: Haojian Wu
Date: 2023-07-05T13:30:26+02:00
New Revision: 67e94c9dc8ff7ac49f2557e02fdf375edd850d76

URL: https://github.com/llvm/llvm-project/commit/67e94c9dc8ff7ac49f2557e02fdf375edd850d76
DIFF: https://github.com/llvm/llvm-project/commit/67e94c9dc8ff7ac49f2557e02fdf375edd850d76.diff

LOG: [include-cleaner] Ignore the layering-violation errors for the standalone tool

If the source code is compilable-but-layering-violation, we still want
the tool to be functional on it (rather than bailing out).

Differential Revision: https://reviews.llvm.org/D154477

Added: 
    clang-tools-extra/include-cleaner/test/Inputs/modules/a.h
    clang-tools-extra/include-cleaner/test/Inputs/modules/module.map
    clang-tools-extra/include-cleaner/test/module.cpp

Modified: 
    clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/include-cleaner/test/Inputs/modules/a.h b/clang-tools-extra/include-cleaner/test/Inputs/modules/a.h
new file mode 100644
index 00000000000000..0b502e27d342bb
--- /dev/null
+++ b/clang-tools-extra/include-cleaner/test/Inputs/modules/a.h
@@ -0,0 +1,2 @@
+#pragma once
+class A {};

diff  --git a/clang-tools-extra/include-cleaner/test/Inputs/modules/module.map b/clang-tools-extra/include-cleaner/test/Inputs/modules/module.map
new file mode 100644
index 00000000000000..510bfdbd1d83be
--- /dev/null
+++ b/clang-tools-extra/include-cleaner/test/Inputs/modules/module.map
@@ -0,0 +1,2 @@
+module XA {
+}

diff  --git a/clang-tools-extra/include-cleaner/test/module.cpp b/clang-tools-extra/include-cleaner/test/module.cpp
new file mode 100644
index 00000000000000..b344d16eefdf20
--- /dev/null
+++ b/clang-tools-extra/include-cleaner/test/module.cpp
@@ -0,0 +1,7 @@
+// RUN: cp %s %t.cpp
+// RUN: clang-include-cleaner -edit %t.cpp -- -I%S/Inputs/modules -fimplicit-module-maps -fmodules-strict-decluse -fmodule-name=XA
+// RUN: FileCheck --match-full-lines --check-prefix=EDIT %s < %t.cpp
+
+// Verify the tool still works on compilable-but-layering-violation code.
+#include "a.h"
+// EDIT-NOT: {{^}}#include "a.h"{{$}}

diff  --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
index 574023fda4968f..62febb488531af 100644
--- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -95,6 +95,15 @@ class Action : public clang::ASTFrontendAction {
   RecordedPP PP;
   PragmaIncludes PI;
 
+  bool BeginInvocation(CompilerInstance &CI) override {
+    // We only perform include-cleaner analysis. So we disable diagnostics that
+    // won't affect our analysis to make the tool more robust against
+    // in-development code.
+    CI.getLangOpts().ModulesDeclUse = false;
+    CI.getLangOpts().ModulesStrictDeclUse = false;
+    return true;
+  }
+
   void ExecuteAction() override {
     auto &P = getCompilerInstance().getPreprocessor();
     P.addPPCallbacks(PP.record(P));


        


More information about the cfe-commits mailing list