16 #include "llvm/ADT/StringRef.h" 17 #include "llvm/IR/Constants.h" 19 using namespace clang;
20 using namespace CodeGen;
29 SanitizerKind::KernelAddress |
30 SanitizerKind::HWAddress |
31 SanitizerKind::KernelHWAddress))
36 llvm::Metadata *LocDescr =
nullptr;
37 llvm::Metadata *GlobalName =
nullptr;
42 LocDescr = getLocationMetadata(Loc);
44 GlobalName = llvm::MDString::get(VMContext, Name);
47 llvm::Metadata *GlobalMetadata[] = {
48 llvm::ConstantAsMetadata::get(GV), LocDescr, GlobalName,
49 llvm::ConstantAsMetadata::get(
50 llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), IsDynInit)),
51 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
52 llvm::Type::getInt1Ty(VMContext), IsBlacklisted))};
54 llvm::MDNode *ThisGlobal = llvm::MDNode::get(VMContext, GlobalMetadata);
55 llvm::NamedMDNode *AsanGlobals =
56 CGM.
getModule().getOrInsertNamedMetadata(
"llvm.asan.globals");
57 AsanGlobals->addOperand(ThisGlobal);
61 const VarDecl &D,
bool IsDynInit) {
63 SanitizerKind::KernelAddress |
64 SanitizerKind::HWAddress |
65 SanitizerKind::KernelHWAddress))
68 llvm::raw_string_ostream OS(QualName);
71 bool IsBlacklisted =
false;
73 if (
Attr->getMask() & SanitizerKind::Address)
83 SanitizerKind::KernelAddress |
84 SanitizerKind::HWAddress |
85 SanitizerKind::KernelHWAddress))
90 I->setMetadata(CGM.
getModule().getMDKindID(
"nosanitize"),
94 llvm::MDNode *SanitizerMetadata::getLocationMetadata(
SourceLocation Loc) {
99 llvm::Metadata *LocMetadata[] = {
100 llvm::MDString::get(VMContext, PLoc.
getFilename()),
101 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
102 llvm::Type::getInt32Ty(VMContext), PLoc.
getLine())),
103 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
104 llvm::Type::getInt32Ty(VMContext), PLoc.
getColumn())),
106 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