brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 94e3a18 Raw
76 lines · cpp
1//===-- nsan_flags.cc -----------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8//9// This file is a part of NumericalStabilitySanitizer.10//11//===----------------------------------------------------------------------===//12 13#include "nsan_flags.h"14 15#include "sanitizer_common/sanitizer_flag_parser.h"16#include "sanitizer_common/sanitizer_flags.h"17 18using namespace __sanitizer;19using namespace __nsan;20 21SANITIZER_INTERFACE_WEAK_DEF(const char *, __nsan_default_options, void) {22  return "";23}24 25Flags __nsan::flags_data;26 27void Flags::SetDefaults() {28#define NSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;29#include "nsan_flags.inc"30#undef NSAN_FLAG31}32 33void Flags::PopulateCache() {34  cached_absolute_error_threshold =35      1.0 / (1ull << log2_absolute_error_threshold);36}37 38static void RegisterNSanFlags(FlagParser *parser, Flags *f) {39#define NSAN_FLAG(Type, Name, DefaultValue, Description)                       \40  RegisterFlag(parser, #Name, Description, &f->Name);41#include "nsan_flags.inc"42#undef NSAN_FLAG43}44 45static const char *MaybeCallNsanDefaultOptions() {46  return (&__nsan_default_options) ? __nsan_default_options() : "";47}48 49void __nsan::InitializeFlags() {50  SetCommonFlagsDefaults();51  {52    CommonFlags cf;53    cf.CopyFrom(*common_flags());54    cf.external_symbolizer_path = GetEnv("NSAN_SYMBOLIZER_PATH");55    OverrideCommonFlags(cf);56  }57 58  flags().SetDefaults();59 60  FlagParser parser;61  RegisterCommonFlags(&parser);62  RegisterNSanFlags(&parser, &flags());63 64  const char *nsan_default_options = MaybeCallNsanDefaultOptions();65  parser.ParseString(nsan_default_options);66 67  parser.ParseString(GetEnv("NSAN_OPTIONS"));68  InitializeCommonFlags();69  if (Verbosity())70    ReportUnrecognizedFlags();71  if (common_flags()->help)72    parser.PrintFlagDescriptions();73 74  flags().PopulateCache();75}76