codegen: add support for lowering .field_ptr on a slice

Closes #13068
This commit is contained in:
jacobly0
2022-10-12 05:40:59 -04:00
committed by GitHub
parent b47e54ed3f
commit 562ac8be48
7 changed files with 83 additions and 18 deletions

View File

@@ -363,11 +363,21 @@ pub fn generateSymbol(
const mod = bin_file.options.module.?;
const decl = mod.declPtr(decl_index);
const addend = blk: {
switch (decl.ty.tag()) {
.@"struct" => {
switch (decl.ty.zigTypeTag()) {
.Struct => {
const addend = decl.ty.structFieldOffset(field_ptr.field_index, target);
break :blk @intCast(u32, addend);
},
.Pointer => {
assert(decl.ty.isSlice());
var buf: Type.SlicePtrFieldTypeBuffer = undefined;
const addend = switch (field_ptr.field_index) {
0 => 0,
1 => decl.ty.slicePtrFieldType(&buf).abiSize(target),
else => unreachable,
};
break :blk @intCast(u32, addend);
},
else => return Result{
.fail = try ErrorMsg.create(
bin_file.allocator,