15 #include "llvm/ADT/StringRef.h" 16 #include "llvm/IR/Constants.h" 18 using namespace clang;
19 using namespace CodeGen;
24 return SS.
hasOneOf(SanitizerKind::Address | SanitizerKind::KernelAddress |
25 SanitizerKind::HWAddress | SanitizerKind::KernelHWAddress |
26 SanitizerKind::MemTag);
38 llvm::Metadata *LocDescr =
nullptr;
39 llvm::Metadata *GlobalName =
nullptr;
44 LocDescr = getLocationMetadata(Loc);
46 GlobalName = llvm::MDString::get(VMContext, Name);
49 llvm::Metadata *GlobalMetadata[] = {
50 llvm::ConstantAsMetadata::get(GV), LocDescr, GlobalName,
51 llvm::ConstantAsMetadata::get(
52 llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), IsDynInit)),
53 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
54 llvm::Type::getInt1Ty(VMContext), IsBlacklisted))};
56 llvm::MDNode *ThisGlobal = llvm::MDNode::get(VMContext, GlobalMetadata);
57 llvm::NamedMDNode *AsanGlobals =
58 CGM.
getModule().getOrInsertNamedMetadata(
"llvm.asan.globals");
59 AsanGlobals->addOperand(ThisGlobal);
63 const VarDecl &D,
bool IsDynInit) {
67 llvm::raw_string_ostream OS(QualName);
70 bool IsBlacklisted =
false;
72 if (
Attr->getMask() & SanitizerKind::Address)
86 I->setMetadata(CGM.
getModule().getMDKindID(
"nosanitize"),
90 llvm::MDNode *SanitizerMetadata::getLocationMetadata(
SourceLocation Loc) {
95 llvm::Metadata *LocMetadata[] = {
97 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
98 llvm::Type::getInt32Ty(VMContext), PLoc.
getLine())),
99 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
100 llvm::Type::getInt32Ty(VMContext), PLoc.
getColumn())),
102 return llvm::MDNode::get(VMContext, LocMetadata);
A (possibly-)qualified type.
llvm::LLVMContext & getLLVMContext()
SanitizerSet Sanitize
Set of enabled sanitizers.
C Language Family Type Representation.
Represents a variable declaration or definition.
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.
bool isInSanitizerBlacklist(SanitizerMask Kind, llvm::Function *Fn, SourceLocation Loc) const
unsigned getLine() const
Return the presumed line number of this location.
Represents an unpacked "presumed" location which can be presented to the user.
void printQualifiedName(raw_ostream &OS) const
Returns a human-readable qualified name for this declaration, like A::B::i, for i being member of nam...
const LangOptions & getLangOpts() const
ASTContext & getContext() const
const char * getFilename() const
Return the presumed filename of this location.
unsigned getColumn() const
Return the presumed column number of this location.
Encodes a location in the source.
This class organizes the cross-function state that is used while generating LLVM code.
Dataflow Directional Tag Classes.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
llvm::Module & getModule() const
SourceManager & getSourceManager()
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
Attr - This represents one attribute.
SourceLocation getLocation() const