18using namespace CodeGen;
23 return SS.
hasOneOf(SanitizerKind::Address | SanitizerKind::KernelAddress |
24 SanitizerKind::HWAddress | SanitizerKind::MemTag |
29 if (Mask & (SanitizerKind::Address | SanitizerKind::KernelAddress))
30 Mask |= SanitizerKind::Address | SanitizerKind::KernelAddress;
39 if (G.getName().starts_with(
"llvm.") || G.isThreadLocal() || G.isConstant())
78 FsanitizeArgument.
Mask};
80 llvm::GlobalVariable::SanitizerMetadata Meta;
81 if (GV->hasSanitizerMetadata())
82 Meta = GV->getSanitizerMetadata();
84 Meta.NoAddress |= NoSanitizeAttrSet.
hasOneOf(SanitizerKind::Address);
86 FsanitizeArgument.
Mask & SanitizerKind::Address, GV,
Loc, Ty);
88 Meta.NoHWAddress |= NoSanitizeAttrSet.
hasOneOf(SanitizerKind::HWAddress);
90 FsanitizeArgument.
Mask & SanitizerKind::HWAddress, GV,
Loc, Ty);
93 Meta.Memtag |=
static_cast<bool>(FsanitizeArgument.
Mask &
94 SanitizerKind::MemtagGlobals);
95 Meta.Memtag &= !NoSanitizeAttrSet.
hasOneOf(SanitizerKind::MemTag);
97 FsanitizeArgument.
Mask & SanitizerKind::MemTag, GV,
Loc, Ty);
102 Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
103 FsanitizeArgument.
has(SanitizerKind::Address) &&
105 SanitizerKind::KernelAddress,
106 GV,
Loc, Ty,
"init");
108 GV->setSanitizerMetadata(Meta);
111 NoSanitizeAttrMask & SanitizerKind::Type)
118 llvm::Metadata *GlobalMetadata[] = {llvm::ConstantAsMetadata::get(GV),
122 if (llvm::MDNode::getIfExists(CGM.
getLLVMContext(), GlobalMetadata))
125 llvm::MDNode *ThisGlobal =
127 llvm::NamedMDNode *TysanGlobals =
128 CGM.
getModule().getOrInsertNamedMetadata(
"llvm.tysan.globals");
129 TysanGlobals->addOperand(ThisGlobal);
136 std::string QualName;
137 llvm::raw_string_ostream OS(QualName);
138 D.printQualifiedName(OS);
140 auto getNoSanitizeMask = [](
const VarDecl &
D) {
141 if (
D.
hasAttr<DisableSanitizerInstrumentationAttr>())
142 return SanitizerKind::All;
146 NoSanitizeMask |=
Attr->getMask();
148 if (
D.hasExternalStorage())
149 NoSanitizeMask |= SanitizerKind::Type;
151 return NoSanitizeMask;
C Language Family Type Representation.
Attr - This represents one attribute.
This class organizes the cross-function state that is used while generating LLVM code.
llvm::Module & getModule() const
bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn, SourceLocation Loc) const
const LangOptions & getLangOpts() const
ASTContext & getContext() const
llvm::MDNode * getTBAATypeInfo(QualType QTy)
getTBAATypeInfo - Get metadata used to describe accesses to objects of the given type.
llvm::LLVMContext & getLLVMContext()
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
SourceLocation getLocation() const
SanitizerSet Sanitize
Set of enabled sanitizers.
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Encodes a location in the source.
Represents a variable declaration or definition.
The JSON file list parser is used to communicate input to InstallAPI.
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
SanitizerMask Mask
Bitmask of enabled sanitizers.
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.