The following function generates invalid TZIR (changing const val to var val fixes it):
fn foo(ok: bool) void {
const val: i32 = blk: {
if (!ok) break :blk 10;
break :blk 20;
};
var other: i32 = val;
}
TZIR output (I implemented TZIR printing for blocks etc, PR incoming):
Module.Function(name=foo):
@1: i32 = 10;
@2: void = {};
@4: i32 = 20;
%0: bool = arg(ok)
%1: void = dbg_stmt()
%2: *i32 = alloc()
%3: i32 = block(
%4: void = dbg_stmt()
%5: void = block(
%6: bool = not(%0)
%7: noreturn = condbr(%6,
then:
%8: void = store(%2, @1)
%9: noreturn = br(%3, @1)
else:
%10: noreturn = br(%5, @2)
)
)
%11: void = dbg_stmt()
%12: void = store(%2, @4)
%13: noreturn = br(%3, @4)
)
%14: void = dbg_stmt()
%15: *i32 = alloc()
%16: void = store(%15, %3)
%17: noreturn = retvoid()
The problem happens at instruction %16. Here we try to store %3 in %15, however %3 is the block instruction. But as you can see in instruction %8, we store the value in %2. So I think the problem is that instruction %16 should change to:
%16: void = store(%15, %2)
The following function generates invalid TZIR (changingconst valtovar valfixes it):TZIR output (I implemented TZIR printing for blocks etc, PR incoming):The problem happens at instruction%16. Here we try to store%3in%15, however%3is theblockinstruction. But as you can see in instruction%8, we store the value in%2. So I think the problem is that instruction%16should change to: