| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- // 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 "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;
- }
- LexedNumericLiteral::Parser parser(NullDiagnosticEmitter(), *token);
- if (parser.Check() == LexedNumericLiteral::Parser::UnrecoverableError) {
- // Lexically OK, but token is meaningless.
- return 0;
- }
- // Ensure we can exercise the various queries on a valid literal.
- volatile auto radix = parser.GetRadix();
- volatile auto mantissa = parser.GetMantissa();
- volatile auto exponent = parser.GetExponent();
- (void)radix;
- (void)mantissa;
- (void)exponent;
- return 0;
- }
- } // namespace Carbon
|