PR rtl-optimization/79386
[official-gcc.git] / libsanitizer / ubsan / ubsan_flags.cc
blob19f5de1727e12d7b87d5cdb41fa091cad4374f78
1 //===-- ubsan_flags.cc ----------------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // Runtime flags for UndefinedBehaviorSanitizer.
9 //
10 //===----------------------------------------------------------------------===//
12 #include "ubsan_platform.h"
13 #if CAN_SANITIZE_UB
14 #include "ubsan_flags.h"
15 #include "sanitizer_common/sanitizer_common.h"
16 #include "sanitizer_common/sanitizer_flags.h"
17 #include "sanitizer_common/sanitizer_flag_parser.h"
19 namespace __ubsan {
21 const char *MaybeCallUbsanDefaultOptions() {
22 return (&__ubsan_default_options) ? __ubsan_default_options() : "";
25 Flags ubsan_flags;
27 void Flags::SetDefaults() {
28 #define UBSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
29 #include "ubsan_flags.inc"
30 #undef UBSAN_FLAG
33 void RegisterUbsanFlags(FlagParser *parser, Flags *f) {
34 #define UBSAN_FLAG(Type, Name, DefaultValue, Description) \
35 RegisterFlag(parser, #Name, Description, &f->Name);
36 #include "ubsan_flags.inc"
37 #undef UBSAN_FLAG
40 void InitializeFlags() {
41 SetCommonFlagsDefaults();
43 CommonFlags cf;
44 cf.CopyFrom(*common_flags());
45 cf.print_summary = false;
46 OverrideCommonFlags(cf);
49 Flags *f = flags();
50 f->SetDefaults();
52 FlagParser parser;
53 RegisterCommonFlags(&parser);
54 RegisterUbsanFlags(&parser, f);
56 // Override from user-specified string.
57 parser.ParseString(MaybeCallUbsanDefaultOptions());
58 // Override from environment variable.
59 parser.ParseString(GetEnv("UBSAN_OPTIONS"));
60 InitializeCommonFlags();
61 if (Verbosity()) ReportUnrecognizedFlags();
63 if (common_flags()->help) parser.PrintFlagDescriptions();
66 } // namespace __ubsan
68 extern "C" {
70 #if !SANITIZER_SUPPORTS_WEAK_HOOKS
71 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
72 const char *__ubsan_default_options() { return ""; }
73 #endif
75 #if SANITIZER_WINDOWS
76 const char *__ubsan_default_default_options() { return ""; }
77 # ifdef _WIN64
78 # pragma comment(linker, "/alternatename:__ubsan_default_options=__ubsan_default_default_options")
79 # else
80 # pragma comment(linker, "/alternatename:___ubsan_default_options=___ubsan_default_default_options")
81 # endif
82 #endif
84 } // extern "C"
86 #endif // CAN_SANITIZE_UB