Remove assert in get_def_bb_for_const
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_flags.cc
bloba24ff900011cb07fbf1aeac403a75f594937c23b
1 //===-- sanitizer_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 // This file is a part of ThreadSanitizer/AddressSanitizer runtime.
9 //
10 //===----------------------------------------------------------------------===//
12 #include "sanitizer_flags.h"
14 #include "sanitizer_common.h"
15 #include "sanitizer_libc.h"
16 #include "sanitizer_list.h"
17 #include "sanitizer_flag_parser.h"
19 namespace __sanitizer {
21 CommonFlags common_flags_dont_use;
23 struct FlagDescription {
24 const char *name;
25 const char *description;
26 FlagDescription *next;
29 IntrusiveList<FlagDescription> flag_descriptions;
31 // If set, the tool will install its own SEGV signal handler by default.
32 #ifndef SANITIZER_NEEDS_SEGV
33 # define SANITIZER_NEEDS_SEGV 1
34 #endif
36 void CommonFlags::SetDefaults() {
37 #define COMMON_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
38 #include "sanitizer_flags.inc"
39 #undef COMMON_FLAG
42 void CommonFlags::CopyFrom(const CommonFlags &other) {
43 internal_memcpy(this, &other, sizeof(*this));
46 // Copy the string from "s" to "out", replacing "%b" with the binary basename.
47 static void SubstituteBinaryName(const char *s, char *out, uptr out_size) {
48 char *out_end = out + out_size;
49 while (*s && out < out_end - 1) {
50 if (s[0] != '%' || s[1] != 'b') { *out++ = *s++; continue; }
51 const char *base = GetProcessName();
52 CHECK(base);
53 while (*base && out < out_end - 1)
54 *out++ = *base++;
55 s += 2; // skip "%b"
57 *out = '\0';
60 class FlagHandlerInclude : public FlagHandlerBase {
61 FlagParser *parser_;
62 bool ignore_missing_;
64 public:
65 explicit FlagHandlerInclude(FlagParser *parser, bool ignore_missing)
66 : parser_(parser), ignore_missing_(ignore_missing) {}
67 bool Parse(const char *value) final {
68 if (internal_strchr(value, '%')) {
69 char *buf = (char *)MmapOrDie(kMaxPathLength, "FlagHandlerInclude");
70 SubstituteBinaryName(value, buf, kMaxPathLength);
71 bool res = parser_->ParseFile(buf, ignore_missing_);
72 UnmapOrDie(buf, kMaxPathLength);
73 return res;
75 return parser_->ParseFile(value, ignore_missing_);
79 void RegisterIncludeFlags(FlagParser *parser, CommonFlags *cf) {
80 FlagHandlerInclude *fh_include = new (FlagParser::Alloc) // NOLINT
81 FlagHandlerInclude(parser, /*ignore_missing*/ false);
82 parser->RegisterHandler("include", fh_include,
83 "read more options from the given file");
84 FlagHandlerInclude *fh_include_if_exists = new (FlagParser::Alloc) // NOLINT
85 FlagHandlerInclude(parser, /*ignore_missing*/ true);
86 parser->RegisterHandler(
87 "include_if_exists", fh_include_if_exists,
88 "read more options from the given file (if it exists)");
91 void RegisterCommonFlags(FlagParser *parser, CommonFlags *cf) {
92 #define COMMON_FLAG(Type, Name, DefaultValue, Description) \
93 RegisterFlag(parser, #Name, Description, &cf->Name);
94 #include "sanitizer_flags.inc"
95 #undef COMMON_FLAG
97 RegisterIncludeFlags(parser, cf);
100 } // namespace __sanitizer