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 {...@@ -28,19 +28,20 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class {
28 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return none;28 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return none;
29 switch (ty.zigTypeTag(mod)) {29 switch (ty.zigTypeTag(mod)) {
30 .Struct => {30 .Struct => {
31 if (ty.containerLayout(mod) == .Packed) {31 const struct_type = mod.typeToStruct(ty).?;
32 if (struct_type.layout == .Packed) {
32 if (ty.bitSize(mod) <= 64) return direct;33 if (ty.bitSize(mod) <= 64) return direct;
33 return .{ .direct, .direct };34 return .{ .direct, .direct };
34 }35 }
35 if (ty.structFieldCount(mod) > 1) {36 if (struct_type.field_types.len > 1) {
36 // The struct type is non-scalar.37 // The struct type is non-scalar.
37 return memory;38 return memory;
38 }39 }
39 const field_ty = ty.structFieldType(0, mod);40 const field_ty = struct_type.field_types.get(ip)[0].toType();
40 const resolved_align = ty.structFieldAlign(0, mod);41 const explicit_align = struct_type.fieldAlign(ip, 0);
41 if (resolved_align.compare(.gt, field_ty.abiAlignment(mod))) {42 if (explicit_align != .none) {
42 // The struct's alignment is greater than natural alignment.43 if (explicit_align.compareStrict(.gt, field_ty.abiAlignment(mod)))
43 return memory;44 return memory;
44 }45 }
45 return classifyType(field_ty, mod);46 return classifyType(field_ty, mod);
46 },47 },