mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 12:31:04 +01:00
Initialize cpp_mangle_context_ in Mangler's constructor (#5095)
This is a followup of [a comment](https://github.com/carbon-language/carbon-lang/pull/5062/files/89e56d51858bcc18d4242d4e5c9ee0e7496d887e#r1979993815) in #5062. Add a mutable AST pointer to `FileContext`. This is necessary since we use [Clang with lack of const correctness](https://github.com/llvm/llvm-project/pull/130096#issuecomment-2704413782). Alternatives in Clang: * Change `ASTUnit::getASTContext() const` to return a non-const `ASTContext`. [Tried and was rejected upstream due to weakening const correctness](https://github.com/llvm/llvm-project/pull/130096). * Change `createMangleContext()` to be `const`. Tried that and it seems like it relies heavily on non const API. * Change `MangleContext::mangleName()` to `const`. Tried that but there are several lazy initialization and id creations happening that modify the context. See details in https://github.com/llvm/llvm-project/pull/130613. Alternatives in Carbon: * Use `const_cast` on `ASTContext` when calling `createMangleContext()`. * Make `FileContext::sem_ir_` point to a mutable `SemIR::File`. * Change `File::cpp_ast()` to be const while keeping it return a mutable pointer. Part of #4666.
This commit is contained in:
@@ -598,9 +598,10 @@ auto CompilationUnit::RunLower(
|
||||
// TODO: Consider disabling instruction naming by default if we're not
|
||||
// producing textual LLVM IR.
|
||||
SemIR::InstNamer inst_namer(&*sem_ir_);
|
||||
module_ = Lower::LowerToLLVM(
|
||||
*llvm_context_, tree_and_subtrees_getters_for_debug_info,
|
||||
input_filename_, *sem_ir_, &inst_namer, vlog_stream_);
|
||||
module_ = Lower::LowerToLLVM(*llvm_context_,
|
||||
tree_and_subtrees_getters_for_debug_info,
|
||||
input_filename_, *sem_ir_, sem_ir_->cpp_ast(),
|
||||
&inst_namer, vlog_stream_);
|
||||
});
|
||||
if (vlog_stream_) {
|
||||
CARBON_VLOG("*** llvm::Module ***\n");
|
||||
|
||||
Reference in New Issue
Block a user