Skip to content

Commit

Permalink
Assert that the llvm::Function is created with the same name as reque…
Browse files Browse the repository at this point in the history
…sted (carbon-language#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.
  • Loading branch information
dwblaikie authored Sep 13, 2024
1 parent 88f3b34 commit ec63d2b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions toolchain/lower/file_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down

0 comments on commit ec63d2b

Please sign in to comment.