From 2c921b957e491e4676a1b61bef10279138ae5f52 Mon Sep 17 00:00:00 2001 From: FractalFir Date: Thu, 18 Sep 2025 16:15:16 +0200 Subject: [PATCH 1/2] Fixed 'is_i128', making it check if the type is an intiger, before casting it to check the intiger bit width --- crates/rustc_codegen_nvvm/src/builder.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/rustc_codegen_nvvm/src/builder.rs b/crates/rustc_codegen_nvvm/src/builder.rs index e011e14c..98abeac7 100644 --- a/crates/rustc_codegen_nvvm/src/builder.rs +++ b/crates/rustc_codegen_nvvm/src/builder.rs @@ -1358,7 +1358,11 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { // Helper function to check if a value is 128-bit integer fn is_i128(&self, val: &'ll Value) -> bool { let ty = self.val_ty(val); - unsafe { llvm::LLVMGetIntTypeWidth(ty) == 128 } + if unsafe { llvm::LLVMRustGetTypeKind(ty) == llvm::TypeKind::Integer } { + unsafe { llvm::LLVMGetIntTypeWidth(ty) == 128 } + } else { + false + } } // Helper to split i128 into low and high u64 parts From 3404a849165a2eaada3bc46a743da91edf70839d Mon Sep 17 00:00:00 2001 From: Christian Legnitto Date: Thu, 18 Sep 2025 21:34:58 -0700 Subject: [PATCH 2/2] Make int_width only operate on ints --- crates/rustc_codegen_nvvm/src/ty.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/rustc_codegen_nvvm/src/ty.rs b/crates/rustc_codegen_nvvm/src/ty.rs index 6bfd0bbd..17735af3 100644 --- a/crates/rustc_codegen_nvvm/src/ty.rs +++ b/crates/rustc_codegen_nvvm/src/ty.rs @@ -237,7 +237,10 @@ impl<'ll, 'tcx> BaseTypeCodegenMethods for CodegenCx<'ll, 'tcx> { } fn int_width(&self, ty: &'ll Type) -> u64 { - unsafe { llvm::LLVMGetIntTypeWidth(ty) as u64 } + match self.type_kind(ty) { + TypeKind::Integer => unsafe { llvm::LLVMGetIntTypeWidth(ty) as u64 }, + _ => bug!("llvm_int_width called on a non-integer type"), + } } fn val_ty(&self, v: &'ll Value) -> &'ll Type {