From 4975bfa143d86bbd4f20edcb86fc1015b3d355dd Mon Sep 17 00:00:00 2001 From: Christian Legnitto Date: Fri, 3 Apr 2026 21:49:47 -0700 Subject: [PATCH] Fix f16/f128 TypeKind UB causing SIGTRAP on aarch64 The `TypeKind` repr(C) enum was missing `X86_FP80`, `FP128`, and `PPC_FP128` variants (values 4, 5, 6). When `compiler_builtins` is compiled with `--cfg f128_enabled` (new in recent nightlies), the C FFI function `LLVMRustGetTypeKind` returns 5 for fp128 types. The Rust enum had no variant for that discriminant, causing instant undefined behavior (manifesting as SIGTRAP). Also adds f16 and f128 cases to the ABI `Reg::llvm_type` float match, which previously only handled 32 and 64-bit floats. --- crates/rustc_codegen_nvvm/src/abi.rs | 2 ++ crates/rustc_codegen_nvvm/src/llvm.rs | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/crates/rustc_codegen_nvvm/src/abi.rs b/crates/rustc_codegen_nvvm/src/abi.rs index bb438795..712b9a55 100644 --- a/crates/rustc_codegen_nvvm/src/abi.rs +++ b/crates/rustc_codegen_nvvm/src/abi.rs @@ -213,8 +213,10 @@ impl LlvmType for Reg { match self.kind { RegKind::Integer => cx.type_ix(self.size.bits()), RegKind::Float => match self.size.bits() { + 16 => cx.type_f16(), 32 => cx.type_f32(), 64 => cx.type_f64(), + 128 => cx.type_f128(), _ => bug!("unsupported float: {:?}", self), }, RegKind::Vector => cx.type_vector(cx.type_i8(), self.size.bytes()), diff --git a/crates/rustc_codegen_nvvm/src/llvm.rs b/crates/rustc_codegen_nvvm/src/llvm.rs index a9cbcad3..2fea8e12 100644 --- a/crates/rustc_codegen_nvvm/src/llvm.rs +++ b/crates/rustc_codegen_nvvm/src/llvm.rs @@ -292,6 +292,9 @@ pub(crate) enum TypeKind { Half = 1, Float = 2, Double = 3, + X86_FP80 = 4, + FP128 = 5, + PPC_FP128 = 6, Label = 7, Integer = 8, Function = 9, @@ -312,6 +315,9 @@ impl TypeKind { TypeKind::Half => rustc_codegen_ssa::common::TypeKind::Half, TypeKind::Float => rustc_codegen_ssa::common::TypeKind::Float, TypeKind::Double => rustc_codegen_ssa::common::TypeKind::Double, + TypeKind::X86_FP80 => rustc_codegen_ssa::common::TypeKind::X86_FP80, + TypeKind::FP128 => rustc_codegen_ssa::common::TypeKind::FP128, + TypeKind::PPC_FP128 => rustc_codegen_ssa::common::TypeKind::PPC_FP128, TypeKind::Label => rustc_codegen_ssa::common::TypeKind::Label, TypeKind::Integer => rustc_codegen_ssa::common::TypeKind::Integer, TypeKind::Function => rustc_codegen_ssa::common::TypeKind::Function,