numeric_literal_fuzzer.cpp 944 B

123456789101112131415161718192021222324252627282930
  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 <cstring>
  5. #include "llvm/ADT/StringRef.h"
  6. #include "testing/fuzzing/libfuzzer.h"
  7. #include "toolchain/diagnostics/null_diagnostics.h"
  8. #include "toolchain/lex/numeric_literal.h"
  9. namespace Carbon::Testing {
  10. // NOLINTNEXTLINE: Match the documented fuzzer entry point declaration style.
  11. extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data,
  12. std::size_t size) {
  13. auto token = Lex::NumericLiteral::Lex(
  14. llvm::StringRef(reinterpret_cast<const char*>(data), size));
  15. if (!token) {
  16. // Lexically not a numeric literal.
  17. return 0;
  18. }
  19. volatile auto value =
  20. token->ComputeValue(NullDiagnosticEmitter<const char*>());
  21. (void)value;
  22. return 0;
  23. }
  24. } // namespace Carbon::Testing