Coverage Report

Created: 2021-08-24 07:12

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Driver/SanitizerArgs.h
Line
Count
Source
1
//===--- SanitizerArgs.h - Arguments for sanitizer tools  -------*- C++ -*-===//
2
//
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
6
//
7
//===----------------------------------------------------------------------===//
8
#ifndef LLVM_CLANG_DRIVER_SANITIZERARGS_H
9
#define LLVM_CLANG_DRIVER_SANITIZERARGS_H
10
11
#include "clang/Basic/Sanitizers.h"
12
#include "clang/Driver/Types.h"
13
#include "llvm/Option/Arg.h"
14
#include "llvm/Option/ArgList.h"
15
#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
16
#include <string>
17
#include <vector>
18
19
namespace clang {
20
namespace driver {
21
22
class ToolChain;
23
24
class SanitizerArgs {
25
  SanitizerSet Sanitizers;
26
  SanitizerSet RecoverableSanitizers;
27
  SanitizerSet TrapSanitizers;
28
29
  std::vector<std::string> UserIgnorelistFiles;
30
  std::vector<std::string> SystemIgnorelistFiles;
31
  std::vector<std::string> CoverageAllowlistFiles;
32
  std::vector<std::string> CoverageIgnorelistFiles;
33
  int CoverageFeatures = 0;
34
  int MsanTrackOrigins = 0;
35
  bool MsanUseAfterDtor = true;
36
  bool CfiCrossDso = false;
37
  bool CfiICallGeneralizePointers = false;
38
  bool CfiCanonicalJumpTables = false;
39
  int AsanFieldPadding = 0;
40
  bool SharedRuntime = false;
41
  bool AsanUseAfterScope = true;
42
  bool AsanPoisonCustomArrayCookie = false;
43
  bool AsanGlobalsDeadStripping = false;
44
  bool AsanUseOdrIndicator = false;
45
  bool AsanInvalidPointerCmp = false;
46
  bool AsanInvalidPointerSub = false;
47
  bool AsanOutlineInstrumentation = false;
48
  llvm::AsanDtorKind AsanDtorKind = llvm::AsanDtorKind::Invalid;
49
  std::string HwasanAbi;
50
  bool LinkRuntimes = true;
51
  bool LinkCXXRuntimes = false;
52
  bool NeedPIE = false;
53
  bool SafeStackRuntime = false;
54
  bool Stats = false;
55
  bool TsanMemoryAccess = true;
56
  bool TsanFuncEntryExit = true;
57
  bool TsanAtomics = true;
58
  bool MinimalRuntime = false;
59
  // True if cross-dso CFI support if provided by the system (i.e. Android).
60
  bool ImplicitCfiRuntime = false;
61
  bool NeedsMemProfRt = false;
62
  bool HwasanUseAliases = false;
63
  llvm::AsanDetectStackUseAfterReturnMode AsanUseAfterReturn =
64
      llvm::AsanDetectStackUseAfterReturnMode::Invalid;
65
66
public:
67
  /// Parses the sanitizer arguments from an argument list.
68
  SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args);
69
70
16.2k
  bool needsSharedRt() const { return SharedRuntime; }
71
72
2.02k
  bool needsMemProfRt() const { return NeedsMemProfRt; }
73
20.5k
  bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
74
15.9k
  bool needsHwasanRt() const {
75
15.9k
    return Sanitizers.has(SanitizerKind::HWAddress);
76
15.9k
  }
77
25
  bool needsHwasanAliasesRt() const {
78
25
    return needsHwasanRt() && HwasanUseAliases;
79
25
  }
80
61.8k
  bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
81
15.8k
  bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
82
6.08k
  bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
83
19.3k
  bool needsLsanRt() const {
84
19.3k
    return Sanitizers.has(SanitizerKind::Leak) &&
85
19.3k
           
!Sanitizers.has(SanitizerKind::Address)74
&&
86
19.3k
           
!Sanitizers.has(SanitizerKind::HWAddress)73
;
87
19.3k
  }
88
  bool needsFuzzerInterceptors() const;
89
  bool needsUbsanRt() const;
90
203
  bool requiresMinimalRuntime() const { return MinimalRuntime; }
91
15.7k
  bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
92
1.99k
  bool needsSafeStackRt() const { return SafeStackRuntime; }
93
  bool needsCfiRt() const;
94
  bool needsCfiDiagRt() const;
95
15.7k
  bool needsStatsRt() const { return Stats; }
96
15.7k
  bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
97
98
  bool requiresPIE() const;
99
  bool needsUnwindTables() const;
100
  bool needsLTO() const;
101
383
  bool linkRuntimes() const { return LinkRuntimes; }
102
267
  bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
103
2.07k
  bool hasCrossDsoCfi() const { return CfiCrossDso; }
104
192
  bool hasAnySanitizer() const { return !Sanitizers.empty(); }
105
  void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
106
               llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
107
};
108
109
}  // namespace driver
110
}  // namespace clang
111
112
#endif