diff --git a/rustc_codegen_spirv/src/builder/builder_methods.rs b/rustc_codegen_spirv/src/builder/builder_methods.rs index e6d5c5aeab..3179030f40 100644 --- a/rustc_codegen_spirv/src/builder/builder_methods.rs +++ b/rustc_codegen_spirv/src/builder/builder_methods.rs @@ -318,7 +318,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - fn zombie_bitcast_ptr(&self, def: Word) { + fn zombie_bitcast_ptr(&self, def: Word, from_ty: Word, to_ty: Word) { let is_logical = self .emit() .module_ref() @@ -328,7 +328,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { inst.operands[0].unwrap_addressing_model() == AddressingModel::Logical }); if is_logical { - self.zombie(def, "OpBitcast on ptr without AddressingModel != Logical") + if self.is_system_crate() { + self.zombie(def, "OpBitcast on ptr without AddressingModel != Logical") + } else { + self.struct_err("Cannot cast between pointer types") + .note(&format!("from: {}", self.debug_type(from_ty))) + .note(&format!("to: {}", self.debug_type(to_ty))) + .emit() + } } } @@ -1111,7 +1118,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { let val_is_ptr = matches!(self.lookup_type(val.ty), SpirvType::Pointer{..}); let dest_is_ptr = matches!(self.lookup_type(dest_ty), SpirvType::Pointer{..}); if val_is_ptr || dest_is_ptr { - self.zombie_bitcast_ptr(result.def); + self.zombie_bitcast_ptr(result.def, val.ty, dest_ty); } result } @@ -1207,7 +1214,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { .bitcast(dest_ty, None, val.def) .unwrap() .with_type(dest_ty); - self.zombie_bitcast_ptr(result.def); + self.zombie_bitcast_ptr(result.def, val.ty, dest_ty); result } } diff --git a/rustc_codegen_spirv/src/builder/mod.rs b/rustc_codegen_spirv/src/builder/mod.rs index de65c6fbec..b41fe009b4 100644 --- a/rustc_codegen_spirv/src/builder/mod.rs +++ b/rustc_codegen_spirv/src/builder/mod.rs @@ -17,6 +17,7 @@ use rustc_codegen_ssa::traits::{ CoverageInfoBuilderMethods, DebugInfoBuilderMethods, HasCodegen, InlineAsmOperandRef, StaticBuilderMethods, }; +use rustc_errors::DiagnosticBuilder; use rustc_hir::LlvmInlineAsmInner; use rustc_middle::mir::coverage::{ CodeRegion, CounterValueReference, ExpressionOperandId, InjectedExpressionIndex, Op, @@ -63,7 +64,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - /* pub fn struct_err(&self, msg: &str) -> DiagnosticBuilder<'_> { if let Some(current_span) = self.current_span { self.tcx.sess.struct_span_err(current_span, msg) @@ -71,7 +71,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.tcx.sess.struct_err(msg) } } - */ pub fn err(&self, msg: &str) { if let Some(current_span) = self.current_span { diff --git a/rustc_codegen_spirv/src/codegen_cx/mod.rs b/rustc_codegen_spirv/src/codegen_cx/mod.rs index 15203596e5..903dc54d1b 100644 --- a/rustc_codegen_spirv/src/codegen_cx/mod.rs +++ b/rustc_codegen_spirv/src/codegen_cx/mod.rs @@ -136,7 +136,7 @@ impl<'tcx> CodegenCx<'tcx> { self.zombie_values.borrow_mut().insert(word, reason); } - fn is_system_crate(&self) -> bool { + pub fn is_system_crate(&self) -> bool { self.tcx .sess .contains_name(self.tcx.hir().krate_attrs(), sym::compiler_builtins)