[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 04:33:56 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG67e94c9dc8ff: [include-cleaner] Ignore the layering-violation errors for the standalone tool (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D154477?vs=537240&id=537292#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154477/new/

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 {
+    // 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));
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.537292.patch
Type: text/x-patch
Size: 1879 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230705/d37e1443/attachment-0001.bin>


More information about the cfe-commits mailing list