diff --git a/toolchain/lower/file_context.cpp b/toolchain/lower/file_context.cpp index afcc31f75934..ba700247e58f 100644 --- a/toolchain/lower/file_context.cpp +++ b/toolchain/lower/file_context.cpp @@ -58,17 +58,17 @@ auto FileContext::Run() -> std::unique_ptr { } 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()) { - inst_id = alias->value_id; - target = sem_ir().insts().Get(inst_id); - } - if (auto function_decl = target.TryAs()) { return GetFunction(function_decl->function_id); } diff --git a/toolchain/lower/testdata/packages/cross_package_call.carbon b/toolchain/lower/testdata/packages/cross_package_call.carbon new file mode 100644 index 000000000000..989b979bd8a7 --- /dev/null +++ b/toolchain/lower/testdata/packages/cross_package_call.carbon @@ -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()