summaryrefslogtreecommitdiffstats
path: root/include/clang/Driver/SanitizerArgs.h
blob: 3524da0e7ffea3dc45ad32c2db4a6dcec5688e33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//===--- SanitizerArgs.h - Arguments for sanitizer tools  -------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_DRIVER_SANITIZERARGS_H
#define LLVM_CLANG_DRIVER_SANITIZERARGS_H

#include "clang/Basic/Sanitizers.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include <string>

namespace clang {
namespace driver {

class Driver;
class ToolChain;

class SanitizerArgs {
  SanitizerSet Sanitizers;
  SanitizerSet RecoverableSanitizers;

  std::string BlacklistFile;
  int SanitizeCoverage;
  int MsanTrackOrigins;
  int AsanFieldPadding;
  bool AsanZeroBaseShadow;
  bool UbsanTrapOnError;
  bool AsanSharedRuntime;
  bool LinkCXXRuntimes;

 public:
  /// Parses the sanitizer arguments from an argument list.
  SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args);

  bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
  bool needsSharedAsanRt() const { return AsanSharedRuntime; }
  bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
  bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
  bool needsLsanRt() const {
    return Sanitizers.has(SanitizerKind::Leak) &&
           !Sanitizers.has(SanitizerKind::Address);
  }
  bool needsUbsanRt() const;
  bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }

  bool sanitizesVptr() const { return Sanitizers.has(SanitizerKind::Vptr); }
  bool requiresPIE() const;
  bool needsUnwindTables() const;
  bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
  void addArgs(const llvm::opt::ArgList &Args,
               llvm::opt::ArgStringList &CmdArgs) const;

 private:
  void clear();
  bool getDefaultBlacklist(const Driver &D, std::string &BLPath);
};

}  // namespace driver
}  // namespace clang

#endif