Skip to content

Commit cc5958e

Browse files
authored
[fuzzer] Do not generate void expressions in sizeof (#132)
1 parent 4317381 commit cc5958e

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

tools/fuzzer/constraints.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,7 @@ TypeConstraints TypeConstraints::allowed_to_point_to() const {
228228
}
229229

230230
if (std::holds_alternative<AnyType>(ptr_types_)) {
231-
TypeConstraints retval = TypeConstraints::all();
232-
retval.scalar_types_[ScalarType::Void] = false;
233-
return retval;
231+
return TypeConstraints::all_non_void();
234232
}
235233

236234
const auto* specific_types_ptr =

tools/fuzzer/constraints.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ class TypeConstraints {
9292
return retval;
9393
}
9494

95-
static TypeConstraints all() {
95+
static TypeConstraints all_non_void() {
9696
TypeConstraints retval;
97-
retval.scalar_types_ = ScalarMask::all_set();
97+
retval.scalar_types_ = ~ScalarMask(ScalarType::Void);
9898
retval.tagged_types_ = AnyType{};
9999
retval.ptr_types_ = AnyType{};
100100
retval.array_types_ = AnyType{};

tools/fuzzer/constraints_test.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ TEST(Constraints, ScalarValues) {
2525
TypeConstraints float_only = FLOAT_TYPES;
2626
TypeConstraints int_only = INT_TYPES;
2727

28-
TypeConstraints any = TypeConstraints::all();
28+
TypeConstraints any = TypeConstraints::all_non_void();
2929
TypeConstraints none;
3030

3131
PointerType void_ptr_type{QualifiedType(ScalarType::Void)};
@@ -85,7 +85,7 @@ TEST(Constraints, TaggedTypes) {
8585
EXPECT_THAT(test_struct.allows_non_void_pointer(), IsFalse());
8686
EXPECT_THAT(test_struct.allows_void_pointer(), IsFalse());
8787

88-
TypeConstraints any = TypeConstraints::all();
88+
TypeConstraints any = TypeConstraints::all_non_void();
8989
TypeConstraints none;
9090

9191
EXPECT_THAT(any.allows_tagged_types(), IsTrue());
@@ -159,7 +159,7 @@ TEST(Constraints, PointerTypes) {
159159
// void types :(
160160
EXPECT_THAT(void_constraints.allows_any_of(ScalarType::Void), IsFalse());
161161

162-
TypeConstraints any = TypeConstraints::all();
162+
TypeConstraints any = TypeConstraints::all_non_void();
163163
TypeConstraints none;
164164

165165
EXPECT_THAT(any.allows_type(const_int_ptr), IsTrue());
@@ -176,7 +176,7 @@ TEST(Constraints, EnumTypes) {
176176
EnumType unscoped_enum("UnscopedEnum", false);
177177
EnumType specific_enum("SpecificEnum", true);
178178

179-
TypeConstraints any = TypeConstraints::all();
179+
TypeConstraints any = TypeConstraints::all_non_void();
180180
TypeConstraints none;
181181
TypeConstraints bool_ctx = TypeConstraints::all_in_bool_ctx();
182182
TypeConstraints only_specific = TypeConstraints(specific_enum);
@@ -217,7 +217,7 @@ TEST(Constraints, ArrayTypes) {
217217
ArrayType array_of_ptrs = ArrayType(int_ptr, 3);
218218
PointerType ptr_to_array = PointerType(QualifiedType(array_of_three));
219219

220-
TypeConstraints any = TypeConstraints::all();
220+
TypeConstraints any = TypeConstraints::all_non_void();
221221
EXPECT_THAT(any.allows_type(array_of_three), IsTrue());
222222
EXPECT_THAT(any.allows_type(array_of_four), IsTrue());
223223
EXPECT_THAT(any.allows_type(array2d), IsTrue());

tools/fuzzer/expr_gen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ std::optional<Expr> ExprGenerator::gen_sizeof_expr_impl(
903903
return SizeofExpr(std::move(maybe_type.value()));
904904
}
905905

906-
auto maybe_expr = gen_with_weights(weights, TypeConstraints::all());
906+
auto maybe_expr = gen_with_weights(weights, TypeConstraints::all_non_void());
907907
if (!maybe_expr.has_value()) {
908908
return {};
909909
}

0 commit comments

Comments
 (0)