sema: fix memory corruption caused by resolveStructLayout

This commit is contained in:
Casey Banner 2023-04-22 13:12:35 -04:00 committed by GitHub
parent 7e9a760482
commit c7067ef6e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -30369,7 +30369,9 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
} }
if (struct_obj.layout == .Auto and sema.mod.backendSupportsFeature(.field_reordering)) { if (struct_obj.layout == .Auto and sema.mod.backendSupportsFeature(.field_reordering)) {
const optimized_order = blk: { const optimized_order = if (struct_obj.owner_decl == sema.owner_decl_index)
try sema.perm_arena.alloc(u32, struct_obj.fields.count())
else blk: {
const decl = sema.mod.declPtr(struct_obj.owner_decl); const decl = sema.mod.declPtr(struct_obj.owner_decl);
var decl_arena = decl.value_arena.?.promote(sema.mod.gpa); var decl_arena = decl.value_arena.?.promote(sema.mod.gpa);
defer decl.value_arena.?.* = decl_arena.state; defer decl.value_arena.?.* = decl_arena.state;

View file

@ -1060,7 +1060,7 @@ pub fn getDeclVAddr(
.offset = reloc_info.offset, .offset = reloc_info.offset,
.addend = reloc_info.addend, .addend = reloc_info.addend,
}); });
return undefined; return 0;
} }
pub fn getDeclBlock(self: *const Plan9, index: DeclBlock.Index) DeclBlock { pub fn getDeclBlock(self: *const Plan9, index: DeclBlock.Index) DeclBlock {