numeric_literal_fuzzer.cpp 910 B

1234567891011121314151617181920212223242526272829
  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, size_t size) {
  12. auto token = Lex::NumericLiteral::Lex(
  13. llvm::StringRef(reinterpret_cast<const char*>(data), size), true);
  14. if (!token) {
  15. // Lexically not a numeric literal.
  16. return 0;
  17. }
  18. volatile auto value =
  19. token->ComputeValue(Diagnostics::NullEmitter<const char*>());
  20. (void)value;
  21. return 0;
  22. }
  23. } // namespace Carbon::Testing