mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 08:33:06 +00:00
Sema: ignore dbg_block instructions when checking for comptimeness
Closes #12514
This commit is contained in:
parent
d48af541c7
commit
20d0018d79
10
src/Sema.zig
10
src/Sema.zig
@ -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,
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user