spirv-fuzz: Assert false in IsApplicable method of TransformationAccessChain (#3528)

… if it is invalid (with null or undefined pointer).

In this case, assert false instead of returning false so that the fuzzer fails.

Fixes #3185.
This commit is contained in:
Stefano Milizia 2020-07-17 11:57:36 +00:00 committed by GitHub
parent 680c77fa6c
commit de1ff50f28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 9 deletions

View File

@ -74,9 +74,9 @@ bool TransformationAccessChain::IsApplicable(
switch (pointer->opcode()) {
case SpvOpConstantNull:
case SpvOpUndef:
// TODO(https://github.com/KhronosGroup/SPIRV-Tools/issues/3185): When
// fuzzing for real we would like an 'assert(false)' here. But we also
// want to be able to write negative unit tests.
assert(
false &&
"Access chains should not be created from null/undefined pointers");
return false;
default:
break;

View File

@ -183,15 +183,23 @@ TEST(TransformationAccessChainTest, BasicTest) {
100, 43, {80}, MakeInstructionDescriptor(24, SpvOpLoad, 100))
.IsApplicable(context.get(), transformation_context));
#ifndef NDEBUG
// Bad: pointer is null
ASSERT_FALSE(TransformationAccessChain(
100, 45, {80}, MakeInstructionDescriptor(24, SpvOpLoad, 0))
.IsApplicable(context.get(), transformation_context));
ASSERT_DEATH(
TransformationAccessChain(100, 45, {80},
MakeInstructionDescriptor(24, SpvOpLoad, 0))
.IsApplicable(context.get(), transformation_context),
"Access chains should not be created from null/undefined pointers");
#endif
#ifndef NDEBUG
// Bad: pointer is undef
ASSERT_FALSE(TransformationAccessChain(
100, 46, {80}, MakeInstructionDescriptor(24, SpvOpLoad, 0))
.IsApplicable(context.get(), transformation_context));
ASSERT_DEATH(
TransformationAccessChain(100, 46, {80},
MakeInstructionDescriptor(24, SpvOpLoad, 0))
.IsApplicable(context.get(), transformation_context),
"Access chains should not be created from null/undefined pointers");
#endif
// Bad: pointer to result type does not exist
ASSERT_FALSE(TransformationAccessChain(