diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -22,6 +22,9 @@ // 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 @@ 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 --- /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 --- /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 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 diff --git a/clang/test/ClangScanDeps/Inputs/removed-args/module.modulemap b/clang/test/ClangScanDeps/Inputs/removed-args/module.modulemap new file mode 100644 --- /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 --- /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 --- /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: }