From 4b14384989362f93cd014628810c63b5cd9d3fff Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 25 Feb 2022 16:46:40 +0100 Subject: [PATCH] aarch64: check if type has runtime bits before allocating mem ptr --- src/arch/aarch64/CodeGen.zig | 5 +++++ src/arch/x86_64/CodeGen.zig | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index 2b863fd359..dc64e77f81 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/src/arch/aarch64/CodeGen.zig @@ -786,6 +786,11 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: u32) !u /// Use a pointer instruction as the basis for allocating stack memory. fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 { const elem_ty = self.air.typeOfIndex(inst).elemType(); + + if (!elem_ty.hasRuntimeBits()) { + return self.allocMem(inst, @sizeOf(usize), @alignOf(usize)); + } + const abi_size = math.cast(u32, elem_ty.abiSize(self.target.*)) catch { return self.fail("type '{}' too big to fit into stack frame", .{elem_ty}); }; diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index f7713a4e69..25dc8d81aa 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -852,7 +852,7 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 { const elem_ty = ptr_ty.elemType(); if (!elem_ty.hasRuntimeBits()) { - return self.allocMem(inst, 8, 8); + return self.allocMem(inst, @sizeOf(usize), @alignOf(usize)); } const abi_size = math.cast(u32, elem_ty.abiSize(self.target.*)) catch {