mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:00:13 +01:00
Fix lowering of a call to an imported function. (#3863)
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user