Skip to content

Commit d5d0c90

Browse files
authored
Fix for duplicate OpMemberName, and add OpMemberName for ScalarPairs (#814)
1 parent 2e4de94 commit d5d0c90

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

crates/rustc_codegen_spirv/src/abi.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,26 @@ impl<'tcx> ConvSpirvType<'tcx> for TyAndLayout<'tcx> {
381381
} else {
382382
Some(self.size)
383383
};
384+
let mut field_names = Vec::new();
385+
if let TyKind::Adt(adt, _) = self.ty.kind() {
386+
if let Variants::Single { index } = self.variants {
387+
for i in self.fields.index_by_increasing_offset() {
388+
let field = &adt.variants[index].fields[i];
389+
field_names.push(field.ident.name.to_ident_string());
390+
}
391+
}
392+
}
384393
SpirvType::Adt {
385394
def_id: def_id_for_spirv_type_adt(*self),
386395
size,
387396
align: self.align.abi,
388397
field_types: vec![a, b],
389398
field_offsets: vec![a_offset, b_offset],
390-
field_names: None,
399+
field_names: if field_names.len() == 2 {
400+
Some(field_names)
401+
} else {
402+
None
403+
},
391404
}
392405
.def_with_name(cx, span, TyLayoutNameKey::from(*self))
393406
}

crates/rustc_codegen_spirv/src/linker/duplicates.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,14 @@ pub fn remove_duplicate_types(module: &mut Module) {
269269
.retain(|inst| anno_set.insert(inst.assemble()));
270270
// Same thing with OpName
271271
let mut name_ids = FxHashSet::default();
272+
let mut member_name_ids = FxHashSet::default();
272273
module.debug_names.retain(|inst| {
273-
inst.class.opcode != Op::Name || name_ids.insert(inst.operands[0].unwrap_id_ref())
274+
(inst.class.opcode != Op::Name || name_ids.insert(inst.operands[0].unwrap_id_ref()))
275+
&& (inst.class.opcode != Op::MemberName
276+
|| member_name_ids.insert((
277+
inst.operands[0].unwrap_id_ref(),
278+
inst.operands[1].unwrap_literal_int32(),
279+
)))
274280
});
275281
}
276282

0 commit comments

Comments
 (0)