spirv-fuzz: Only replace regular ids with synonyms (#3255)
Fixes an issue where an id use in a non-regular context, e.g. as a
scope parameter to an atomic instruction, would be replaced with a
synonym.
diff --git a/source/fuzz/fuzzer_pass_apply_id_synonyms.cpp b/source/fuzz/fuzzer_pass_apply_id_synonyms.cpp
index 30884a6..2025821 100644
--- a/source/fuzz/fuzzer_pass_apply_id_synonyms.cpp
+++ b/source/fuzz/fuzzer_pass_apply_id_synonyms.cpp
@@ -38,16 +38,20 @@
GetTransformationContext()
->GetFactManager()
->GetIdsForWhichSynonymsAreKnown(GetIRContext())) {
- // Gather up all uses of |id_with_known_synonym|, and then subsequently
- // iterate over these uses. We use this separation because, when
- // considering a given use, we might apply a transformation that will
+ // Gather up all uses of |id_with_known_synonym| as a regular id, and
+ // subsequently iterate over these uses. We use this separation because,
+ // when considering a given use, we might apply a transformation that will
// invalidate the def-use manager.
std::vector<std::pair<opt::Instruction*, uint32_t>> uses;
GetIRContext()->get_def_use_mgr()->ForEachUse(
id_with_known_synonyms,
[&uses](opt::Instruction* use_inst, uint32_t use_index) -> void {
- uses.emplace_back(
- std::pair<opt::Instruction*, uint32_t>(use_inst, use_index));
+ // We only gather up regular id uses; e.g. we do not include a use of
+ // the id as the scope for an atomic operation.
+ if (use_inst->GetOperand(use_index).type == SPV_OPERAND_TYPE_ID) {
+ uses.emplace_back(
+ std::pair<opt::Instruction*, uint32_t>(use_inst, use_index));
+ }
});
for (auto& use : uses) {