Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exempt the clang subcommand when fuzzing. #4468

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions toolchain/driver/clang_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ Arguments passed to Clang.
auto ClangSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
std::string target = llvm::sys::getDefaultTargetTriple();
ClangRunner runner(driver_env.installation, target, driver_env.vlog_stream);

// Don't run Clang when fuzzing, it is known to not be reliable under fuzzing
// due to many unfixed issues.
if (driver_env.fuzzing) {
driver_env.error_stream
<< "error: cannot run `clang` subcommand productively when fuzzing\n";
return {.success = false};
}

return {.success = runner.Run(options_.args)};
}

Expand Down
14 changes: 14 additions & 0 deletions toolchain/driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct Options {
auto Build(CommandLine::CommandBuilder& b) -> void;

bool verbose;
bool fuzzing;

ClangSubcommand clang;
CompileSubcommand compile;
Expand Down Expand Up @@ -63,6 +64,13 @@ auto Options::Build(CommandLine::CommandBuilder& b) -> void {
},
[&](CommandLine::FlagBuilder& arg_b) { arg_b.Set(&verbose); });

b.AddFlag(
{
.name = "fuzzing",
.help = "Configure the command line for fuzzing.",
},
[&](CommandLine::FlagBuilder& arg_b) { arg_b.Set(&fuzzing); });

b.AddSubcommand(ClangOptions::Info, [&](CommandLine::CommandBuilder& sub_b) {
clang.BuildOptions(sub_b);
sub_b.Do([&] { subcommand = &clang; });
Expand Down Expand Up @@ -109,8 +117,14 @@ auto Driver::RunCommand(llvm::ArrayRef<llvm::StringRef> args) -> DriverResult {
// Note this implies streamed output in order to interleave.
driver_env_.vlog_stream = &driver_env_.error_stream;
}
if (options.fuzzing) {
SetFuzzing();
}

CARBON_CHECK(options.subcommand != nullptr);
return options.subcommand->Run(driver_env_);
}

auto Driver::SetFuzzing() -> void { driver_env_.fuzzing = true; }

} // namespace Carbon
4 changes: 4 additions & 0 deletions toolchain/driver/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class Driver {
// error stream (stderr by default).
auto RunCommand(llvm::ArrayRef<llvm::StringRef> args) -> DriverResult;

// Configure the driver for fuzzing. This allows specific commands to error
// rather than perform operations that aren't well behaved during fuzzing.
auto SetFuzzing() -> void;

private:
DriverEnv driver_env_;
};
Expand Down
3 changes: 3 additions & 0 deletions toolchain/driver/driver_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ struct DriverEnv {

// For CARBON_VLOG.
llvm::raw_pwrite_stream* vlog_stream = nullptr;

// Tracks when the driver is being fuzzed.
bool fuzzing = false;
};

} // namespace Carbon
Expand Down
1 change: 1 addition & 0 deletions toolchain/driver/driver_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ extern "C" auto LLVMFuzzerTestOneInput(const unsigned char* data, size_t size)
TestRawOstream error_stream;
llvm::raw_null_ostream dest;
Driver d(fs, install_paths, dest, error_stream);
d.SetFuzzing();
if (!d.RunCommand(args).success) {
auto str = error_stream.TakeStr();
// TODO: Fix command_line to use `error`, switch back to `find`.
Expand Down
Loading