16 #include "llvm/ADT/StringRef.h" 17 #include "llvm/IR/Constants.h" 19 using namespace clang;
20 using namespace CodeGen;
25 return SS.
hasOneOf(SanitizerKind::Address | SanitizerKind::KernelAddress |
26 SanitizerKind::HWAddress | SanitizerKind::KernelHWAddress |
27 SanitizerKind::MemTag);
39 llvm::Metadata *LocDescr =
nullptr;
40 llvm::Metadata *GlobalName =
nullptr;
45 LocDescr = getLocationMetadata(Loc);
47 GlobalName = llvm::MDString::get(VMContext, Name);
50 llvm::Metadata *GlobalMetadata[] = {
51 llvm::ConstantAsMetadata::get(GV), LocDescr, GlobalName,
52 llvm::ConstantAsMetadata::get(
53 llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), IsDynInit)),
54 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
55 llvm::Type::getInt1Ty(VMContext), IsBlacklisted))};
57 llvm::MDNode *ThisGlobal = llvm::MDNode::get(VMContext, GlobalMetadata);
58 llvm::NamedMDNode *AsanGlobals =
59 CGM.
getModule().getOrInsertNamedMetadata(
"llvm.asan.globals");
60 AsanGlobals->addOperand(ThisGlobal);
64 const VarDecl &D,
bool IsDynInit) {
68 llvm::raw_string_ostream OS(QualName);
71 bool IsBlacklisted =
false;
73 if (
Attr->getMask() & SanitizerKind::Address)
87 I->setMetadata(CGM.
getModule().getMDKindID(
"nosanitize"),
91 llvm::MDNode *SanitizerMetadata::getLocationMetadata(
SourceLocation Loc) {
96 llvm::Metadata *LocMetadata[] = {
98 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
99 llvm::Type::getInt32Ty(VMContext), PLoc.
getLine())),
100 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
101 llvm::Type::getInt32Ty(VMContext), PLoc.
getColumn())),
103 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