clang API Documentation
#include "clang/Driver/SanitizerArgs.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/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/SpecialCaseList.h"
#include <memory>
#include "clang/Basic/Sanitizers.def"
Go to the source code of this file.
Defines | |
#define | SANITIZER(NAME, ID) SO_##ID, |
#define | SANITIZER_GROUP(NAME, ID, ALIAS) SO_##ID##Group, |
#define | SANITIZER(NAME, ID) ID = 1 << SO_##ID, |
#define | SANITIZER_GROUP(NAME, ID, ALIAS) ID = ALIAS, ID##Group = 1 << SO_##ID##Group, |
#define | SANITIZER(NAME, ID) |
#define | SANITIZER(NAME, ID) |
#define | SANITIZER(NAME, ID) |
#define | SANITIZER(NAME, ID) |
#define | SANITIZER(NAME, ID) .Case(NAME, ID) |
#define | SANITIZER_GROUP(NAME, ID, ALIAS) .Case(NAME, ID##Group) |
#define | SANITIZER(NAME, ID) |
#define | SANITIZER_GROUP(NAME, ID, ALIAS) if (Kinds & ID##Group) Kinds |= ID; |
Enumerations | |
enum | SanitizeOrdinal |
enum | SanitizeKind |
Functions | |
static bool | hasOneOf (const clang::SanitizerSet &Sanitizers, unsigned Kinds) |
static void | addAllOf (clang::SanitizerSet &Sanitizers, unsigned Kinds) |
Adds all sanitizers from Kinds to Sanitizers . | |
static unsigned | toSanitizeKind (clang::SanitizerKind K) |
static unsigned | parseValue (const char *Value) |
static unsigned | parseArgValues (const Driver &D, const llvm::opt::Arg *A, bool DiagnoseErrors) |
static bool | parseArgument (const Driver &D, const llvm::opt::Arg *A, unsigned &Add, unsigned &Remove, bool DiagnoseErrors) |
static std::string | lastArgumentForMask (const Driver &D, const llvm::opt::ArgList &Args, unsigned Mask) |
static std::string | lastArgumentForKind (const Driver &D, const llvm::opt::ArgList &Args, clang::SanitizerKind K) |
static std::string | describeSanitizeArg (const llvm::opt::Arg *A, unsigned Mask) |
static std::string | toString (const clang::SanitizerSet &Sanitizers) |
static unsigned | expandGroups (unsigned Kinds) |
static unsigned | getToolchainUnsupportedKinds (const ToolChain &TC) |
Definition at line 39 of file SanitizerArgs.cpp.
if (Sanitizers.has(clang::SanitizerKind::ID) && (Kinds & ID)) \ return true;
Definition at line 39 of file SanitizerArgs.cpp.
if (Kinds & ID) \ Sanitizers.set(clang::SanitizerKind::ID, true);
Definition at line 39 of file SanitizerArgs.cpp.
if (K == clang::SanitizerKind::ID) \ return ID;
Definition at line 39 of file SanitizerArgs.cpp.
if (Sanitizers.has(clang::SanitizerKind::ID)) { \ if (!Res.empty()) \ Res += ","; \ Res += NAME; \ }
Definition at line 39 of file SanitizerArgs.cpp.
Definition at line 39 of file SanitizerArgs.cpp.
Definition at line 39 of file SanitizerArgs.cpp.
#define SANITIZER_GROUP | ( | NAME, | |
ID, | |||
ALIAS | |||
) | SO_##ID##Group, |
Definition at line 40 of file SanitizerArgs.cpp.
Definition at line 40 of file SanitizerArgs.cpp.
#define SANITIZER_GROUP | ( | NAME, | |
ID, | |||
ALIAS | |||
) | .Case(NAME, ID##Group) |
Definition at line 40 of file SanitizerArgs.cpp.
#define SANITIZER_GROUP | ( | NAME, | |
ID, | |||
ALIAS | |||
) | if (Kinds & ID##Group) Kinds |= ID; |
Definition at line 40 of file SanitizerArgs.cpp.
enum SanitizeKind |
Represents a set of sanitizer kinds. It is also used to define: 1) set of sanitizers each sanitizer group expands into. 2) set of sanitizers sharing a specific property (e.g. all sanitizers with zero-base shadow).
Definition at line 38 of file SanitizerArgs.cpp.
enum SanitizeOrdinal |
Assign ordinals to possible values of -fsanitize= flag. We use the ordinal values as bit positions within SanitizeKind
.
Definition at line 27 of file SanitizerArgs.cpp.
static void addAllOf | ( | clang::SanitizerSet & | Sanitizers, |
unsigned | Kinds | ||
) | [static] |
Adds all sanitizers from Kinds
to Sanitizers
.
Definition at line 61 of file SanitizerArgs.cpp.
Referenced by clang::driver::SanitizerArgs::SanitizerArgs().
std::string describeSanitizeArg | ( | const llvm::opt::Arg * | A, |
unsigned | 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 470 of file SanitizerArgs.cpp.
References expandGroups(), and parseValue().
Referenced by lastArgumentForMask(), and clang::driver::SanitizerArgs::SanitizerArgs().
unsigned expandGroups | ( | unsigned | Kinds | ) | [static] |
For each sanitizer group bit set in Kinds
, set the bits for sanitizers this group enables.
Definition at line 421 of file SanitizerArgs.cpp.
Referenced by describeSanitizeArg(), lastArgumentForMask(), and clang::driver::SanitizerArgs::SanitizerArgs().
static unsigned getToolchainUnsupportedKinds | ( | const ToolChain & | TC | ) | [static] |
Definition at line 120 of file SanitizerArgs.cpp.
References clang::driver::ToolChain::getTriple(), and clang::driver::options::Unsupported.
Referenced by clang::driver::SanitizerArgs::SanitizerArgs().
static bool hasOneOf | ( | const clang::SanitizerSet & | Sanitizers, |
unsigned | Kinds | ||
) | [static] |
Returns true if set of Sanitizers
contain at least one sanitizer from Kinds
.
Definition at line 52 of file SanitizerArgs.cpp.
Referenced by clang::driver::SanitizerArgs::hasZeroBaseShadow(), clang::driver::SanitizerArgs::needsUbsanRt(), clang::driver::SanitizerArgs::needsUnwindTables(), and clang::driver::SanitizerArgs::SanitizerArgs().
static std::string lastArgumentForKind | ( | const Driver & | D, |
const llvm::opt::ArgList & | Args, | ||
clang::SanitizerKind | K | ||
) | [static] |
Definition at line 100 of file SanitizerArgs.cpp.
References lastArgumentForMask(), and toSanitizeKind().
Referenced by clang::driver::SanitizerArgs::SanitizerArgs().
std::string lastArgumentForMask | ( | const Driver & | D, |
const llvm::opt::ArgList & | Args, | ||
unsigned | 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 456 of file SanitizerArgs.cpp.
References describeSanitizeArg(), expandGroups(), and parseArgument().
Referenced by lastArgumentForKind(), and clang::driver::SanitizerArgs::SanitizerArgs().
bool parseArgument | ( | const Driver & | D, |
const llvm::opt::Arg * | A, | ||
unsigned & | Add, | ||
unsigned & | Remove, | ||
bool | DiagnoseErrors | ||
) | [static] |
Parse a single flag of the form -f[no]sanitize=. Sets the masks defining required change of the set of sanitizers. Returns true if the flag was parsed successfully.
Definition at line 441 of file SanitizerArgs.cpp.
References parseArgValues().
Referenced by lastArgumentForMask(), and clang::driver::SanitizerArgs::SanitizerArgs().
unsigned 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 OR of members of SanitizeKind
enumeration.
Definition at line 428 of file SanitizerArgs.cpp.
References clang::driver::Driver::Diag(), and parseValue().
Referenced by parseArgument().
unsigned parseValue | ( | const char * | Value | ) | [static] |
Parse a single value from a -fsanitize= or -fno-sanitize= value list. Returns a member of the SanitizeKind
enumeration, or 0
if Value
is not known.
Definition at line 412 of file SanitizerArgs.cpp.
References SANITIZER.
Referenced by describeSanitizeArg(), and parseArgValues().
static unsigned toSanitizeKind | ( | clang::SanitizerKind | K | ) | [static] |
Definition at line 68 of file SanitizerArgs.cpp.
Referenced by lastArgumentForKind().
static std::string toString | ( | const clang::SanitizerSet & | Sanitizers | ) | [static] |
Produce a string containing comma-separated names of sanitizers in Sanitizers
set.
Definition at line 348 of file SanitizerArgs.cpp.
Referenced by clang::driver::SanitizerArgs::addArgs().