From a2e9a608c12ad6289f8fa4e1d813c82ace6807d2 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Thu, 19 Jan 2023 19:08:32 +0100 Subject: [PATCH] fuzzgen: Enable s390x and disable unimplemented ops (#5596) Also fix assertion failure when using "i128 uext" or "i128 sext" arguments or return values, as discovered by the fuzzer. --- cranelift/codegen/src/isa/s390x/abi.rs | 1 - cranelift/codegen/src/isa/s390x/inst.isle | 6 ++-- cranelift/fuzzgen/src/function_generator.rs | 40 +++++++++++++++++++++ fuzz/Cargo.toml | 2 +- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/cranelift/codegen/src/isa/s390x/abi.rs b/cranelift/codegen/src/isa/s390x/abi.rs index c66d3ac2a0..9d27be3012 100644 --- a/cranelift/codegen/src/isa/s390x/abi.rs +++ b/cranelift/codegen/src/isa/s390x/abi.rs @@ -275,7 +275,6 @@ impl ABIMachineSpec for S390xMachineDeps { } else if call_conv.extends_wasmtime() { panic!("i128 args/return values not supported in the Wasmtime ABI"); } else { - assert!(param.extension == ir::ArgumentExtension::None); // We must pass this by implicit reference. if args_or_rets == ArgsOrRets::Rets { // For return values, just force them to memory. diff --git a/cranelift/codegen/src/isa/s390x/inst.isle b/cranelift/codegen/src/isa/s390x/inst.isle index 458dfe4789..815513f046 100644 --- a/cranelift/codegen/src/isa/s390x/inst.isle +++ b/cranelift/codegen/src/isa/s390x/inst.isle @@ -2975,9 +2975,9 @@ ;; Helper to compute the type of an implicitly extended argument/return value. (decl abi_ext_ty (ArgumentExtension Type) Type) -(rule (abi_ext_ty (ArgumentExtension.None) ty) ty) -(rule (abi_ext_ty (ArgumentExtension.Uext) _) $I64) -(rule (abi_ext_ty (ArgumentExtension.Sext) _) $I64) +(rule 0 (abi_ext_ty _ ty) ty) +(rule 1 (abi_ext_ty (ArgumentExtension.Uext) (gpr32_ty _)) $I64) +(rule 1 (abi_ext_ty (ArgumentExtension.Sext) (gpr32_ty _)) $I64) ;; Helpers for generating immediate values ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/cranelift/fuzzgen/src/function_generator.rs b/cranelift/fuzzgen/src/function_generator.rs index 2383fbdb54..f98212c9c3 100644 --- a/cranelift/fuzzgen/src/function_generator.rs +++ b/cranelift/fuzzgen/src/function_generator.rs @@ -502,6 +502,46 @@ fn valid_for_target(triple: &Triple, op: Opcode, args: &[Type], rets: &[Type]) - ) } + Architecture::S390x => { + exceptions!( + (Opcode::IaddCout), + (Opcode::Udiv, &[I128, I128]), + (Opcode::Sdiv, &[I128, I128]), + (Opcode::Urem, &[I128, I128]), + (Opcode::Srem, &[I128, I128]), + (Opcode::Smin), + (Opcode::Smax), + (Opcode::Umin), + (Opcode::Umax), + (Opcode::Band, &[F32, F32]), + (Opcode::Band, &[F64, F64]), + (Opcode::Bor, &[F32, F32]), + (Opcode::Bor, &[F64, F64]), + (Opcode::Bxor, &[F32, F32]), + (Opcode::Bxor, &[F64, F64]), + (Opcode::Bnot, &[F32, F32]), + (Opcode::Bnot, &[F64, F64]), + (Opcode::BandNot, &[F32, F32]), + (Opcode::BandNot, &[F64, F64]), + (Opcode::BorNot, &[F32, F32]), + (Opcode::BorNot, &[F64, F64]), + (Opcode::BxorNot, &[F32, F32]), + (Opcode::BxorNot, &[F64, F64]), + (Opcode::FcvtToUint, &[F32], &[I128]), + (Opcode::FcvtToUint, &[F64], &[I128]), + (Opcode::FcvtToUintSat, &[F32], &[I128]), + (Opcode::FcvtToUintSat, &[F64], &[I128]), + (Opcode::FcvtToSint, &[F32], &[I128]), + (Opcode::FcvtToSint, &[F64], &[I128]), + (Opcode::FcvtToSintSat, &[F32], &[I128]), + (Opcode::FcvtToSintSat, &[F64], &[I128]), + (Opcode::FcvtFromUint, &[I128], &[F32]), + (Opcode::FcvtFromUint, &[I128], &[F64]), + (Opcode::FcvtFromSint, &[I128], &[F32]), + (Opcode::FcvtFromSint, &[I128], &[F64]), + ) + } + Architecture::Riscv64(_) => { exceptions!( // TODO diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 8ee4559574..11b6ff3d02 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -10,7 +10,7 @@ cargo-fuzz = true [dependencies] anyhow = { workspace = true } once_cell = { workspace = true } -cranelift-codegen = { workspace = true, features = ["incremental-cache", "x86", "arm64", "riscv64"] } +cranelift-codegen = { workspace = true, features = ["incremental-cache", "x86", "arm64", "s390x", "riscv64"] } cranelift-reader = { workspace = true } cranelift-wasm = { workspace = true } cranelift-filetests = { workspace = true }