Files
carbon-lang/lexer/numeric_literal_fuzzer.cpp
T
Richard Smith 9325b50cfe Make numeric literal parsing interface more value-oriented. (#407)
Instead of exposing a stateful Parser type, expose only the result of
its parsing action. This also makes the numeric literal code better
mirror the string literal code.
2021-03-22 15:39:44 -07:00

32 lines
932 B
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 <cstdint>
#include <cstring>
#include "diagnostics/diagnostic_emitter.h"
#include "diagnostics/null_diagnostics.h"
#include "lexer/numeric_literal.h"
#include "llvm/ADT/StringRef.h"
namespace Carbon {
// NOLINTNEXTLINE: Match the documented fuzzer entry point declaration style.
extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data,
std::size_t size) {
auto token = LexedNumericLiteral::Lex(
llvm::StringRef(reinterpret_cast<const char*>(data), size));
if (!token) {
// Lexically not a numeric literal.
return 0;
}
volatile auto value =
token->ComputeValue(NullDiagnosticEmitter<const char*>());
(void)value;
return 0;
}
} // namespace Carbon