numeric_literal_fuzzer.cpp 980 B

12345678910111213141516171819202122232425262728293031
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include <cstdint>
  5. #include <cstring>
  6. #include "llvm/ADT/StringRef.h"
  7. #include "toolchain/diagnostics/diagnostic_emitter.h"
  8. #include "toolchain/diagnostics/null_diagnostics.h"
  9. #include "toolchain/lexer/numeric_literal.h"
  10. namespace Carbon::Testing {
  11. // NOLINTNEXTLINE: Match the documented fuzzer entry point declaration style.
  12. extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data,
  13. std::size_t size) {
  14. auto token = LexedNumericLiteral::Lex(
  15. llvm::StringRef(reinterpret_cast<const char*>(data), size));
  16. if (!token) {
  17. // Lexically not a numeric literal.
  18. return 0;
  19. }
  20. volatile auto value =
  21. token->ComputeValue(NullDiagnosticEmitter<const char*>());
  22. (void)value;
  23. return 0;
  24. }
  25. } // namespace Carbon::Testing