]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/sanitizer_common/sancov_flags.cc
Merge compiler-rt r291274.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / sanitizer_common / sancov_flags.cc
1 //===-- sancov_flags.cc -----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Sanitizer Coverage runtime flags.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "sancov_flags.h"
15 #include "sanitizer_flag_parser.h"
16 #include "sanitizer_platform.h"
17
18 #if !SANITIZER_LINUX
19 // other platforms do not have weak symbols out of the box.
20 extern "C" const char* __sancov_default_options() { return ""; }
21 #endif
22
23 using namespace __sanitizer;
24
25 namespace __sancov {
26
27 SancovFlags sancov_flags_dont_use_directly;  // use via flags();
28
29 void SancovFlags::SetDefaults() {
30 #define SANCOV_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
31 #include "sancov_flags.inc"
32 #undef SANCOV_FLAG
33 }
34
35 static void RegisterSancovFlags(FlagParser *parser, SancovFlags *f) {
36 #define SANCOV_FLAG(Type, Name, DefaultValue, Description) \
37   RegisterFlag(parser, #Name, Description, &f->Name);
38 #include "sancov_flags.inc"
39 #undef SANCOV_FLAG
40 }
41
42 static const char *MaybeCallSancovDefaultOptions() {
43   return (&__sancov_default_options) ? __sancov_default_options() : "";
44 }
45
46 void InitializeSancovFlags() {
47   SancovFlags *f = sancov_flags();
48   f->SetDefaults();
49
50   FlagParser parser;
51   RegisterSancovFlags(&parser, f);
52
53   parser.ParseString(MaybeCallSancovDefaultOptions());
54   parser.ParseString(GetEnv("SANCOV_OPTIONS"));
55
56   ReportUnrecognizedFlags();
57   if (f->help) parser.PrintFlagDescriptions();
58 }
59
60 }  // namespace __sancov