codegen: add support for lowering .field_ptr on a slice

Closes #13068
This commit is contained in:
jacobly0 authored and GitHub committed 2022-10-12 12:40:59 +03:00
1 parent b47e54ed3f
commit 562ac8be48
7 files changed
+83 -18

No files matched your search

+12 -2
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,