]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/ubsan/ubsan_flags.cc
Merge libc++ trunk r338150, and resolve conflicts.
[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 #include <stdlib.h>
22
23 namespace __ubsan {
24
25 const char *MaybeCallUbsanDefaultOptions() {
26   return (&__ubsan_default_options) ? __ubsan_default_options() : "";
27 }
28
29 Flags ubsan_flags;
30
31 void Flags::SetDefaults() {
32 #define UBSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
33 #include "ubsan_flags.inc"
34 #undef UBSAN_FLAG
35 }
36
37 void RegisterUbsanFlags(FlagParser *parser, Flags *f) {
38 #define UBSAN_FLAG(Type, Name, DefaultValue, Description) \
39   RegisterFlag(parser, #Name, Description, &f->Name);
40 #include "ubsan_flags.inc"
41 #undef UBSAN_FLAG
42 }
43
44 void InitializeFlags() {
45   SetCommonFlagsDefaults();
46   {
47     CommonFlags cf;
48     cf.CopyFrom(*common_flags());
49     cf.print_summary = false;
50     cf.external_symbolizer_path = getenv("UBSAN_SYMBOLIZER_PATH");
51     OverrideCommonFlags(cf);
52   }
53
54   Flags *f = flags();
55   f->SetDefaults();
56
57   FlagParser parser;
58   RegisterCommonFlags(&parser);
59   RegisterUbsanFlags(&parser, f);
60
61   // Override from user-specified string.
62   parser.ParseString(MaybeCallUbsanDefaultOptions());
63   // Override from environment variable.
64   parser.ParseString(getenv("UBSAN_OPTIONS"));
65   InitializeCommonFlags();
66   if (Verbosity()) ReportUnrecognizedFlags();
67
68   if (common_flags()->help) parser.PrintFlagDescriptions();
69 }
70
71 }  // namespace __ubsan
72
73 SANITIZER_INTERFACE_WEAK_DEF(const char *, __ubsan_default_options, void) {
74   return "";
75 }
76
77 #endif  // CAN_SANITIZE_UB