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-exception |
6 | // |
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 | |
18 | using namespace __sanitizer; |
19 | using namespace __nsan; |
20 | |
21 | SANITIZER_INTERFACE_WEAK_DEF(const char *, __nsan_default_options, void) { |
22 | return "" ; |
23 | } |
24 | |
25 | Flags __nsan::flags_data; |
26 | |
27 | void Flags::SetDefaults() { |
28 | #define NSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue; |
29 | #include "nsan_flags.inc" |
30 | #undef NSAN_FLAG |
31 | } |
32 | |
33 | void Flags::PopulateCache() { |
34 | cached_absolute_error_threshold = |
35 | 1.0 / (1ull << log2_absolute_error_threshold); |
36 | } |
37 | |
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" |
42 | #undef NSAN_FLAG |
43 | } |
44 | |
45 | static const char *MaybeCallNsanDefaultOptions() { |
46 | return (&__nsan_default_options) ? __nsan_default_options() : "" ; |
47 | } |
48 | |
49 | void __nsan::InitializeFlags() { |
50 | SetCommonFlagsDefaults(); |
51 | { |
52 | CommonFlags cf; |
53 | cf.CopyFrom(other: *common_flags()); |
54 | cf.external_symbolizer_path = GetEnv(name: "NSAN_SYMBOLIZER_PATH" ); |
55 | OverrideCommonFlags(cf); |
56 | } |
57 | |
58 | flags().SetDefaults(); |
59 | |
60 | FlagParser parser; |
61 | RegisterCommonFlags(parser: &parser); |
62 | RegisterNSanFlags(parser: &parser, f: &flags()); |
63 | |
64 | const char *nsan_default_options = MaybeCallNsanDefaultOptions(); |
65 | parser.ParseString(s: nsan_default_options); |
66 | |
67 | parser.ParseString(s: GetEnv(name: "NSAN_OPTIONS" )); |
68 | InitializeCommonFlags(); |
69 | if (Verbosity()) |
70 | ReportUnrecognizedFlags(); |
71 | if (common_flags()->help) |
72 | parser.PrintFlagDescriptions(); |
73 | |
74 | flags().PopulateCache(); |
75 | } |
76 | |