Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm: correctly lower packed structs in arguments #18897

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions src/arch/wasm/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1432,21 +1432,13 @@ fn lowerArg(func: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value:
}
assert(ty_classes[0] == .direct);
const scalar_type = abi.scalarType(ty, mod);
const abi_size = scalar_type.abiSize(mod);
try func.emitWValue(value);

// When the value lives in the virtual stack, we must load it onto the actual stack
if (value != .imm32 and value != .imm64) {
const opcode = buildOpcode(.{
.op = .load,
.width = @as(u8, @intCast(abi_size)),
.signedness = if (scalar_type.isSignedInt(mod)) .signed else .unsigned,
.valtype1 = typeToValtype(scalar_type, mod),
});
try func.addMemArg(Mir.Inst.Tag.fromOpcode(opcode), .{
.offset = value.offset(),
.alignment = @intCast(scalar_type.abiAlignment(mod).toByteUnitsOptional().?),
});
switch (value) {
.memory,
.memory_offset,
.stack_offset,
=> _ = try func.load(value, scalar_type, 0),
.dead => unreachable,
else => try func.emitWValue(value),
}
},
.Int, .Float => {
Expand Down Expand Up @@ -2522,7 +2514,7 @@ fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValu
return WValue{ .stack = {} };
}

const abi_size = @as(u8, @intCast(ty.abiSize(mod)));
const abi_size: u8 = @intCast(ty.abiSize(mod));
const opcode = buildOpcode(.{
.valtype1 = typeToValtype(ty, mod),
.width = abi_size * 8,
Expand Down
Loading