16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/IR/Constants.h"
19 using namespace clang;
20 using namespace CodeGen;
29 SanitizerKind::KernelAddress))
34 llvm::Metadata *LocDescr =
nullptr;
35 llvm::Metadata *GlobalName =
nullptr;
40 LocDescr = getLocationMetadata(Loc);
42 GlobalName = llvm::MDString::get(VMContext, Name);
45 llvm::Metadata *GlobalMetadata[] = {
46 llvm::ConstantAsMetadata::get(GV), LocDescr, GlobalName,
47 llvm::ConstantAsMetadata::get(
48 llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), IsDynInit)),
49 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
50 llvm::Type::getInt1Ty(VMContext), IsBlacklisted))};
52 llvm::MDNode *ThisGlobal = llvm::MDNode::get(VMContext, GlobalMetadata);
53 llvm::NamedMDNode *AsanGlobals =
54 CGM.
getModule().getOrInsertNamedMetadata(
"llvm.asan.globals");
55 AsanGlobals->addOperand(ThisGlobal);
59 const VarDecl &D,
bool IsDynInit) {
61 SanitizerKind::KernelAddress))
64 llvm::raw_string_ostream OS(QualName);
73 SanitizerKind::KernelAddress))
78 I->setMetadata(CGM.
getModule().getMDKindID(
"nosanitize"),
82 llvm::MDNode *SanitizerMetadata::getLocationMetadata(
SourceLocation Loc) {
87 llvm::Metadata *LocMetadata[] = {
89 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
90 llvm::Type::getInt32Ty(VMContext), PLoc.
getLine())),
91 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
92 llvm::Type::getInt32Ty(VMContext), PLoc.
getColumn())),
94 return llvm::MDNode::get(VMContext, LocMetadata);
unsigned getColumn() const
Return the presumed column number of this location.
llvm::Module & getModule() const
llvm::LLVMContext & getLLVMContext()
SanitizerSet Sanitize
Set of enabled sanitizers.
unsigned getLine() const
Return the presumed line number of this location.
ASTContext & getContext() const
Represents an unpacked "presumed" location which can be presented to the user.
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.
const char * getFilename() const
Return the presumed filename of this location.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
const LangOptions & getLangOpts() const
void printQualifiedName(raw_ostream &OS) const
bool isInSanitizerBlacklist(llvm::Function *Fn, SourceLocation Loc) const
SourceManager & getSourceManager()
SourceLocation getLocation() const
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.