Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spirv-fuzz: Skip early terminator wrappers when merging returns #3968

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions source/fuzz/fuzzer_pass_merge_function_returns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ void FuzzerPassMergeFunctionReturns::Apply() {
continue;
}

// We skip wrappers for early terminators, since this fuzzer pass introduces
// such wrappers to eliminate early terminators.
if (IsEarlyTerminatorWrapper(*function)) {
continue;
}

// Only consider functions that have early returns.
if (!function->HasEarlyReturn()) {
continue;
Expand Down Expand Up @@ -316,5 +322,16 @@ FuzzerPassMergeFunctionReturns::GetInfoNeededForMergeBlocks(
return result;
}

bool FuzzerPassMergeFunctionReturns::IsEarlyTerminatorWrapper(
const opt::Function& function) const {
for (SpvOp opcode : {SpvOpKill, SpvOpUnreachable, SpvOpTerminateInvocation}) {
if (TransformationWrapEarlyTerminatorInFunction::MaybeGetWrapperFunction(
GetIRContext(), opcode) == &function) {
return true;
}
}
return false;
}

} // namespace fuzz
} // namespace spvtools
4 changes: 4 additions & 0 deletions source/fuzz/fuzzer_pass_merge_function_returns.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class FuzzerPassMergeFunctionReturns : public FuzzerPass {
const std::vector<uint32_t>& merge_blocks,
std::map<uint32_t, std::vector<uint32_t>>*
ids_available_after_entry_block);

// Returns true if and only if |function| is a wrapper for an early terminator
// instruction such as OpKill.
bool IsEarlyTerminatorWrapper(const opt::Function& function) const;
};
} // namespace fuzz
} // namespace spvtools
Expand Down