authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-21 22:25:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-21 22:25:58-07:00
log221295b7db97c78ffce39e64dd6cafd8ad0b3f9a
treed41c8344573283da5e5be48e06d4c73662e25ddc
parent747440677dc58394c73235627d9016ee5f7588d8

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 ```

1 files changed, 8 insertions(+), 7 deletions(-)

src/arch/wasm/abi.zig+8-7
......@@ -28,19 +28,20 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class {
2828 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return none;
2929 switch (ty.zigTypeTag(mod)) {
3030 .Struct => {
31 if (ty.containerLayout(mod) == .Packed) {
31 const struct_type = mod.typeToStruct(ty).?;
32 if (struct_type.layout == .Packed) {
3233 if (ty.bitSize(mod) <= 64) return direct;
3334 return .{ .direct, .direct };
3435 }
35 if (ty.structFieldCount(mod) > 1) {
36 if (struct_type.field_types.len > 1) {
3637 // The struct type is non-scalar.
3738 return memory;
3839 }
39 const field_ty = ty.structFieldType(0, mod);
40 const resolved_align = ty.structFieldAlign(0, mod);
41 if (resolved_align.compare(.gt, field_ty.abiAlignment(mod))) {
42 // The struct's alignment is greater than natural alignment.
43 return memory;
40 const field_ty = struct_type.field_types.get(ip)[0].toType();
41 const explicit_align = struct_type.fieldAlign(ip, 0);
42 if (explicit_align != .none) {
43 if (explicit_align.compareStrict(.gt, field_ty.abiAlignment(mod)))
44 return memory;
4445 }
4546 return classifyType(field_ty, mod);
4647 },