Skip to content

Commit

Permalink
spirv-fuzz: Ignore specialization constants (KhronosGroup#3664)
Browse files Browse the repository at this point in the history
`FuzzerPassInterchangeSignednessOfIntegerOperands` and `FuzzerPassInterchangeZeroLikeConstants` both included specialization constants when trying to find integer constants with known values. However, this is incorrect behavior because we do not know the value of specialization constants. Furthermore, ConstantManager does not support them, and this led to crashes where we assumed we could look up specialization constants via the ConstantManager.

This change fixes both passes to ignore specialization constants.

Fixes KhronosGroup#3663.
  • Loading branch information
andreperezmaselco authored and dnovillo committed Aug 19, 2020
1 parent 630c60c commit d08090b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ void FuzzerPassInterchangeSignednessOfIntegerOperands::Apply() {

uint32_t FuzzerPassInterchangeSignednessOfIntegerOperands::
FindOrCreateToggledIntegerConstant(uint32_t id) {
// |id| must not be a specialization constant because we do not know the value
// of specialization constants.
if (opt::IsSpecConstantInst(
GetIRContext()->get_def_use_mgr()->GetDef(id)->opcode())) {
return 0;
}

auto constant = GetIRContext()->get_constant_mgr()->FindDeclaredConstant(id);

// This pass only toggles integer constants.
Expand Down
8 changes: 7 additions & 1 deletion source/fuzz/fuzzer_pass_interchange_zero_like_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ FuzzerPassInterchangeZeroLikeConstants::

uint32_t FuzzerPassInterchangeZeroLikeConstants::FindOrCreateToggledConstant(
opt::Instruction* declaration) {
// |declaration| must not be a specialization constant because we do not know
// the value of specialization constants.
if (opt::IsSpecConstantInst(declaration->opcode())) {
return 0;
}

auto constant = GetIRContext()->get_constant_mgr()->FindDeclaredConstant(
declaration->result_id());

Expand Down Expand Up @@ -107,4 +113,4 @@ void FuzzerPassInterchangeZeroLikeConstants::Apply() {
}
}
} // namespace fuzz
} // namespace spvtools
} // namespace spvtools

0 comments on commit d08090b

Please sign in to comment.