Sema: ignore dbg_block instructions when checking for comptimeness

Closes #12514
This commit is contained in:
Veikka Tuominen 2022-08-21 12:48:26 +03:00
parent d48af541c7
commit 20d0018d79
2 changed files with 20 additions and 5 deletions

View File

@ -3087,7 +3087,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
const candidate = block.instructions.items[search_index];
switch (air_tags[candidate]) {
.dbg_stmt => continue,
.dbg_stmt, .dbg_block_begin, .dbg_block_end => continue,
.store => break candidate,
else => break :ct,
}
@ -3099,7 +3099,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
const candidate = block.instructions.items[search_index];
switch (air_tags[candidate]) {
.dbg_stmt => continue,
.dbg_stmt, .dbg_block_begin, .dbg_block_end => continue,
.alloc => {
if (Air.indexToRef(candidate) != alloc) break :ct;
break;
@ -3317,7 +3317,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
const candidate = block.instructions.items[search_index];
switch (air_tags[candidate]) {
.dbg_stmt => continue,
.dbg_stmt, .dbg_block_begin, .dbg_block_end => continue,
.store => break candidate,
else => break :ct,
}
@ -3329,7 +3329,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
const candidate = block.instructions.items[search_index];
switch (air_tags[candidate]) {
.dbg_stmt => continue,
.dbg_stmt, .dbg_block_begin, .dbg_block_end => continue,
.bitcast => break candidate,
else => break :ct,
}
@ -3341,7 +3341,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
const candidate = block.instructions.items[search_index];
switch (air_tags[candidate]) {
.dbg_stmt => continue,
.dbg_stmt, .dbg_block_begin, .dbg_block_end => continue,
.constant => break candidate,
else => break :ct,
}

View File

@ -1310,3 +1310,18 @@ test "repeated value is correctly expanded" {
} }, res);
}
}
test "value in if block is comptime known" {
if (builtin.zig_backend == .stage1) return error.SkipZigTest;
const first = blk: {
const s = if (false) "a" else "b";
break :blk "foo" ++ s;
};
const second = blk: {
const S = struct { str: []const u8 };
const s = if (false) S{ .str = "a" } else S{ .str = "b" };
break :blk "foo" ++ s.str;
};
comptime try expect(std.mem.eql(u8, first, second));
}