1 //===-- ubsan_flags.cc ----------------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // Runtime flags for UndefinedBehaviorSanitizer.
10 //===----------------------------------------------------------------------===//
12 #include "ubsan_platform.h"
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"
21 const char *MaybeCallUbsanDefaultOptions() {
22 return (&__ubsan_default_options
) ? __ubsan_default_options() : "";
27 void Flags::SetDefaults() {
28 #define UBSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
29 #include "ubsan_flags.inc"
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"
40 void InitializeFlags() {
41 SetCommonFlagsDefaults();
44 cf
.CopyFrom(*common_flags());
45 cf
.print_summary
= false;
46 OverrideCommonFlags(cf
);
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
70 #if !SANITIZER_SUPPORTS_WEAK_HOOKS
71 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
72 const char *__ubsan_default_options() { return ""; }
76 const char *__ubsan_default_default_options() { return ""; }
78 # pragma comment(linker, "/alternatename:__ubsan_default_options=__ubsan_default_default_options")
80 # pragma comment(linker, "/alternatename:___ubsan_default_options=___ubsan_default_default_options")
86 #endif // CAN_SANITIZE_UB