diff --git a/tools/fuzzer/constraints.cc b/tools/fuzzer/constraints.cc index 5a4146fd..1c587366 100644 --- a/tools/fuzzer/constraints.cc +++ b/tools/fuzzer/constraints.cc @@ -228,9 +228,7 @@ TypeConstraints TypeConstraints::allowed_to_point_to() const { } if (std::holds_alternative(ptr_types_)) { - TypeConstraints retval = TypeConstraints::all(); - retval.scalar_types_[ScalarType::Void] = false; - return retval; + return TypeConstraints::all_non_void(); } const auto* specific_types_ptr = diff --git a/tools/fuzzer/constraints.h b/tools/fuzzer/constraints.h index 51acafc7..5bda4de2 100644 --- a/tools/fuzzer/constraints.h +++ b/tools/fuzzer/constraints.h @@ -92,9 +92,9 @@ class TypeConstraints { return retval; } - static TypeConstraints all() { + static TypeConstraints all_non_void() { TypeConstraints retval; - retval.scalar_types_ = ScalarMask::all_set(); + retval.scalar_types_ = ~ScalarMask(ScalarType::Void); retval.tagged_types_ = AnyType{}; retval.ptr_types_ = AnyType{}; retval.array_types_ = AnyType{}; diff --git a/tools/fuzzer/constraints_test.cc b/tools/fuzzer/constraints_test.cc index 8bce2566..192a8cdf 100644 --- a/tools/fuzzer/constraints_test.cc +++ b/tools/fuzzer/constraints_test.cc @@ -25,7 +25,7 @@ TEST(Constraints, ScalarValues) { TypeConstraints float_only = FLOAT_TYPES; TypeConstraints int_only = INT_TYPES; - TypeConstraints any = TypeConstraints::all(); + TypeConstraints any = TypeConstraints::all_non_void(); TypeConstraints none; PointerType void_ptr_type{QualifiedType(ScalarType::Void)}; @@ -85,7 +85,7 @@ TEST(Constraints, TaggedTypes) { EXPECT_THAT(test_struct.allows_non_void_pointer(), IsFalse()); EXPECT_THAT(test_struct.allows_void_pointer(), IsFalse()); - TypeConstraints any = TypeConstraints::all(); + TypeConstraints any = TypeConstraints::all_non_void(); TypeConstraints none; EXPECT_THAT(any.allows_tagged_types(), IsTrue()); @@ -159,7 +159,7 @@ TEST(Constraints, PointerTypes) { // void types :( EXPECT_THAT(void_constraints.allows_any_of(ScalarType::Void), IsFalse()); - TypeConstraints any = TypeConstraints::all(); + TypeConstraints any = TypeConstraints::all_non_void(); TypeConstraints none; EXPECT_THAT(any.allows_type(const_int_ptr), IsTrue()); @@ -176,7 +176,7 @@ TEST(Constraints, EnumTypes) { EnumType unscoped_enum("UnscopedEnum", false); EnumType specific_enum("SpecificEnum", true); - TypeConstraints any = TypeConstraints::all(); + TypeConstraints any = TypeConstraints::all_non_void(); TypeConstraints none; TypeConstraints bool_ctx = TypeConstraints::all_in_bool_ctx(); TypeConstraints only_specific = TypeConstraints(specific_enum); @@ -217,7 +217,7 @@ TEST(Constraints, ArrayTypes) { ArrayType array_of_ptrs = ArrayType(int_ptr, 3); PointerType ptr_to_array = PointerType(QualifiedType(array_of_three)); - TypeConstraints any = TypeConstraints::all(); + TypeConstraints any = TypeConstraints::all_non_void(); EXPECT_THAT(any.allows_type(array_of_three), IsTrue()); EXPECT_THAT(any.allows_type(array_of_four), IsTrue()); EXPECT_THAT(any.allows_type(array2d), IsTrue()); diff --git a/tools/fuzzer/expr_gen.cc b/tools/fuzzer/expr_gen.cc index f8ed78bf..a3c5a098 100644 --- a/tools/fuzzer/expr_gen.cc +++ b/tools/fuzzer/expr_gen.cc @@ -903,7 +903,7 @@ std::optional ExprGenerator::gen_sizeof_expr_impl( return SizeofExpr(std::move(maybe_type.value())); } - auto maybe_expr = gen_with_weights(weights, TypeConstraints::all()); + auto maybe_expr = gen_with_weights(weights, TypeConstraints::all_non_void()); if (!maybe_expr.has_value()) { return {}; }