From 221295b7db97c78ffce39e64dd6cafd8ad0b3f9a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 21 Sep 2023 22:25:58 -0700 Subject: [PATCH] wasm: fix regression of C ABI It seems the webassembly backend does not want the exception that `structFieldAlignmentExtern` makes for 128-bit integers. Perhaps that logic should be modified to check if the target is wasm. Without this, this branch fails the C ABI tests for wasm, causing this: ``` wasm-ld: warning: function signature mismatch: zig_struct_u128 >>> defined as (i64, i64) -> void in cfuncs.o >>> defined as (i32) -> void in test-c-abi-wasm32-wasi-musl-ReleaseFast.wasm.o ``` --- src/arch/wasm/abi.zig | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/arch/wasm/abi.zig b/src/arch/wasm/abi.zig index 677ba1037c..c6967809dc 100644 --- a/src/arch/wasm/abi.zig +++ b/src/arch/wasm/abi.zig @@ -28,19 +28,20 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class { if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return none; switch (ty.zigTypeTag(mod)) { .Struct => { - if (ty.containerLayout(mod) == .Packed) { + const struct_type = mod.typeToStruct(ty).?; + if (struct_type.layout == .Packed) { if (ty.bitSize(mod) <= 64) return direct; return .{ .direct, .direct }; } - if (ty.structFieldCount(mod) > 1) { + if (struct_type.field_types.len > 1) { // The struct type is non-scalar. return memory; } - const field_ty = ty.structFieldType(0, mod); - const resolved_align = ty.structFieldAlign(0, mod); - if (resolved_align.compare(.gt, field_ty.abiAlignment(mod))) { - // The struct's alignment is greater than natural alignment. - return memory; + const field_ty = struct_type.field_types.get(ip)[0].toType(); + const explicit_align = struct_type.fieldAlign(ip, 0); + if (explicit_align != .none) { + if (explicit_align.compareStrict(.gt, field_ty.abiAlignment(mod))) + return memory; } return classifyType(field_ty, mod); },