Skip to content

[clang][cas] Fix crash on invalid with IncludeTreeBuilder #11075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,13 @@ Error IncludeTreeActionController::finalizeModuleBuild(
ModuleScanInstance.getInvocation().getLangOpts(),
ModuleScanInstance.getInvocation().getCodeGenOpts());
auto Builder = BuilderStack.pop_back_val();

// If there was an error, bail out early. The state of `Builder` may be
// inconsistent since there is no guarantee that exitedInclude or
// finalizeModuleBuild have been called for all imports.
if (ModuleScanInstance.getDiagnostics().hasUnrecoverableErrorOccurred())
return Error::success(); // Already reported.

auto Tree = Builder->finishIncludeTree(ModuleScanInstance,
ModuleScanInstance.getInvocation());
if (!Tree)
Expand Down
28 changes: 28 additions & 0 deletions clang/test/ClangScanDeps/modules-include-tree-missing-header.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Tests that a missing header in a module that is itself imported by another
// module does not crash/assert in the IncludeTreeBuilder.

// RUN: rm -rf %t
// RUN: split-file %s %t

// 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
// 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

//--- module.modulemap
module MissingH {
header "missing.h"
}

module Importer {
header "importer.h"
}

//--- not-missing.h

//--- importer.h
@import MissingH;

//--- tu0.m
@import MissingH;

//--- tu1.m
@import Importer;