aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2021-10-26 02:29:07 +0200
committerRobin Voetter <robin@voetter.nl>2021-10-26 02:29:07 +0200
commitf95ec229f8478eedbb59700cbd223367ebd89a86 (patch)
tree15a9c47f38b5671e29d568c6f8de895b06a9e7f3 /src
parent914993123c91534e4fa1d32c93bc43341cb24a8c (diff)
downloadzig-f95ec229f8478eedbb59700cbd223367ebd89a86.tar.gz
zig-f95ec229f8478eedbb59700cbd223367ebd89a86.zip
stage2: fix use-after-free in analyzeBlockBody
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 924ff7b267..6d087fde7e 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -3035,10 +3035,11 @@ fn analyzeBlockBody(
// to emit a jump instruction to after the block when it encounters the break.
try parent_block.instructions.append(gpa, merges.block_inst);
const resolved_ty = try sema.resolvePeerTypes(parent_block, src, merges.results.items, .none);
+ const ty_inst = try sema.addType(resolved_ty);
try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +
child_block.instructions.items.len);
sema.air_instructions.items(.data)[merges.block_inst] = .{ .ty_pl = .{
- .ty = try sema.addType(resolved_ty),
+ .ty = ty_inst,
.payload = sema.addExtraAssumeCapacity(Air.Block{
.body_len = @intCast(u32, child_block.instructions.items.len),
}),