Skip to content

Commit 87860f4

Browse files
authored
[fuzzer] Fix Linux specific issues (#142)
1 parent d96cefe commit 87860f4

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

testdata/rules.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def binary_gen(name, srcs):
3838
platform_opts = "--for-linker -debug:dwarf",
3939
),
4040
"//conditions:default": build_cmd.format(
41-
platform_opts = "-lstdc++",
41+
# Using "-static" prevents fuzzer_binary from using __log2
42+
# function from libm.so.
43+
platform_opts = "-lstdc++ -static",
4244
),
4345
}),
4446
tags = ["no-sandbox"],

tools/fuzzer/expr_gen.cc

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ std::optional<Expr> ExprGenerator::gen_variable_expr_impl(
200200

201201
std::vector<std::reference_wrapper<const VariableExpr>> vars;
202202
for (const auto& [k, v] : symtab_.vars()) {
203+
// Skip long double variables if long double isn't enabled.
204+
if (!cfg_.long_double_enabled && k == Type(ScalarType::LongDouble)) {
205+
continue;
206+
}
207+
203208
if (type_constraints.allows_type(k)) {
204209
for (const auto& var : v) {
205210
if (var.expr.name() == "this" && constraints.must_be_lvalue()) {
@@ -729,12 +734,21 @@ std::optional<Expr> ExprGenerator::gen_member_of_ptr_expr_impl(
729734

730735
Field field = rng_->pick_field(fields);
731736
TypeConstraints new_type_constraints(field.containing_type());
732-
// If the field is a reference or a virtually inherited field, assume a read
733-
// from memory.
734-
MemoryConstraints new_memory_constraints =
735-
field.is_reference_or_virtual()
736-
? MemoryConstraints(true, 1)
737-
: memory_constraints.from_member_of(constraints.must_be_lvalue(), 1);
737+
738+
// `&(ptr)->field` is equivalent to `ptr + offset(field)` where offset can
739+
// be determined statically if the `field` isn't a reference or a virtually
740+
// inherited field (in these cases a read from memory is expected). However,
741+
// lldb-eval doesn't support address-of elision for member-of expressions,
742+
// so assume a read from memory in all cases.
743+
MemoryConstraints new_memory_constraints(true, 1);
744+
745+
// TODO: Uncomment the following code once lldb-eval supports address-of
746+
// elision for member-of expressions.
747+
// MemoryConstraints new_memory_constraints =
748+
// field.is_reference_or_virtual() ? MemoryConstraints(true, 1)
749+
// : memory_constraints.from_member_of(
750+
// constraints.must_be_lvalue(), 1);
751+
738752
ExprConstraints new_constraints =
739753
ExprConstraints(new_type_constraints.make_pointer_constraints(),
740754
std::move(new_memory_constraints));
@@ -1267,6 +1281,11 @@ std::optional<Type> ExprGenerator::gen_tagged_type(
12671281
std::optional<Type> ExprGenerator::gen_scalar_type(
12681282
const TypeConstraints& constraints) {
12691283
ScalarMask mask = constraints.allowed_scalar_types();
1284+
1285+
if (!cfg_.long_double_enabled) {
1286+
mask[ScalarType::LongDouble] = false;
1287+
}
1288+
12701289
if (mask.none()) {
12711290
return {};
12721291
}

tools/fuzzer/expr_gen.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ struct GenConfig {
152152
// from memory is expected.
153153
bool valid_pointer_cast_enabled = false;
154154

155+
// Long double may not work properly in lldb-eval yet.
156+
bool long_double_enabled = false;
157+
155158
BinOpMask bin_op_mask = BinOpMask::all_set();
156159
UnOpMask un_op_mask = UnOpMask::all_set();
157160

0 commit comments

Comments
 (0)