mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 15:50:11 +01:00
* finished fuzzer and added fuzzverter util * fixed typo * renamed cmd line params * fixed libproto_mutator download path * small fixes * small fixes * small fixes * renamed sample corpus proto * small fixes * try building on github with LIBCPP_DEBUG enabled * temporarily marked proto fuzzer as a manual test * code review * use a dedicated proto-fuzzer feature to work around LIBCPP_DEBUG=1 crash in proto code * code review comments, added README.md * minor fixes to the text * Update bazel/cc_toolchains/clang_cc_toolchain_config.bzl Co-authored-by: Jon Meow <jperkins@google.com> * use Carbon source representation for "empty Main()" instead of text format proto representation * fixed typo * made FuzzerUtil produce the full carbon source (proto converted + Main if needed) to decrease code duplication a bit * typo * switched to text proto format per code review * Update executable_semantics/prelude.h Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/fuzzing/README.md Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/fuzzing/README.md Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/fuzzing/README.md Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/fuzzing/README.md Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/fuzzing/README.md Co-authored-by: Jon Meow <jperkins@google.com> * review comments * removed unnecessary file mode variables * Update executable_semantics/fuzzing/fuzzverter.cpp Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/fuzzing/README.md Co-authored-by: Jon Meow <jperkins@google.com> * Update executable_semantics/fuzzing/README.md Co-authored-by: Jon Meow <jperkins@google.com> * code review comments * Update executable_semantics/syntax/BUILD Co-authored-by: Jon Meow <jperkins@google.com> * buildifier Co-authored-by: Jon Meow <jperkins@google.com>
43 lines
1.5 KiB
C++
43 lines
1.5 KiB
C++
// 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 <google/protobuf/text_format.h>
|
|
#include <libprotobuf_mutator/src/libfuzzer/libfuzzer_macro.h>
|
|
|
|
#include "common/fuzzing/carbon.pb.h"
|
|
#include "executable_semantics/fuzzing/fuzzer_util.h"
|
|
#include "executable_semantics/interpreter/exec_program.h"
|
|
#include "executable_semantics/syntax/parse.h"
|
|
#include "executable_semantics/syntax/prelude.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// Parses and executes a fuzzer-generated program.
|
|
void ParseAndExecute(const Fuzzing::CompilationUnit& compilation_unit) {
|
|
const std::string source = ProtoToCarbonWithMain(compilation_unit);
|
|
|
|
Arena arena;
|
|
ErrorOr<AST> ast = ParseFromString(&arena, "Fuzzer.carbon", source,
|
|
/*trace=*/false);
|
|
if (!ast.ok()) {
|
|
llvm::errs() << "Parsing failed: " << ast.error().message() << "\n";
|
|
return;
|
|
}
|
|
AddPrelude("executable_semantics/data/prelude.carbon", &arena,
|
|
&ast->declarations);
|
|
const ErrorOr<int> result = ExecProgram(&arena, *ast, /*trace=*/false);
|
|
if (!result.ok()) {
|
|
llvm::errs() << "Execution failed: " << result.error().message() << "\n";
|
|
return;
|
|
}
|
|
llvm::outs() << "Executed OK: " << *result << "\n";
|
|
}
|
|
|
|
} // namespace Carbon
|
|
|
|
DEFINE_TEXT_PROTO_FUZZER(const Carbon::Fuzzing::Carbon& input) {
|
|
Carbon::ParseAndExecute(input.compilation_unit());
|
|
}
|