]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Driver/SanitizerArgs.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Driver / SanitizerArgs.h
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 <string>
16 #include <vector>
17
18 namespace clang {
19 namespace driver {
20
21 class ToolChain;
22
23 class SanitizerArgs {
24   SanitizerSet Sanitizers;
25   SanitizerSet RecoverableSanitizers;
26   SanitizerSet TrapSanitizers;
27
28   std::vector<std::string> BlacklistFiles;
29   std::vector<std::string> ExtraDeps;
30   int CoverageFeatures = 0;
31   int MsanTrackOrigins = 0;
32   bool MsanUseAfterDtor = true;
33   bool CfiCrossDso = false;
34   bool CfiICallGeneralizePointers = false;
35   int AsanFieldPadding = 0;
36   bool SharedRuntime = false;
37   bool AsanUseAfterScope = true;
38   bool AsanPoisonCustomArrayCookie = false;
39   bool AsanGlobalsDeadStripping = false;
40   bool AsanUseOdrIndicator = false;
41   bool AsanInvalidPointerCmp = false;
42   bool AsanInvalidPointerSub = false;
43   std::string HwasanAbi;
44   bool LinkCXXRuntimes = false;
45   bool NeedPIE = false;
46   bool SafeStackRuntime = false;
47   bool Stats = false;
48   bool TsanMemoryAccess = true;
49   bool TsanFuncEntryExit = true;
50   bool TsanAtomics = true;
51   bool MinimalRuntime = false;
52   // True if cross-dso CFI support if provided by the system (i.e. Android).
53   bool ImplicitCfiRuntime = false;
54
55  public:
56   /// Parses the sanitizer arguments from an argument list.
57   SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args);
58
59   bool needsSharedRt() const { return SharedRuntime; }
60
61   bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
62   bool needsHwasanRt() const { return Sanitizers.has(SanitizerKind::HWAddress); }
63   bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
64   bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
65   bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
66   bool needsLsanRt() const {
67     return Sanitizers.has(SanitizerKind::Leak) &&
68            !Sanitizers.has(SanitizerKind::Address) &&
69            !Sanitizers.has(SanitizerKind::HWAddress);
70   }
71   bool needsUbsanRt() const;
72   bool requiresMinimalRuntime() const { return MinimalRuntime; }
73   bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
74   bool needsSafeStackRt() const { return SafeStackRuntime; }
75   bool needsCfiRt() const;
76   bool needsCfiDiagRt() const;
77   bool needsStatsRt() const { return Stats; }
78   bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
79
80   bool requiresPIE() const;
81   bool needsUnwindTables() const;
82   bool needsLTO() const;
83   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
84   bool hasCrossDsoCfi() const { return CfiCrossDso; }
85   bool hasAnySanitizer() const { return !Sanitizers.empty(); }
86   void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
87                llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
88 };
89
90 }  // namespace driver
91 }  // namespace clang
92
93 #endif