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"
23 const char *MaybeCallUbsanDefaultOptions() {
24 return (&__ubsan_default_options) ? __ubsan_default_options() : "";
29 void Flags::SetDefaults() {
30 #define UBSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
31 #include "ubsan_flags.inc"
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"
42 void InitializeFlags() {
43 SetCommonFlagsDefaults();
46 cf.CopyFrom(*common_flags());
47 cf.print_summary = false;
48 cf.external_symbolizer_path = GetEnv("UBSAN_SYMBOLIZER_PATH");
49 OverrideCommonFlags(cf);
56 RegisterCommonFlags(&parser);
57 RegisterUbsanFlags(&parser, f);
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();
66 if (common_flags()->help) parser.PrintFlagDescriptions();
69 } // namespace __ubsan
71 SANITIZER_INTERFACE_WEAK_DEF(const char *, __ubsan_default_options, void) {
75 #endif // CAN_SANITIZE_UB