authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-01-20 19:44:28+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-20 18:19:20-05:00
logf763000dc918c2367ebc181645eb48db896205d8
treee51b07e48ba4a0e1a138f9e9a9b42a3aa2a4a3b7
parenteb70f6e8d7f4c1a735fe25de368f6d5459cba16c

Fix abi size of optional slices

Previously, optional slices returned the pointer size as abi size. We now account for slices to calculate the correct size which is abi-alignment + slice ABI size.

1 files changed, 2 insertions(+), 2 deletions(-)

src/type.zig+2-2
...@@ -2157,7 +2157,7 @@ pub const Type = extern union {...@@ -2157,7 +2157,7 @@ pub const Type = extern union {
2157 const child_type = self.optionalChild(&buf);2157 const child_type = self.optionalChild(&buf);
2158 if (!child_type.hasCodeGenBits()) return 1;2158 if (!child_type.hasCodeGenBits()) return 1;
21592159
2160 if (child_type.zigTypeTag() == .Pointer and !child_type.isCPtr())2160 if (child_type.zigTypeTag() == .Pointer and !child_type.isCPtr() and !child_type.isSlice())
2161 return @divExact(target.cpu.arch.ptrBitWidth(), 8);2161 return @divExact(target.cpu.arch.ptrBitWidth(), 8);
21622162
2163 // Optional types are represented as a struct with the child type as the first2163 // Optional types are represented as a struct with the child type as the first
...@@ -2344,7 +2344,7 @@ pub const Type = extern union {...@@ -2344,7 +2344,7 @@ pub const Type = extern union {
2344 const child_type = ty.optionalChild(&buf);2344 const child_type = ty.optionalChild(&buf);
2345 if (!child_type.hasCodeGenBits()) return 8;2345 if (!child_type.hasCodeGenBits()) return 8;
23462346
2347 if (child_type.zigTypeTag() == .Pointer and !child_type.isCPtr())2347 if (child_type.zigTypeTag() == .Pointer and !child_type.isCPtr() and !child_type.isSlice())
2348 return target.cpu.arch.ptrBitWidth();2348 return target.cpu.arch.ptrBitWidth();
23492349
2350 // Optional types are represented as a struct with the child type as the first2350 // Optional types are represented as a struct with the child type as the first