[fuzzer] Do not generate void expressions in sizeof (#132)
diff --git a/tools/fuzzer/constraints.cc b/tools/fuzzer/constraints.cc
index 5a4146f..1c58736 100644
--- a/tools/fuzzer/constraints.cc
+++ b/tools/fuzzer/constraints.cc
@@ -228,9 +228,7 @@
}
if (std::holds_alternative<AnyType>(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 51acafc..5bda4de 100644
--- a/tools/fuzzer/constraints.h
+++ b/tools/fuzzer/constraints.h
@@ -92,9 +92,9 @@
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 8bce256..192a8cd 100644
--- a/tools/fuzzer/constraints_test.cc
+++ b/tools/fuzzer/constraints_test.cc
@@ -25,7 +25,7 @@
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 @@
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 @@
// 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 @@
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 @@
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 f8ed78b..a3c5a09 100644
--- a/tools/fuzzer/expr_gen.cc
+++ b/tools/fuzzer/expr_gen.cc
@@ -903,7 +903,7 @@
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 {};
}