Skip to content

Commit 0bc607f

Browse files
committed
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.
1 parent a5894ad commit 0bc607f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

crates/rustc_codegen_nvvm/src/abi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,10 @@ impl LlvmType for Reg {
213213
match self.kind {
214214
RegKind::Integer => cx.type_ix(self.size.bits()),
215215
RegKind::Float => match self.size.bits() {
216+
16 => cx.type_f16(),
216217
32 => cx.type_f32(),
217218
64 => cx.type_f64(),
219+
128 => cx.type_f128(),
218220
_ => bug!("unsupported float: {:?}", self),
219221
},
220222
RegKind::Vector => cx.type_vector(cx.type_i8(), self.size.bytes()),

crates/rustc_codegen_nvvm/src/llvm.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ pub(crate) enum TypeKind {
292292
Half = 1,
293293
Float = 2,
294294
Double = 3,
295+
X86_FP80 = 4,
296+
FP128 = 5,
297+
PPC_FP128 = 6,
295298
Label = 7,
296299
Integer = 8,
297300
Function = 9,
@@ -312,6 +315,9 @@ impl TypeKind {
312315
TypeKind::Half => rustc_codegen_ssa::common::TypeKind::Half,
313316
TypeKind::Float => rustc_codegen_ssa::common::TypeKind::Float,
314317
TypeKind::Double => rustc_codegen_ssa::common::TypeKind::Double,
318+
TypeKind::X86_FP80 => rustc_codegen_ssa::common::TypeKind::X86_FP80,
319+
TypeKind::FP128 => rustc_codegen_ssa::common::TypeKind::FP128,
320+
TypeKind::PPC_FP128 => rustc_codegen_ssa::common::TypeKind::PPC_FP128,
315321
TypeKind::Label => rustc_codegen_ssa::common::TypeKind::Label,
316322
TypeKind::Integer => rustc_codegen_ssa::common::TypeKind::Integer,
317323
TypeKind::Function => rustc_codegen_ssa::common::TypeKind::Function,

0 commit comments

Comments
 (0)