diff --git a/toolchain/driver/driver.cpp b/toolchain/driver/driver.cpp index 70f17d4874b7..3ab0e7e5993f 100644 --- a/toolchain/driver/driver.cpp +++ b/toolchain/driver/driver.cpp @@ -422,6 +422,12 @@ class Driver::CompilationUnit { // Parses tokens. Returns true on success. auto RunParse() -> bool { + // Can be called when the file fails to load, so ensure there's source. + if (!source_) { + return false; + } + CARBON_CHECK(tokens_); + LogCall("Parse::Tree::Parse", [&] { parse_tree_ = Parse::Tree::Parse(*tokens_, *consumer_, vlog_stream_); }); @@ -435,6 +441,12 @@ class Driver::CompilationUnit { // Check the parse tree and produce SemIR. Returns true on success. auto RunCheck(const SemIR::File& builtins) -> bool { + // Can be called when the file fails to load, so ensure there's source. + if (!source_) { + return false; + } + CARBON_CHECK(parse_tree_); + LogCall("Check::CheckParseTree", [&] { sem_ir_ = Check::CheckParseTree(builtins, *tokens_, *parse_tree_, *consumer_, vlog_stream_); @@ -466,6 +478,8 @@ class Driver::CompilationUnit { // Lower SemIR to LLVM IR. auto RunLower() -> void { + CARBON_CHECK(sem_ir_); + LogCall("Lower::LowerToLLVM", [&] { llvm_context_ = std::make_unique(); module_ = Lower::LowerToLLVM(*llvm_context_, input_file_name_, *sem_ir_, @@ -485,6 +499,8 @@ class Driver::CompilationUnit { // Do codegen. Returns true on success. auto RunCodeGen() -> bool { + CARBON_CHECK(module_); + CARBON_VLOG() << "*** CodeGen ***\n"; std::optional codegen = CodeGen::Create(*module_, options_.target, driver_->error_stream_); diff --git a/toolchain/driver/testdata/fail_missing_file.carbon b/toolchain/driver/testdata/fail_missing_file.carbon index 3d87be4cd51d..f526de9ee047 100644 --- a/toolchain/driver/testdata/fail_missing_file.carbon +++ b/toolchain/driver/testdata/fail_missing_file.carbon @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -// ARGS: compile --phase=lex nonexistent.carbon +// ARGS: compile nonexistent.carbon // // AUTOUPDATE // CHECK:STDERR: nonexistent.carbon: Error opening file for read: No such file or directory