1 //===-- ubsan_flags.cc ----------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Runtime flags for UndefinedBehaviorSanitizer.
12 //===----------------------------------------------------------------------===//
14 #include "ubsan_platform.h"
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"
25 const char *MaybeCallUbsanDefaultOptions() {
26 return (&__ubsan_default_options) ? __ubsan_default_options() : "";
29 static const char *GetFlag(const char *flag) {
30 // We cannot call getenv() from inside a preinit array initializer
31 if (SANITIZER_CAN_USE_PREINIT_ARRAY) {
40 void Flags::SetDefaults() {
41 #define UBSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
42 #include "ubsan_flags.inc"
46 void RegisterUbsanFlags(FlagParser *parser, Flags *f) {
47 #define UBSAN_FLAG(Type, Name, DefaultValue, Description) \
48 RegisterFlag(parser, #Name, Description, &f->Name);
49 #include "ubsan_flags.inc"
53 void InitializeFlags() {
54 SetCommonFlagsDefaults();
57 cf.CopyFrom(*common_flags());
58 cf.print_summary = false;
59 cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH");
60 OverrideCommonFlags(cf);
67 RegisterCommonFlags(&parser);
68 RegisterUbsanFlags(&parser, f);
70 // Override from user-specified string.
71 parser.ParseString(MaybeCallUbsanDefaultOptions());
72 // Override from environment variable.
73 parser.ParseString(GetFlag("UBSAN_OPTIONS"));
74 InitializeCommonFlags();
75 if (Verbosity()) ReportUnrecognizedFlags();
77 if (common_flags()->help) parser.PrintFlagDescriptions();
80 } // namespace __ubsan
82 SANITIZER_INTERFACE_WEAK_DEF(const char *, __ubsan_default_options, void) {
86 #endif // CAN_SANITIZE_UB