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
```
This commit is contained in:
Andrew Kelley 2023-09-21 22:25:58 -07:00
parent 747440677d
commit 221295b7db

View File

@ -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);
},