clang  14.0.0git
Macros | Enumerations | Functions | Variables
SanitizerArgs.cpp File Reference
#include "clang/Driver/SanitizerArgs.h"
#include "ToolChains/CommonArgs.h"
#include "clang/Basic/Sanitizers.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/ToolChain.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/SpecialCaseList.h"
#include "llvm/Support/TargetParser.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
#include <memory>
#include "clang/Basic/Sanitizers.def"
Include dependency graph for SanitizerArgs.cpp:

Go to the source code of this file.

Macros

#define SANITIZER(NAME, ID)
 
#define SANITIZER_GROUP(NAME, ID, ALIAS)
 
#define SANITIZER(NAME, ID)
 

Enumerations

enum  CoverageFeature {
  CoverageFunc = 1 << 0, CoverageBB = 1 << 1, CoverageEdge = 1 << 2, CoverageIndirCall = 1 << 3,
  CoverageTraceBB = 1 << 4, CoverageTraceCmp = 1 << 5, CoverageTraceDiv = 1 << 6, CoverageTraceGep = 1 << 7,
  Coverage8bitCounters = 1 << 8, CoverageTracePC = 1 << 9, CoverageTracePCGuard = 1 << 10, CoverageNoPrune = 1 << 11,
  CoverageInline8bitCounters = 1 << 12, CoveragePCTable = 1 << 13, CoverageStackDepth = 1 << 14, CoverageInlineBoolFlag = 1 << 15
}
 

Functions

static SanitizerMask parseArgValues (const Driver &D, const llvm::opt::Arg *A, bool DiagnoseErrors)
 Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any invalid components. More...
 
static int parseCoverageFeatures (const Driver &D, const llvm::opt::Arg *A)
 Parse -f(no-)?sanitize-coverage= flag values, diagnosing any invalid components. More...
 
static std::string lastArgumentForMask (const Driver &D, const llvm::opt::ArgList &Args, SanitizerMask Mask)
 Produce an argument string from ArgList Args, which shows how it provides some sanitizer kind from Mask. More...
 
static std::string describeSanitizeArg (const llvm::opt::Arg *A, SanitizerMask Mask)
 Produce an argument string from argument A, which shows how it provides a value in Mask. More...
 
static std::string toString (const clang::SanitizerSet &Sanitizers)
 Produce a string containing comma-separated names of sanitizers in Sanitizers set. More...
 
static void validateSpecialCaseListFormat (const Driver &D, std::vector< std::string > &SCLFiles, unsigned MalformedSCLErrorDiagID)
 
static void addDefaultIgnorelists (const Driver &D, SanitizerMask Kinds, std::vector< std::string > &IgnorelistFiles)
 
static void parseSpecialCaseListArg (const Driver &D, const llvm::opt::ArgList &Args, std::vector< std::string > &SCLFiles, llvm::opt::OptSpecifier SCLOptionID, llvm::opt::OptSpecifier NoSCLOptionID, unsigned MalformedSCLErrorDiagID)
 Parse -f(no-)?sanitize-(coverage-)?(white|ignore)list argument's values, diagnosing any invalid file paths and validating special case list format. More...
 
static SanitizerMask setGroupBits (SanitizerMask Kinds)
 Sets group bits for every group that has at least one representative already enabled in Kinds. More...
 
static SanitizerMask parseSanitizeTrapArgs (const Driver &D, const llvm::opt::ArgList &Args)
 
static void addSpecialCaseListOpt (const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const char *SCLOptFlag, const std::vector< std::string > &SCLFiles)
 
static void addIncludeLinkerOption (const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, StringRef SymbolName)
 
static bool hasTargetFeatureMTE (const llvm::opt::ArgStringList &CmdArgs)
 

Variables

static const SanitizerMask NeedsUbsanRt
 
static const SanitizerMask NeedsUbsanCxxRt
 
static const SanitizerMask NotAllowedWithTrap = SanitizerKind::Vptr
 
static const SanitizerMask NotAllowedWithMinimalRuntime
 
static const SanitizerMask RequiresPIE
 
static const SanitizerMask NeedsUnwindTables
 
static const SanitizerMask SupportsCoverage
 
static const SanitizerMask RecoverableByDefault
 
static const SanitizerMask Unrecoverable
 
static const SanitizerMask AlwaysRecoverable
 
static const SanitizerMask NeedsLTO = SanitizerKind::CFI
 
static const SanitizerMask TrappingSupported
 
static const SanitizerMask TrappingDefault = SanitizerKind::CFI
 
static const SanitizerMask CFIClasses
 
static const SanitizerMask CompatibleWithMinimalRuntime
 

Macro Definition Documentation

◆ SANITIZER [1/2]

#define SANITIZER (   NAME,
  ID 
)

◆ SANITIZER [2/2]

#define SANITIZER (   NAME,
  ID 
)
Value:
if (Sanitizers.has(SanitizerKind::ID)) { \
if (!Res.empty()) \
Res += ","; \
Res += NAME; \
}

◆ SANITIZER_GROUP

#define SANITIZER_GROUP (   NAME,
  ID,
  ALIAS 
)
Value:
if (Kinds & SanitizerKind::ID) \

Enumeration Type Documentation

◆ CoverageFeature

Enumerator
CoverageFunc 
CoverageBB 
CoverageEdge 
CoverageIndirCall 
CoverageTraceBB 
CoverageTraceCmp 
CoverageTraceDiv 
CoverageTraceGep 
Coverage8bitCounters 
CoverageTracePC 
CoverageTracePCGuard 
CoverageNoPrune 
CoverageInline8bitCounters 
CoveragePCTable 
CoverageStackDepth 
CoverageInlineBoolFlag 

Definition at line 77 of file SanitizerArgs.cpp.

Function Documentation

◆ addDefaultIgnorelists()

static void addDefaultIgnorelists ( const Driver D,
SanitizerMask  Kinds,
std::vector< std::string > &  IgnorelistFiles 
)
static

◆ addIncludeLinkerOption()

static void addIncludeLinkerOption ( const ToolChain TC,
const llvm::opt::ArgList &  Args,
llvm::opt::ArgStringList &  CmdArgs,
StringRef  SymbolName 
)
static

◆ addSpecialCaseListOpt()

static void addSpecialCaseListOpt ( const llvm::opt::ArgList &  Args,
llvm::opt::ArgStringList &  CmdArgs,
const char *  SCLOptFlag,
const std::vector< std::string > &  SCLFiles 
)
static

Definition at line 933 of file SanitizerArgs.cpp.

Referenced by clang::driver::SanitizerArgs::addArgs().

◆ describeSanitizeArg()

std::string describeSanitizeArg ( const llvm::opt::Arg *  A,
SanitizerMask  Mask 
)
static

Produce an argument string from argument A, which shows how it provides a value in Mask.

For instance, the argument "-fsanitize=address,alignment" with mask NeedsUbsanRt would produce "-fsanitize=alignment".

Definition at line 1275 of file SanitizerArgs.cpp.

References clang::expandSanitizerGroups(), clang::parseSanitizerValue(), and string().

Referenced by lastArgumentForMask(), and clang::driver::SanitizerArgs::SanitizerArgs().

◆ hasTargetFeatureMTE()

static bool hasTargetFeatureMTE ( const llvm::opt::ArgStringList &  CmdArgs)
static

Definition at line 958 of file SanitizerArgs.cpp.

References End.

Referenced by clang::driver::SanitizerArgs::addArgs().

◆ lastArgumentForMask()

std::string lastArgumentForMask ( const Driver D,
const llvm::opt::ArgList &  Args,
SanitizerMask  Mask 
)
static

Produce an argument string from ArgList Args, which shows how it provides some sanitizer kind from Mask.

For example, the argument list "-fsanitize=thread,vptr -fsanitize=address" with mask NeedsUbsanRt would produce "-fsanitize=vptr".

Definition at line 1255 of file SanitizerArgs.cpp.

References describeSanitizeArg(), clang::expandSanitizerGroups(), and parseArgValues().

Referenced by clang::driver::SanitizerArgs::addArgs(), and clang::driver::SanitizerArgs::SanitizerArgs().

◆ parseArgValues()

SanitizerMask parseArgValues ( const Driver D,
const llvm::opt::Arg *  A,
bool  DiagnoseErrors 
)
static

Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any invalid components.

Returns a SanitizerMask.

Definition at line 1194 of file SanitizerArgs.cpp.

References clang::driver::Driver::Diag(), and clang::parseSanitizerValue().

Referenced by lastArgumentForMask(), parseSanitizeTrapArgs(), and clang::driver::SanitizerArgs::SanitizerArgs().

◆ parseCoverageFeatures()

int parseCoverageFeatures ( const Driver D,
const llvm::opt::Arg *  A 
)
static

Parse -f(no-)?sanitize-coverage= flag values, diagnosing any invalid components.

Returns OR of members of CoverageFeature enumeration.

Definition at line 1223 of file SanitizerArgs.cpp.

References Coverage8bitCounters, CoverageBB, CoverageEdge, CoverageFunc, CoverageIndirCall, CoverageInline8bitCounters, CoverageInlineBoolFlag, CoverageNoPrune, CoveragePCTable, CoverageStackDepth, CoverageTraceBB, CoverageTraceCmp, CoverageTraceDiv, CoverageTraceGep, CoverageTracePC, CoverageTracePCGuard, and clang::driver::Driver::Diag().

◆ parseSanitizeTrapArgs()

static SanitizerMask parseSanitizeTrapArgs ( const Driver D,
const llvm::opt::ArgList &  Args 
)
static

◆ parseSpecialCaseListArg()

static void parseSpecialCaseListArg ( const Driver D,
const llvm::opt::ArgList &  Args,
std::vector< std::string > &  SCLFiles,
llvm::opt::OptSpecifier  SCLOptionID,
llvm::opt::OptSpecifier  NoSCLOptionID,
unsigned  MalformedSCLErrorDiagID 
)
static

Parse -f(no-)?sanitize-(coverage-)?(white|ignore)list argument's values, diagnosing any invalid file paths and validating special case list format.

Definition at line 173 of file SanitizerArgs.cpp.

References clang::driver::Driver::Diag(), clang::driver::Driver::getVFS(), string(), and validateSpecialCaseListFormat().

◆ setGroupBits()

static SanitizerMask setGroupBits ( SanitizerMask  Kinds)
static

Sets group bits for every group that has at least one representative already enabled in Kinds.

Definition at line 200 of file SanitizerArgs.cpp.

Referenced by parseSanitizeTrapArgs(), and clang::driver::SanitizerArgs::SanitizerArgs().

◆ toString()

static std::string toString ( const clang::SanitizerSet Sanitizers)
static

Produce a string containing comma-separated names of sanitizers in Sanitizers set.

Definition at line 921 of file SanitizerArgs.cpp.

References string().

Referenced by clang::driver::SanitizerArgs::addArgs().

◆ validateSpecialCaseListFormat()

static void validateSpecialCaseListFormat ( const Driver D,
std::vector< std::string > &  SCLFiles,
unsigned  MalformedSCLErrorDiagID 
)
static

Variable Documentation

◆ AlwaysRecoverable

const SanitizerMask AlwaysRecoverable
static
Initial value:
=
SanitizerKind::KernelAddress | SanitizerKind::KernelHWAddress

Definition at line 60 of file SanitizerArgs.cpp.

Referenced by emitCheckHandlerCall(), and getRecoverableKind().

◆ CFIClasses

const SanitizerMask CFIClasses
static
Initial value:
=
SanitizerKind::CFIVCall | SanitizerKind::CFINVCall |
SanitizerKind::CFIMFCall | SanitizerKind::CFIDerivedCast |
SanitizerKind::CFIUnrelatedCast

Definition at line 69 of file SanitizerArgs.cpp.

Referenced by clang::driver::SanitizerArgs::addArgs().

◆ CompatibleWithMinimalRuntime

const SanitizerMask CompatibleWithMinimalRuntime
static
Initial value:
=
TrappingSupported | SanitizerKind::Scudo | SanitizerKind::ShadowCallStack |
SanitizerKind::MemTag

Definition at line 73 of file SanitizerArgs.cpp.

◆ NeedsLTO

const SanitizerMask NeedsLTO = SanitizerKind::CFI
static

◆ NeedsUbsanCxxRt

const SanitizerMask NeedsUbsanCxxRt
static
Initial value:
=
SanitizerKind::Vptr | SanitizerKind::CFI

Definition at line 33 of file SanitizerArgs.cpp.

Referenced by clang::driver::SanitizerArgs::SanitizerArgs().

◆ NeedsUbsanRt

const SanitizerMask NeedsUbsanRt
static
Initial value:
=
SanitizerKind::Undefined | SanitizerKind::Integer |
SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
SanitizerKind::CFI | SanitizerKind::FloatDivideByZero |
SanitizerKind::ObjCCast

Definition at line 28 of file SanitizerArgs.cpp.

Referenced by clang::driver::SanitizerArgs::needsUbsanRt().

◆ NeedsUnwindTables

const SanitizerMask NeedsUnwindTables
static
Initial value:
=
SanitizerKind::Address | SanitizerKind::HWAddress | SanitizerKind::Thread |
SanitizerKind::Memory | SanitizerKind::DataFlow

Definition at line 40 of file SanitizerArgs.cpp.

Referenced by clang::driver::SanitizerArgs::needsUnwindTables().

◆ NotAllowedWithMinimalRuntime

const SanitizerMask NotAllowedWithMinimalRuntime
static
Initial value:
=
SanitizerKind::Function | SanitizerKind::Vptr

Definition at line 36 of file SanitizerArgs.cpp.

Referenced by clang::driver::SanitizerArgs::SanitizerArgs().

◆ NotAllowedWithTrap

const SanitizerMask NotAllowedWithTrap = SanitizerKind::Vptr
static

Definition at line 35 of file SanitizerArgs.cpp.

Referenced by clang::driver::SanitizerArgs::SanitizerArgs().

◆ RecoverableByDefault

const SanitizerMask RecoverableByDefault
static
Initial value:
=
SanitizerKind::Undefined | SanitizerKind::Integer |
SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast

Definition at line 54 of file SanitizerArgs.cpp.

◆ RequiresPIE

const SanitizerMask RequiresPIE
static
Initial value:
=
SanitizerKind::DataFlow | SanitizerKind::HWAddress | SanitizerKind::Scudo

Definition at line 38 of file SanitizerArgs.cpp.

Referenced by clang::driver::SanitizerArgs::requiresPIE().

◆ SupportsCoverage

const SanitizerMask SupportsCoverage
static
Initial value:
=
SanitizerKind::Address | SanitizerKind::HWAddress |
SanitizerKind::KernelAddress | SanitizerKind::KernelHWAddress |
SanitizerKind::MemTag | SanitizerKind::Memory |
SanitizerKind::KernelMemory | SanitizerKind::Leak |
SanitizerKind::Undefined | SanitizerKind::Integer | SanitizerKind::Bounds |
SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
SanitizerKind::DataFlow | SanitizerKind::Fuzzer |
SanitizerKind::FuzzerNoLink | SanitizerKind::FloatDivideByZero |
SanitizerKind::SafeStack | SanitizerKind::ShadowCallStack |
SanitizerKind::Thread | SanitizerKind::ObjCCast

Definition at line 43 of file SanitizerArgs.cpp.

◆ TrappingDefault

const SanitizerMask TrappingDefault = SanitizerKind::CFI
static

Definition at line 68 of file SanitizerArgs.cpp.

◆ TrappingSupported

const SanitizerMask TrappingSupported
static
Initial value:
=
(SanitizerKind::Undefined & ~SanitizerKind::Vptr) | SanitizerKind::Integer |
SanitizerKind::Nullability | SanitizerKind::LocalBounds |
SanitizerKind::CFI | SanitizerKind::FloatDivideByZero |
SanitizerKind::ObjCCast

Definition at line 63 of file SanitizerArgs.cpp.

Referenced by parseSanitizeTrapArgs().

◆ Unrecoverable

const SanitizerMask Unrecoverable
static
Initial value:
=
SanitizerKind::Unreachable | SanitizerKind::Return

Definition at line 58 of file SanitizerArgs.cpp.

Referenced by emitCheckHandlerCall(), and getRecoverableKind().

clang::ento::Nullability
Nullability
Definition: CheckerHelpers.h:56
clang::diag::Group
Group
Definition: DiagnosticCategories.h:23
TrappingSupported
static const SanitizerMask TrappingSupported
Definition: SanitizerArgs.cpp:63
clang::SanitizerKind
Definition: Sanitizers.h:131
clang::Builtin::ID
ID
Definition: Builtins.h:48