spirv-fuzz: Fix TransformationRecordSynonymousConstants (#3868)
Fixes #3866.
diff --git a/source/fuzz/transformation_record_synonymous_constants.cpp b/source/fuzz/transformation_record_synonymous_constants.cpp
index 85c629c..30ea94b 100644
--- a/source/fuzz/transformation_record_synonymous_constants.cpp
+++ b/source/fuzz/transformation_record_synonymous_constants.cpp
@@ -81,7 +81,10 @@
auto constant1 = ir_context->get_constant_mgr()->GetConstantFromInst(def_1);
auto constant2 = ir_context->get_constant_mgr()->GetConstantFromInst(def_2);
- assert(constant1 && constant2 && "The ids must refer to constants.");
+ // The ids must refer to constants.
+ if (!constant1 || !constant2) {
+ return false;
+ }
// The types must be compatible.
if (!fuzzerutil::TypesAreEqualUpToSign(ir_context, def_1->type_id(),
@@ -100,11 +103,14 @@
// If the constants are scalar, they are equal iff their words are the same
if (auto scalar1 = constant1->AsScalarConstant()) {
+ // Either both or neither constant is scalar since we've already checked
+ // that their types are compatible.
+ assert(constant2->AsScalarConstant() && "Both constants must be scalar");
return scalar1->words() == constant2->AsScalarConstant()->words();
}
// The only remaining possibility is that the constants are composite
- assert(constant1->AsCompositeConstant() &&
+ assert(constant1->AsCompositeConstant() && constant2->AsCompositeConstant() &&
"Equivalence of constants can only be checked with scalar, composite "
"or null constants.");
diff --git a/test/fuzz/transformation_record_synonymous_constants_test.cpp b/test/fuzz/transformation_record_synonymous_constants_test.cpp
index c340029..ffc5f9a 100644
--- a/test/fuzz/transformation_record_synonymous_constants_test.cpp
+++ b/test/fuzz/transformation_record_synonymous_constants_test.cpp
@@ -90,19 +90,11 @@
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
-#ifndef NDEBUG
// %3 is not a constant declaration
- ASSERT_DEATH(TransformationRecordSynonymousConstants(3, 9).IsApplicable(
- context.get(), transformation_context),
- "The ids must refer to constants.");
-#endif
-
-#ifndef NDEBUG
- // %3 is not a constant declaration
- ASSERT_DEATH(TransformationRecordSynonymousConstants(9, 3).IsApplicable(
- context.get(), transformation_context),
- "The ids must refer to constants.");
-#endif
+ ASSERT_FALSE(TransformationRecordSynonymousConstants(3, 9).IsApplicable(
+ context.get(), transformation_context));
+ ASSERT_FALSE(TransformationRecordSynonymousConstants(9, 3).IsApplicable(
+ context.get(), transformation_context));
// The two constants must be different
ASSERT_FALSE(TransformationRecordSynonymousConstants(9, 9).IsApplicable(