Skip to content

Commit b7b6466

Browse files
authored
Merge pull request #11088 from benlangmuir/includetreebuilder-crash-on-invalid-20240723
🍒[stable/20240723][clang][cas] Fix crash on invalid with IncludeTreeBuilder
2 parents 72027ec + 2d93e2a commit b7b6466

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
@@ -386,6 +386,13 @@ Error IncludeTreeActionController::finalizeModuleBuild(
386386
ModuleScanInstance.getInvocation().getLangOpts(),
387387
ModuleScanInstance.getInvocation().getCodeGenOpts());
388388
auto Builder = BuilderStack.pop_back_val();
389+
390+
// If there was an error, bail out early. The state of `Builder` may be
391+
// inconsistent since there is no guarantee that exitedInclude or
392+
// finalizeModuleBuild have been called for all imports.
393+
if (ModuleScanInstance.getDiagnostics().hasUnrecoverableErrorOccurred())
394+
return Error::success(); // Already reported.
395+
389396
auto Tree = Builder->finishIncludeTree(ModuleScanInstance,
390397
ModuleScanInstance.getInvocation());
391398
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)