From 6b4d4c70fd8b8696eb1220438b89f769a3c3a908 Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Tue, 19 Jul 2022 22:01:32 +0200 Subject: [PATCH] wasm: Only allow lowering C-ABI compatible types --- src/arch/wasm/abi.zig | 20 +------------------- src/codegen/llvm.zig | 5 +---- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/arch/wasm/abi.zig b/src/arch/wasm/abi.zig index f86d82d70e..b1e99f4f92 100644 --- a/src/arch/wasm/abi.zig +++ b/src/arch/wasm/abi.zig @@ -48,38 +48,20 @@ pub fn classifyType(ty: Type, target: Target) [2]Class { }, .Bool => return direct, .Array => return memory, - // .ErrorUnion => { - // const has_tag = ty.errorUnionSet().hasRuntimeBitsIgnoreComptime(); - // const has_pl = ty.errorUnionPayload().hasRuntimeBitsIgnoreComptime(); - // if (!has_pl) return direct; - // if (!has_tag) { - // return classifyType(ty.errorUnionPayload(), target); - // } - // return memory; - // }, .Optional => { std.debug.assert(ty.isPtrLikeOptional()); return direct; - // var buf: Type.Payload.ElemType = undefined; - // const pl_has_bits = ty.optionalChild(&buf).hasRuntimeBitsIgnoreComptime(); - // if (!pl_has_bits) return direct; - // return memory; }, .Pointer => { - // // Slices act like struct and will be passed by reference - // if (ty.isSlice()) return memory; + std.debug.assert(!ty.isSlice()); return direct; }, .Union => { const layout = ty.unionGetLayout(target); std.debug.assert(layout.tag_size == 0); - // if (layout.payload_size == 0 and layout.tag_size != 0) { - // return classifyType(ty.unionTagType().?, target); - // } if (ty.unionFields().count() > 1) return memory; return classifyType(ty.unionFields().values()[0].ty, target); }, - // .AnyFrame, .Frame => return direct, .ErrorUnion, .Frame, .AnyFrame, diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 8dbb9cae31..b4bf8449ce 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -9094,10 +9094,7 @@ fn firstParamSRet(fn_info: Type.Payload.Function.Data, target: std.Target) bool .windows => return x86_64_abi.classifyWindows(fn_info.return_type, target) == .memory, else => return x86_64_abi.classifySystemV(fn_info.return_type, target)[0] == .memory, }, - .wasm32 => { - const classes = wasm_c_abi.classifyType(fn_info.return_type, target); - return classes[0] == .indirect; - }, + .wasm32 => return wasm_c_abi.classifyType(fn_info.return_type, target)[0] == .indirect, else => return false, // TODO investigate C ABI for other architectures }, else => return false,