Fix lowering crash when a SpecificInst's inst_id doesn't emit a value (#7880)

This commit is contained in:
Nicholas Bishop
2026-10-01 19:17:49 +00:00
committed by GitHub
parent f1bf789481
commit 3dadff7d01
4 changed files with 205 additions and 6 deletions
+13 -4
View File
@@ -174,7 +174,8 @@ auto FunctionContext::IsConstant(SemIR::InstId inst_id) -> bool {
.second.is_constant();
}
auto FunctionContext::GetValue(SemIR::InstId inst_id) -> llvm::Value* {
auto FunctionContext::GetValue(SemIR::InstId inst_id, bool require_value)
-> llvm::Value* {
// Singletons are types, as is the builtin TypeType, with the same empty
// lowered value.
if (SemIR::IsSingletonInstId(inst_id) ||
@@ -193,9 +194,17 @@ auto FunctionContext::GetValue(SemIR::InstId inst_id) -> llvm::Value* {
auto [const_ir, const_id] = GetConstantValueInSpecific(
specific_sem_ir(), specific_id_, sem_ir(), inst_id);
CARBON_CHECK(const_ir == &sem_ir() || const_ir == &specific_sem_ir());
CARBON_CHECK(const_id.is_concrete(),
"Missing value: {0} {1} in {2} has non-concrete value {3}",
inst_id, sem_ir().insts().Get(inst_id), specific_id_, const_id);
if (require_value) {
CARBON_CHECK(const_id.is_concrete(),
"Missing value: {0} {1} in {2} has non-concrete value {3}",
inst_id, sem_ir().insts().Get(inst_id), specific_id_,
const_id);
}
if (!const_id.is_concrete()) {
return nullptr;
}
// We can only pass on the InstId if it refers to the file in which the
// constant value was provided.
auto* global = GetFileContext(const_ir).GetConstant(