From ec63d2be2154af0ea50171ab946aa2b5e681e402 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Thu, 12 Sep 2024 17:33:29 -0700 Subject: [PATCH] Assert that the llvm::Function is created with the same name as requested (#4306) This will catch some cases of bugs in the name mangling logic - if within a single file we incorrectly mangle two distinct entities to the same name, llvm::Function will assign a new name to the second copy showing one of the two entities should have a distinct name/is missing something in their mangling. --- toolchain/lower/file_context.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/toolchain/lower/file_context.cpp b/toolchain/lower/file_context.cpp index a78464fc8ca83..d9592544ceacb 100644 --- a/toolchain/lower/file_context.cpp +++ b/toolchain/lower/file_context.cpp @@ -249,6 +249,9 @@ auto FileContext::BuildFunctionDecl(SemIR::FunctionId function_id) llvm::Function::Create(function_type, llvm::Function::ExternalLinkage, mangled_name, llvm_module()); + CARBON_CHECK(llvm_function->getName() == mangled_name, + "Mangled name collision: {0}", mangled_name); + // Set up parameters and the return slot. for (auto [inst_id, arg] : llvm::zip_equal(param_inst_ids, llvm_function->args())) {