mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 19:50:14 +01:00
Factor out fuzzing disablement in the driver (#5048)
We end up needing to do this in any driver subcommand that reaches into external code that may not be fully fuzz-clean. No need to grow multiple different diagnostics for each, we can use a common diagnostic.
This commit is contained in:
@@ -23,13 +23,12 @@
|
||||
|
||||
CARBON_DIAGNOSTIC_KIND(DriverInstallInvalid)
|
||||
CARBON_DIAGNOSTIC_KIND(DriverCommandLineParseFailed)
|
||||
CARBON_DIAGNOSTIC_KIND(ClangFuzzingDisallowed)
|
||||
CARBON_DIAGNOSTIC_KIND(CompilePhaseFlagConflict)
|
||||
CARBON_DIAGNOSTIC_KIND(CompilePreludeManifestError)
|
||||
CARBON_DIAGNOSTIC_KIND(CompileInputNotRegularFile)
|
||||
CARBON_DIAGNOSTIC_KIND(CompileOutputFileOpenError)
|
||||
CARBON_DIAGNOSTIC_KIND(FormatMultipleFilesToOneOutput)
|
||||
CARBON_DIAGNOSTIC_KIND(LLDFuzzingDisallowed)
|
||||
CARBON_DIAGNOSTIC_KIND(ToolFuzzingDisallowed)
|
||||
|
||||
// ============================================================================
|
||||
// SourceBuffer diagnostics
|
||||
|
||||
@@ -95,6 +95,7 @@ cc_library(
|
||||
"compile_subcommand.h",
|
||||
"driver.cpp",
|
||||
"driver_env.h",
|
||||
"driver_subcommand.cpp",
|
||||
"format_subcommand.cpp",
|
||||
"format_subcommand.h",
|
||||
"language_server_subcommand.cpp",
|
||||
|
||||
@@ -50,11 +50,7 @@ auto ClangSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
|
||||
|
||||
// Don't run Clang when fuzzing, it is known to not be reliable under fuzzing
|
||||
// due to many unfixed issues.
|
||||
if (driver_env.fuzzing) {
|
||||
CARBON_DIAGNOSTIC(
|
||||
ClangFuzzingDisallowed, Error,
|
||||
"preventing fuzzing of `clang` subcommand due to library crashes");
|
||||
driver_env.emitter.Emit(ClangFuzzingDisallowed);
|
||||
if (!DisableFuzzingExternalLibraries(driver_env, "clang")) {
|
||||
return {.success = false};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#include "toolchain/driver/driver_subcommand.h"
|
||||
|
||||
#include "llvm/TargetParser/Host.h"
|
||||
#include "llvm/TargetParser/Triple.h"
|
||||
#include "toolchain/driver/lld_runner.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto DriverSubcommand::DisableFuzzingExternalLibraries(DriverEnv& driver_env,
|
||||
llvm::StringRef name)
|
||||
-> bool {
|
||||
// Only need to do anything when fuzzing.
|
||||
if (!driver_env.fuzzing) {
|
||||
return true;
|
||||
}
|
||||
|
||||
CARBON_DIAGNOSTIC(
|
||||
ToolFuzzingDisallowed, Error,
|
||||
"preventing fuzzing of `{0}` subcommand due to external library",
|
||||
std::string);
|
||||
driver_env.emitter.Emit(ToolFuzzingDisallowed, name.str());
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
@@ -45,6 +45,15 @@ class DriverSubcommand {
|
||||
// Runs the command.
|
||||
virtual auto Run(DriverEnv& driver_env) -> DriverResult = 0;
|
||||
|
||||
protected:
|
||||
// Diagnoses and returns false if currently fuzzing.
|
||||
//
|
||||
// This should be used in subcommands to check and diagnose rather than
|
||||
// entering them during fuzzing when they use external libraries that we can't
|
||||
// keep fuzz-clean.
|
||||
auto DisableFuzzingExternalLibraries(DriverEnv& driver_env,
|
||||
llvm::StringRef name) -> bool;
|
||||
|
||||
private:
|
||||
// Subcommand information.
|
||||
CommandLine::CommandInfo info_;
|
||||
|
||||
@@ -93,11 +93,7 @@ auto LldSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
|
||||
|
||||
// Don't run LLD when fuzzing, as we're not currently in a good position to
|
||||
// debug and fix fuzzer-found bugs within LLD.
|
||||
if (driver_env.fuzzing) {
|
||||
CARBON_DIAGNOSTIC(
|
||||
LLDFuzzingDisallowed, Error,
|
||||
"preventing fuzzing of `lld` subcommand due to external library");
|
||||
driver_env.emitter.Emit(LLDFuzzingDisallowed);
|
||||
if (!DisableFuzzingExternalLibraries(driver_env, "lld")) {
|
||||
return {.success = false};
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -11,5 +11,5 @@
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/driver/testdata/fail_clang_fuzzing.cpp
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/driver/testdata/fail_clang_fuzzing.cpp
|
||||
// CHECK:STDERR: error: preventing fuzzing of `clang` subcommand due to library crashes [ClangFuzzingDisallowed]
|
||||
// CHECK:STDERR: error: preventing fuzzing of `clang` subcommand due to external library [ToolFuzzingDisallowed]
|
||||
// CHECK:STDERR:
|
||||
|
||||
+1
-1
@@ -11,5 +11,5 @@
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/driver/testdata/fail_lld_fuzzing.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/driver/testdata/fail_lld_fuzzing.carbon
|
||||
// CHECK:STDERR: error: preventing fuzzing of `lld` subcommand due to external library [LLDFuzzingDisallowed]
|
||||
// CHECK:STDERR: error: preventing fuzzing of `lld` subcommand due to external library [ToolFuzzingDisallowed]
|
||||
// CHECK:STDERR:
|
||||
|
||||
Reference in New Issue
Block a user