Skip to content

Commit 4feb466

Browse files
authored
Merge pull request #11075 from benlangmuir/includetreebuilder-crash-on-invalid
[clang][cas] Fix crash on invalid with IncludeTreeBuilder
2 parents 096dd67 + 5d380b9 commit 4feb466

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

clang/lib/Tooling/DependencyScanning/IncludeTreeActionController.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,13 @@ Error IncludeTreeActionController::finalizeModuleBuild(
425425
ModuleScanInstance.getInvocation().getLangOpts(),
426426
ModuleScanInstance.getInvocation().getCodeGenOpts());
427427
auto Builder = BuilderStack.pop_back_val();
428+
429+
// If there was an error, bail out early. The state of `Builder` may be
430+
// inconsistent since there is no guarantee that exitedInclude or
431+
// finalizeModuleBuild have been called for all imports.
432+
if (ModuleScanInstance.getDiagnostics().hasUnrecoverableErrorOccurred())
433+
return Error::success(); // Already reported.
434+
428435
auto Tree = Builder->finishIncludeTree(ModuleScanInstance,
429436
ModuleScanInstance.getInvocation());
430437
if (!Tree)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Tests that a missing header in a module that is itself imported by another
2+
// module does not crash/assert in the IncludeTreeBuilder.
3+
4+
// RUN: rm -rf %t
5+
// RUN: split-file %s %t
6+
7+
// RUN: not clang-scan-deps -format experimental-include-tree-full -cas-path %t/cas -- %clang -fmodules -fmodules-cache-path=%t/cache -c %t/tu0.m -I%t
8+
// RUN: not clang-scan-deps -format experimental-include-tree-full -cas-path %t/cas -- %clang -fmodules -fmodules-cache-path=%t/cache -c %t/tu1.m -I%t
9+
10+
//--- module.modulemap
11+
module MissingH {
12+
header "missing.h"
13+
}
14+
15+
module Importer {
16+
header "importer.h"
17+
}
18+
19+
//--- not-missing.h
20+
21+
//--- importer.h
22+
@import MissingH;
23+
24+
//--- tu0.m
25+
@import MissingH;
26+
27+
//--- tu1.m
28+
@import Importer;

0 commit comments

Comments
 (0)