[clang] 6da811f - [clang][deps] Reset non-modular language and preprocessor options

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 25 23:43:28 PDT 2021


Author: Jan Svoboda
Date: 2021-08-26T08:43:21+02:00
New Revision: 6da811fd5c7158eecaf25f0e417131f2e7dfb35f

URL: https://github.com/llvm/llvm-project/commit/6da811fd5c7158eecaf25f0e417131f2e7dfb35f
DIFF: https://github.com/llvm/llvm-project/commit/6da811fd5c7158eecaf25f0e417131f2e7dfb35f.diff

LOG: [clang][deps] Reset non-modular language and preprocessor options

There are a number of language and preprocessor options that are reset in the `CompilerInvocation` that describes the build of an implicit module. This patch uses the logic for explicit modules as well.

Reviewed By: dexonsmith

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

Added: 
    clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
    clang/test/ClangScanDeps/Inputs/removed-args/header.h
    clang/test/ClangScanDeps/Inputs/removed-args/mod_header.h
    clang/test/ClangScanDeps/Inputs/removed-args/mod_tu.h
    clang/test/ClangScanDeps/Inputs/removed-args/module.modulemap
    clang/test/ClangScanDeps/Inputs/removed-args/tu.c
    clang/test/ClangScanDeps/removed-args.c

Modified: 
    clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 66f8d97e246e..1e23ad945c83 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -22,6 +22,9 @@ CompilerInvocation ModuleDepCollector::makeInvocationForModuleBuildWithoutPaths(
   // Make a deep copy of the original Clang invocation.
   CompilerInvocation CI(OriginalInvocation);
 
+  CI.getLangOpts()->resetNonModularOptions();
+  CI.getPreprocessorOpts().resetNonModularOptions();
+
   // Remove options incompatible with explicit module build.
   CI.getFrontendOpts().Inputs.clear();
   CI.getFrontendOpts().OutputFile.clear();
@@ -38,8 +41,6 @@ CompilerInvocation ModuleDepCollector::makeInvocationForModuleBuildWithoutPaths(
     CI.getFrontendOpts().ModuleMapFiles.push_back(PrebuiltModule.ModuleMapFile);
   }
 
-  CI.getPreprocessorOpts().ImplicitPCHInclude.clear();
-
   return CI;
 }
 

diff  --git a/clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template b/clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
new file mode 100644
index 000000000000..116e14c92081
--- /dev/null
+++ b/clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template
@@ -0,0 +1,7 @@
+[
+  {
+    "directory": "DIR",
+    "command": "clang -fsyntax-only DIR/tu.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -include DIR/header.h -o DIR/tu.o",
+    "file": "DIR/tu.c"
+  }
+]

diff  --git a/clang/test/ClangScanDeps/Inputs/removed-args/header.h b/clang/test/ClangScanDeps/Inputs/removed-args/header.h
new file mode 100644
index 000000000000..2961518e3504
--- /dev/null
+++ b/clang/test/ClangScanDeps/Inputs/removed-args/header.h
@@ -0,0 +1 @@
+#include "mod_header.h"

diff  --git a/clang/test/ClangScanDeps/Inputs/removed-args/mod_header.h b/clang/test/ClangScanDeps/Inputs/removed-args/mod_header.h
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/clang/test/ClangScanDeps/Inputs/removed-args/mod_tu.h b/clang/test/ClangScanDeps/Inputs/removed-args/mod_tu.h
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/clang/test/ClangScanDeps/Inputs/removed-args/module.modulemap b/clang/test/ClangScanDeps/Inputs/removed-args/module.modulemap
new file mode 100644
index 000000000000..80ec22223134
--- /dev/null
+++ b/clang/test/ClangScanDeps/Inputs/removed-args/module.modulemap
@@ -0,0 +1,2 @@
+module ModHeader { header "mod_header.h" }
+module ModTU     { header "mod_tu.h"     }

diff  --git a/clang/test/ClangScanDeps/Inputs/removed-args/tu.c b/clang/test/ClangScanDeps/Inputs/removed-args/tu.c
new file mode 100644
index 000000000000..085d398a5ab9
--- /dev/null
+++ b/clang/test/ClangScanDeps/Inputs/removed-args/tu.c
@@ -0,0 +1 @@
+#include "mod_tu.h"

diff  --git a/clang/test/ClangScanDeps/removed-args.c b/clang/test/ClangScanDeps/removed-args.c
new file mode 100644
index 000000000000..f47f01cc0387
--- /dev/null
+++ b/clang/test/ClangScanDeps/removed-args.c
@@ -0,0 +1,60 @@
+// Some command-line arguments used for compiling translation units are not
+// compatible with the semantics of modules and should be removed. In this test
+// case, the command-lines for modules should drop the '-include' argument.
+
+// RUN: rm -rf %t && mkdir %t
+// RUN: cp %S/Inputs/removed-args/* %t
+
+// RUN: sed "s|DIR|%/t|g" %S/Inputs/removed-args/cdb.json.template > %t/cdb.json
+// RUN: echo -%t > %t/result.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full >> %t/result.json
+// RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s
+//
+// CHECK:      -[[PREFIX:.*]]
+// CHECK-NEXT: {
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT:     {
+// CHECK-NEXT:       "clang-module-deps": [],
+// CHECK-NEXT:       "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:       "command-line": [
+// CHECK-NEXT:         "-cc1"
+// CHECK-NOT:          "-include"
+// CHECK:            ],
+// CHECK-NEXT:       "context-hash": "[[HASH_MOD_HEADER:.*]]",
+// CHECK-NEXT:       "file-deps": [
+// CHECK-NEXT:         "[[PREFIX]]/mod_header.h",
+// CHECK-NEXT:         "[[PREFIX]]/module.modulemap"
+// CHECK-NEXT:       ],
+// CHECK-NEXT:       "name": "ModHeader"
+// CHECK-NEXT:     },
+// CHECK-NEXT:     {
+// CHECK-NEXT:       "clang-module-deps": [],
+// CHECK-NEXT:       "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:       "command-line": [
+// CHECK-NEXT:         "-cc1"
+// CHECK-NOT:          "-include"
+// CHECK:            ],
+// CHECK-NEXT:       "context-hash": "[[HASH_MOD_TU:.*]]",
+// CHECK-NEXT:       "file-deps": [
+// CHECK-NEXT:         "[[PREFIX]]/mod_tu.h",
+// CHECK-NEXT:         "[[PREFIX]]/module.modulemap"
+// CHECK-NEXT:       ],
+// CHECK-NEXT:       "name": "ModTU"
+// CHECK-NEXT:     }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "translation-units": [
+// CHECK-NEXT:     {
+// CHECK-NEXT:       "clang-context-hash": "[[HASH_TU:.*]]",
+// CHECK-NEXT:       "clang-module-deps": [
+// CHECK-NEXT:         {
+// CHECK-NEXT:           "context-hash": "[[HASH_MOD_HEADER]]",
+// CHECK-NEXT:           "module-name": "ModHeader"
+// CHECK-NEXT:         },
+// CHECK-NEXT:         {
+// CHECK-NEXT:           "context-hash": "[[HASH_MOD_TU]]",
+// CHECK-NEXT:           "module-name": "ModTU"
+// CHECK-NEXT:         }
+// CHECK-NEXT:       ]
+// CHECK:          }
+// CHECK-NEXT:   ]
+// CHECK-NEXT: }


        


More information about the cfe-commits mailing list