1 //===-- ubsan_flags.cpp ---------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Runtime flags for UndefinedBehaviorSanitizer.
11 //===----------------------------------------------------------------------===//
13 #include "ubsan_platform.h"
15 #include "ubsan_flags.h"
16 #include "sanitizer_common/sanitizer_common.h"
17 #include "sanitizer_common/sanitizer_flags.h"
18 #include "sanitizer_common/sanitizer_flag_parser.h"
24 static const char *GetFlag(const char *flag
) {
25 // We cannot call getenv() from inside a preinit array initializer
26 if (SANITIZER_CAN_USE_PREINIT_ARRAY
) {
35 void Flags::SetDefaults() {
36 #define UBSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
37 #include "ubsan_flags.inc"
41 void RegisterUbsanFlags(FlagParser
*parser
, Flags
*f
) {
42 #define UBSAN_FLAG(Type, Name, DefaultValue, Description) \
43 RegisterFlag(parser, #Name, Description, &f->Name);
44 #include "ubsan_flags.inc"
48 void InitializeFlags() {
49 SetCommonFlagsDefaults();
52 cf
.CopyFrom(*common_flags());
53 cf
.print_summary
= false;
54 cf
.external_symbolizer_path
= GetFlag("UBSAN_SYMBOLIZER_PATH");
55 OverrideCommonFlags(cf
);
62 RegisterCommonFlags(&parser
);
63 RegisterUbsanFlags(&parser
, f
);
65 // Override from user-specified string.
66 parser
.ParseString(__ubsan_default_options());
67 // Override from environment variable.
68 parser
.ParseStringFromEnv("UBSAN_OPTIONS");
69 InitializeCommonFlags();
70 if (Verbosity()) ReportUnrecognizedFlags();
72 if (common_flags()->help
) parser
.PrintFlagDescriptions();
75 } // namespace __ubsan
77 SANITIZER_INTERFACE_WEAK_DEF(const char *, __ubsan_default_options
, void) {
81 #endif // CAN_SANITIZE_UB