Fix CHECK failure when there is control flow in a global variable initializer (#3925)

Problem found by fuzzing.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
This commit is contained in:
josh11b
2024-04-30 23:17:32 +00:00
committed by GitHub
co-authored by Josh L
parent 8676ef6f36
commit 4f2bd0b095
3 changed files with 96 additions and 4 deletions
+2 -4
View File
@@ -22,7 +22,7 @@ auto InstBlockStack::Push(SemIR::InstBlockId id) -> void {
}
auto InstBlockStack::PushGlobalInit() -> void {
Push(SemIR::InstBlockId::GlobalInit);
Push(init_block_id_);
stack_[size_ - 1].content = std::move(init_block_);
}
@@ -58,10 +58,8 @@ auto InstBlockStack::Pop() -> SemIR::InstBlockId {
}
auto InstBlockStack::PopGlobalInit() -> void {
CARBON_CHECK(stack_[size_ - 1].id == SemIR::InstBlockId::GlobalInit)
<< "Trying to pop Inits block from " << name_
<< " but a different block is present!";
init_block_ = std::move(stack_[size_ - 1].content);
init_block_id_ = stack_[size_ - 1].id;
PopAndDiscard();
}