Skip to content

Commit 3e11b20

Browse files
committed
[clang][cas] Allow non-existent fmodule-name
Missing the module named by fmodule-name is not an error for a TU or PCH. (cherry picked from commit fcd06ba)
1 parent 0b727cd commit 3e11b20

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

clang/lib/Tooling/DependencyScanning/IncludeTreeActionController.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -640,13 +640,11 @@ IncludeTreeBuilder::finishIncludeTree(CompilerInstance &ScanInstance,
640640
// that case we need both of those modules.
641641
ModuleMap &MMap =
642642
ScanInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap();
643-
M = MMap.findModule(ScanInstance.getLangOpts().CurrentModule);
644-
assert(M && "missing current module?");
645-
if (Error E = AddModule(M))
646-
return std::move(E);
647-
Module *PM =
648-
MMap.findModule(ScanInstance.getLangOpts().ModuleName + "_Private");
649-
if (PM)
643+
if (Module *M = MMap.findModule(ScanInstance.getLangOpts().CurrentModule))
644+
if (Error E = AddModule(M))
645+
return std::move(E);
646+
if (Module *PM =
647+
MMap.findModule(ScanInstance.getLangOpts().ModuleName + "_Private"))
650648
if (Error E = AddModule(PM))
651649
return std::move(E);
652650
}

clang/test/ClangScanDeps/modules-include-tree-implementation.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: split-file %s %t
55
// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
66

7-
// RUN: clang-scan-deps -compilation-database %t/cdb.json \
7+
// RUN: clang-scan-deps -compilation-database %t/cdb.json -j 1 \
88
// RUN: -cas-path %t/cas -module-files-dir %t/outputs \
99
// RUN: -format experimental-include-tree-full -mode preprocess-dependency-directives \
1010
// RUN: > %t/deps.json
@@ -35,12 +35,22 @@
3535
// CHECK: [[PREFIX]]/Mod.h llvmcas://{{[[:xdigit:]]+}}
3636
// CHECK-NOT: [[PREFIX]]/module.modulemap
3737

38+
// RUN: %deps-to-rsp %t/deps.json --tu-index 1 > %t/tu_missing_module.rsp
39+
// RUN: %clang @%t/tu_missing_module.rsp
40+
3841
//--- cdb.json.template
39-
[{
42+
[
43+
{
4044
"file": "DIR/tu.c",
4145
"directory": "DIR",
4246
"command": "clang -fsyntax-only DIR/tu.c -I DIR -fmodule-name=Mod -fmodules -fimplicit-modules -fimplicit-module-maps -fmodules-cache-path=DIR/module-cache"
43-
}]
47+
},
48+
{
49+
"file": "DIR/tu_missing_module.c",
50+
"directory": "DIR",
51+
"command": "clang -fsyntax-only DIR/tu_missing_module.c -I DIR -fmodule-name=NonExistent -fmodules -fimplicit-modules -fimplicit-module-maps -fmodules-cache-path=DIR/module-cache"
52+
}
53+
]
4454

4555
//--- module.modulemap
4656
module Mod { header "Mod.h" }
@@ -55,3 +65,6 @@ void top(void);
5565
void tu(void) {
5666
top();
5767
}
68+
69+
//--- tu_missing_module.c
70+

0 commit comments

Comments
 (0)