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

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 5 00:32:26 PDT 2023


hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang-tools-extra.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154477

Files:
  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
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp


Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===================================================================
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -95,6 +95,15 @@
   RecordedPP PP;
   PragmaIncludes PI;
 
+  bool BeginInvocation(CompilerInstance &CI) override {
+    // Disable the clang-module-based layering-violation checks.
+    // These checks emit errors for a compilable source code. We want the tool
+    // continue to be functional even on a layering-violation code.
+    CI.getLangOpts().ModulesDeclUse = false;
+    CI.getLangOpts().ModulesStrictDeclUse = false;
+    return true;
+  }
+
   void ExecuteAction() override {
     auto &P = getCompilerInstance().getPreprocessor();
     P.addPPCallbacks(PP.record(P));
Index: clang-tools-extra/include-cleaner/test/module.cpp
===================================================================
--- /dev/null
+++ 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"{{$}}
Index: clang-tools-extra/include-cleaner/test/Inputs/modules/module.map
===================================================================
--- /dev/null
+++ clang-tools-extra/include-cleaner/test/Inputs/modules/module.map
@@ -0,0 +1,2 @@
+module XA {
+}
Index: clang-tools-extra/include-cleaner/test/Inputs/modules/a.h
===================================================================
--- /dev/null
+++ clang-tools-extra/include-cleaner/test/Inputs/modules/a.h
@@ -0,0 +1,2 @@
+#pragma once
+class A {};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154477.537240.patch
Type: text/x-patch
Size: 1913 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230705/50f01acb/attachment-0001.bin>


More information about the cfe-commits mailing list