1 //===-- nsan_flags.cc -----------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file is a part of NumericalStabilitySanitizer.
11 //===----------------------------------------------------------------------===//
13 #include "nsan_flags.h"
15 #include "sanitizer_common/sanitizer_flag_parser.h"
16 #include "sanitizer_common/sanitizer_flags.h"
18 using namespace __sanitizer
;
19 using namespace __nsan
;
21 SANITIZER_INTERFACE_WEAK_DEF(const char *, __nsan_default_options
, void) {
25 Flags
__nsan::flags_data
;
27 void Flags::SetDefaults() {
28 #define NSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
29 #include "nsan_flags.inc"
33 void Flags::PopulateCache() {
34 cached_absolute_error_threshold
=
35 1.0 / (1ull << log2_absolute_error_threshold
);
38 static 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"
45 static const char *MaybeCallNsanDefaultOptions() {
46 return (&__nsan_default_options
) ? __nsan_default_options() : "";
49 void __nsan::InitializeFlags() {
50 SetCommonFlagsDefaults();
53 cf
.CopyFrom(*common_flags());
54 cf
.external_symbolizer_path
= GetEnv("NSAN_SYMBOLIZER_PATH");
55 OverrideCommonFlags(cf
);
58 flags().SetDefaults();
61 RegisterCommonFlags(&parser
);
62 RegisterNSanFlags(&parser
, &flags());
64 const char *nsan_default_options
= MaybeCallNsanDefaultOptions();
65 parser
.ParseString(nsan_default_options
);
67 parser
.ParseString(GetEnv("NSAN_OPTIONS"));
68 InitializeCommonFlags();
70 ReportUnrecognizedFlags();
71 if (common_flags()->help
)
72 parser
.PrintFlagDescriptions();
74 flags().PopulateCache();