sancov_flags.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //===-- sancov_flags.cpp ----------------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Sanitizer Coverage runtime flags.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "sancov_flags.h"
  13. #include "sanitizer_flag_parser.h"
  14. #include "sanitizer_platform.h"
  15. SANITIZER_INTERFACE_WEAK_DEF(const char*, __sancov_default_options, void) {
  16. return "";
  17. }
  18. using namespace __sanitizer;
  19. namespace __sancov {
  20. SancovFlags sancov_flags_dont_use_directly; // use via flags();
  21. void SancovFlags::SetDefaults() {
  22. #define SANCOV_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
  23. #include "sancov_flags.inc"
  24. #undef SANCOV_FLAG
  25. }
  26. static void RegisterSancovFlags(FlagParser *parser, SancovFlags *f) {
  27. #define SANCOV_FLAG(Type, Name, DefaultValue, Description) \
  28. RegisterFlag(parser, #Name, Description, &f->Name);
  29. #include "sancov_flags.inc"
  30. #undef SANCOV_FLAG
  31. }
  32. static const char *MaybeCallSancovDefaultOptions() {
  33. return (&__sancov_default_options) ? __sancov_default_options() : "";
  34. }
  35. void InitializeSancovFlags() {
  36. SancovFlags *f = sancov_flags();
  37. f->SetDefaults();
  38. FlagParser parser;
  39. RegisterSancovFlags(&parser, f);
  40. parser.ParseString(MaybeCallSancovDefaultOptions());
  41. parser.ParseStringFromEnv("SANCOV_OPTIONS");
  42. ReportUnrecognizedFlags();
  43. if (f->help) parser.PrintFlagDescriptions();
  44. }
  45. } // namespace __sancov