Home | History | Annotate | Download | only in Driver
      1 //===--- SanitizerArgs.h - Arguments for sanitizer tools  -------*- 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 #ifndef LLVM_CLANG_DRIVER_SANITIZERARGS_H
     10 #define LLVM_CLANG_DRIVER_SANITIZERARGS_H
     11 
     12 #include "clang/Basic/Sanitizers.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 
     27   std::vector<std::string> BlacklistFiles;
     28   int SanitizeCoverage;
     29   int MsanTrackOrigins;
     30   int AsanFieldPadding;
     31   bool AsanZeroBaseShadow;
     32   bool UbsanTrapOnError;
     33   bool AsanSharedRuntime;
     34   bool LinkCXXRuntimes;
     35 
     36  public:
     37   /// Parses the sanitizer arguments from an argument list.
     38   SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args);
     39 
     40   bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
     41   bool needsSharedAsanRt() const { return AsanSharedRuntime; }
     42   bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
     43   bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
     44   bool needsLsanRt() const {
     45     return Sanitizers.has(SanitizerKind::Leak) &&
     46            !Sanitizers.has(SanitizerKind::Address);
     47   }
     48   bool needsUbsanRt() const;
     49   bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
     50 
     51   bool requiresPIE() const;
     52   bool needsUnwindTables() const;
     53   bool needsLTO() const;
     54   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
     55   void addArgs(const llvm::opt::ArgList &Args,
     56                llvm::opt::ArgStringList &CmdArgs) const;
     57 
     58  private:
     59   void clear();
     60 };
     61 
     62 }  // namespace driver
     63 }  // namespace clang
     64 
     65 #endif
     66