]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/ubsan/ubsan_flags.cc
Merge ACPICA 20170929.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / ubsan / ubsan_flags.cc
1 //===-- ubsan_flags.cc ----------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Runtime flags for UndefinedBehaviorSanitizer.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ubsan_platform.h"
15 #if CAN_SANITIZE_UB
16 #include "ubsan_flags.h"
17 #include "sanitizer_common/sanitizer_common.h"
18 #include "sanitizer_common/sanitizer_flags.h"
19 #include "sanitizer_common/sanitizer_flag_parser.h"
20
21 namespace __ubsan {
22
23 const char *MaybeCallUbsanDefaultOptions() {
24   return (&__ubsan_default_options) ? __ubsan_default_options() : "";
25 }
26
27 Flags ubsan_flags;
28
29 void Flags::SetDefaults() {
30 #define UBSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
31 #include "ubsan_flags.inc"
32 #undef UBSAN_FLAG
33 }
34
35 void RegisterUbsanFlags(FlagParser *parser, Flags *f) {
36 #define UBSAN_FLAG(Type, Name, DefaultValue, Description) \
37   RegisterFlag(parser, #Name, Description, &f->Name);
38 #include "ubsan_flags.inc"
39 #undef UBSAN_FLAG
40 }
41
42 void InitializeFlags() {
43   SetCommonFlagsDefaults();
44   {
45     CommonFlags cf;
46     cf.CopyFrom(*common_flags());
47     cf.print_summary = false;
48     cf.external_symbolizer_path = GetEnv("UBSAN_SYMBOLIZER_PATH");
49     OverrideCommonFlags(cf);
50   }
51
52   Flags *f = flags();
53   f->SetDefaults();
54
55   FlagParser parser;
56   RegisterCommonFlags(&parser);
57   RegisterUbsanFlags(&parser, f);
58
59   // Override from user-specified string.
60   parser.ParseString(MaybeCallUbsanDefaultOptions());
61   // Override from environment variable.
62   parser.ParseString(GetEnv("UBSAN_OPTIONS"));
63   InitializeCommonFlags();
64   if (Verbosity()) ReportUnrecognizedFlags();
65
66   if (common_flags()->help) parser.PrintFlagDescriptions();
67 }
68
69 }  // namespace __ubsan
70
71 SANITIZER_INTERFACE_WEAK_DEF(const char *, __ubsan_default_options, void) {
72   return "";
73 }
74
75 #endif  // CAN_SANITIZE_UB