Skip to content

Commit 41a148d

Browse files
committed
[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
1 parent f422920 commit 41a148d

File tree

8 files changed

+74
-2
lines changed

8 files changed

+74
-2
lines changed

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ CompilerInvocation ModuleDepCollector::makeInvocationForModuleBuildWithoutPaths(
2323
// Make a deep copy of the original Clang invocation.
2424
CompilerInvocation CI(OriginalInvocation);
2525

26+
CI.getLangOpts()->resetNonModularOptions();
27+
CI.getPreprocessorOpts().resetNonModularOptions();
28+
2629
// Remove options incompatible with explicit module build.
2730
CI.getFrontendOpts().Inputs.clear();
2831
CI.getFrontendOpts().OutputFile.clear();
@@ -39,8 +42,6 @@ CompilerInvocation ModuleDepCollector::makeInvocationForModuleBuildWithoutPaths(
3942
CI.getFrontendOpts().ModuleMapFiles.push_back(PrebuiltModule.ModuleMapFile);
4043
}
4144

42-
CI.getPreprocessorOpts().ImplicitPCHInclude.clear();
43-
4445
return CI;
4546
}
4647

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"directory": "DIR",
4+
"command": "clang -fsyntax-only DIR/tu.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -include DIR/header.h -o DIR/tu.o",
5+
"file": "DIR/tu.c"
6+
}
7+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "mod_header.h"

clang/test/ClangScanDeps/Inputs/removed-args/mod_header.h

Whitespace-only changes.

clang/test/ClangScanDeps/Inputs/removed-args/mod_tu.h

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module ModHeader { header "mod_header.h" }
2+
module ModTU { header "mod_tu.h" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "mod_tu.h"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Some command-line arguments used for compiling translation units are not
2+
// compatible with the semantics of modules and should be removed. In this test
3+
// case, the command-lines for modules should drop the '-include' argument.
4+
5+
// RUN: rm -rf %t && mkdir %t
6+
// RUN: cp %S/Inputs/removed-args/* %t
7+
8+
// RUN: sed "s|DIR|%/t|g" %S/Inputs/removed-args/cdb.json.template > %t/cdb.json
9+
// RUN: echo -%t > %t/result.json
10+
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full >> %t/result.json
11+
// RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s
12+
//
13+
// CHECK: -[[PREFIX:.*]]
14+
// CHECK-NEXT: {
15+
// CHECK-NEXT: "modules": [
16+
// CHECK-NEXT: {
17+
// CHECK-NEXT: "clang-module-deps": [],
18+
// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
19+
// CHECK-NEXT: "command-line": [
20+
// CHECK-NEXT: "-cc1"
21+
// CHECK-NOT: "-include"
22+
// CHECK: ],
23+
// CHECK-NEXT: "context-hash": "[[HASH_MOD_HEADER:.*]]",
24+
// CHECK-NEXT: "file-deps": [
25+
// CHECK-NEXT: "[[PREFIX]]/mod_header.h",
26+
// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
27+
// CHECK-NEXT: ],
28+
// CHECK-NEXT: "name": "ModHeader"
29+
// CHECK-NEXT: },
30+
// CHECK-NEXT: {
31+
// CHECK-NEXT: "clang-module-deps": [],
32+
// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
33+
// CHECK-NEXT: "command-line": [
34+
// CHECK-NEXT: "-cc1"
35+
// CHECK-NOT: "-include"
36+
// CHECK: ],
37+
// CHECK-NEXT: "context-hash": "[[HASH_MOD_TU:.*]]",
38+
// CHECK-NEXT: "file-deps": [
39+
// CHECK-NEXT: "[[PREFIX]]/mod_tu.h",
40+
// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
41+
// CHECK-NEXT: ],
42+
// CHECK-NEXT: "name": "ModTU"
43+
// CHECK-NEXT: }
44+
// CHECK-NEXT: ],
45+
// CHECK-NEXT: "translation-units": [
46+
// CHECK-NEXT: {
47+
// CHECK-NEXT: "clang-context-hash": "[[HASH_TU:.*]]",
48+
// CHECK-NEXT: "clang-module-deps": [
49+
// CHECK-NEXT: {
50+
// CHECK-NEXT: "context-hash": "[[HASH_MOD_HEADER]]",
51+
// CHECK-NEXT: "module-name": "ModHeader"
52+
// CHECK-NEXT: },
53+
// CHECK-NEXT: {
54+
// CHECK-NEXT: "context-hash": "[[HASH_MOD_TU]]",
55+
// CHECK-NEXT: "module-name": "ModTU"
56+
// CHECK-NEXT: }
57+
// CHECK-NEXT: ]
58+
// CHECK: }
59+
// CHECK-NEXT: ]
60+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)