Skip to content

Commit

Permalink
spirv-fuzz: Fix GetIdEquivalenceClasses (#3767)
Browse files Browse the repository at this point in the history
Pointer (if VariablePointers is enabled) to find sets of potential
synonyms.

However, some instructions with these types cannot be used in an OpPhi:

- OpFunction cannot be used as a value
- OpUndef should not be used, because it yields an undefined value for
  each use
Fixes #3761.
  • Loading branch information
stefanomil authored Sep 2, 2020
1 parent 7884684 commit c278dad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions source/fuzz/fuzzer_pass_add_opphi_synonyms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ FuzzerPassAddOpPhiSynonyms::GetIdEquivalenceClasses() {
continue;
}

// Exclude OpFunction and OpUndef instructions, because:
// - OpFunction does not yield a value;
// - OpUndef yields an undefined value at each use, so it should never be a
// synonym of another id.
if (pair.second->opcode() == SpvOpFunction ||
pair.second->opcode() == SpvOpUndef) {
continue;
}

// We need a new equivalence class for this id.
std::set<uint32_t> new_equivalence_class;

Expand Down
5 changes: 5 additions & 0 deletions test/fuzz/fuzzer_pass_add_opphi_synonyms_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ std::string shader = R"(
%5 = OpTypeBool
%6 = OpConstantTrue %5
%7 = OpTypeInt 32 1
%31 = OpTypeFunction %7
%8 = OpTypeInt 32 0
%9 = OpConstant %7 1
%10 = OpConstant %7 2
Expand Down Expand Up @@ -109,6 +110,10 @@ std::string shader = R"(
%28 = OpLabel
OpReturn
OpFunctionEnd
%32 = OpFunction %7 None %31
%33 = OpLabel
OpReturnValue %9
OpFunctionEnd
)";

TEST(FuzzerPassAddOpPhiSynonymsTest, HelperFunctions) {
Expand Down

0 comments on commit c278dad

Please sign in to comment.