Fix lowering of a call to an imported function. (#3863)

This commit is contained in:
Richard Smith
2024-04-04 21:56:53 +00:00
committed by GitHub
parent 4bd6f8d4be
commit 1792c8f522
2 changed files with 38 additions and 5 deletions
+5 -5
View File
@@ -58,17 +58,17 @@ auto FileContext::Run() -> std::unique_ptr<llvm::Module> {
}
auto FileContext::GetGlobal(SemIR::InstId inst_id) -> llvm::Value* {
auto const_id = sem_ir().constant_values().Get(inst_id);
if (const_id.is_constant()) {
inst_id = const_id.inst_id();
}
// All builtins are types, with the same empty lowered value.
if (inst_id.is_builtin()) {
return GetTypeAsValue();
}
auto target = sem_ir().insts().Get(inst_id);
while (auto alias = target.TryAs<SemIR::BindAlias>()) {
inst_id = alias->value_id;
target = sem_ir().insts().Get(inst_id);
}
if (auto function_decl = target.TryAs<SemIR::FunctionDecl>()) {
return GetFunction(function_decl->function_id);
}
@@ -0,0 +1,33 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// --- a.carbon
package A api;
fn F() {}
// --- b.carbon
import A;
fn G() { A.F(); }
// CHECK:STDOUT: ; ModuleID = 'a.carbon'
// CHECK:STDOUT: source_filename = "a.carbon"
// CHECK:STDOUT:
// CHECK:STDOUT: define void @F() {
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
// CHECK:STDOUT: ; ModuleID = 'b.carbon'
// CHECK:STDOUT: source_filename = "b.carbon"
// CHECK:STDOUT:
// CHECK:STDOUT: define void @G() {
// CHECK:STDOUT: call void @F()
// CHECK:STDOUT: ret void
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: declare void @F()