From d5d0c9065204c52b1c31192dd181f65ab3c19b9a Mon Sep 17 00:00:00 2001 From: Ashley Hauck <953151+khyperia@users.noreply.github.com> Date: Wed, 1 Dec 2021 11:25:23 +0100 Subject: [PATCH] Fix for duplicate OpMemberName, and add OpMemberName for ScalarPairs (#814) --- crates/rustc_codegen_spirv/src/abi.rs | 15 ++++++++++++++- .../rustc_codegen_spirv/src/linker/duplicates.rs | 8 +++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/rustc_codegen_spirv/src/abi.rs b/crates/rustc_codegen_spirv/src/abi.rs index 7f817fb139..155daf7ef0 100644 --- a/crates/rustc_codegen_spirv/src/abi.rs +++ b/crates/rustc_codegen_spirv/src/abi.rs @@ -381,13 +381,26 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> { } else { Some(self.size) }; + let mut field_names = Vec::new(); + if let TyKind::Adt(adt, _) = self.ty.kind() { + if let Variants::Single { index } = self.variants { + for i in self.fields.index_by_increasing_offset() { + let field = &adt.variants[index].fields[i]; + field_names.push(field.ident.name.to_ident_string()); + } + } + } SpirvType::Adt { def_id: def_id_for_spirv_type_adt(*self), size, align: self.align.abi, field_types: vec![a, b], field_offsets: vec![a_offset, b_offset], - field_names: None, + field_names: if field_names.len() == 2 { + Some(field_names) + } else { + None + }, } .def_with_name(cx, span, TyLayoutNameKey::from(*self)) } diff --git a/crates/rustc_codegen_spirv/src/linker/duplicates.rs b/crates/rustc_codegen_spirv/src/linker/duplicates.rs index d382c51646..ea84f53df5 100644 --- a/crates/rustc_codegen_spirv/src/linker/duplicates.rs +++ b/crates/rustc_codegen_spirv/src/linker/duplicates.rs @@ -269,8 +269,14 @@ pub fn remove_duplicate_types(module: &mut Module) { .retain(|inst| anno_set.insert(inst.assemble())); // Same thing with OpName let mut name_ids = FxHashSet::default(); + let mut member_name_ids = FxHashSet::default(); module.debug_names.retain(|inst| { - inst.class.opcode != Op::Name || name_ids.insert(inst.operands[0].unwrap_id_ref()) + (inst.class.opcode != Op::Name || name_ids.insert(inst.operands[0].unwrap_id_ref())) + && (inst.class.opcode != Op::MemberName + || member_name_ids.insert(( + inst.operands[0].unwrap_id_ref(), + inst.operands[1].unwrap_literal_int32(), + ))) }); }