Revert "Fix crash from accessing a Check::Context during lowering (#7335)" (#7353)

This reverts commit afd679129d.

The commit introduced ASAN errors:

https://github.com/carbon-language/carbon-lang/actions/runs/27436787960/job/81100665405
This commit is contained in:
Nicholas Bishop
2026-06-12 23:04:50 +00:00
committed by GitHub
parent 250da35c3b
commit 40d2d8f68c
14 changed files with 169 additions and 495 deletions
-19
View File
@@ -5,7 +5,6 @@
#include "toolchain/lower/context.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Sema/MultiplexExternalSemaSource.h"
#include "common/check.h"
#include "common/growing_range.h"
#include "common/raw_string_ostream.h"
@@ -13,7 +12,6 @@
#include "llvm/Transforms/Utils/ModuleUtils.h"
#include "toolchain/lower/file_context.h"
#include "toolchain/sem_ir/inst_namer.h"
#include "toolchain/sem_ir/read_only_ast_source.h"
namespace Carbon::Lower {
@@ -72,23 +70,6 @@ auto Context::Finalize() && -> std::unique_ptr<llvm::Module> {
for (auto& file_context : file_contexts_.values()) {
if (file_context) {
if (file_context->cpp_file()) {
// Remove the `CarbonExternalASTSource` installed during check
// (always the last child of the multiplex source) and replace
// it with a `ReadOnlyASTSource`. This is necessary because the
// original source has a now-invalid pointer to a
// `Check::Context`.
auto& ast = const_cast<clang::ASTContext&>(
file_context->cpp_file()->ast_context());
auto* multiplex_source =
cast<clang::MultiplexExternalSemaSource>(ast.getExternalSource());
auto& child_sources = multiplex_source->GetSources();
child_sources.pop_back();
multiplex_source->AddSource(
llvm::makeIntrusiveRefCnt<SemIR::ReadOnlyASTSource>(
file_context->sem_ir()));
}
file_context->Finalize();
}
}