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 {};


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 {};
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to