Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/include/llvm/IR/GlobalValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ class GlobalValue : public Constant {
void setSanitizerMetadata(SanitizerMetadata Meta);
void removeSanitizerMetadata();
void setNoSanitizeMetadata();
void disableSanitizerMetadataGlobalTagging();

bool isTagged() const {
return hasSanitizerMetadata() && getSanitizerMetadata().Memtag;
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/IR/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ void GlobalValue::setNoSanitizeMetadata() {
setSanitizerMetadata(Meta);
}

void GlobalValue::disableSanitizerMetadataGlobalTagging() {
if (!isTagged()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the braces are not need for 1 liner condition. ( git clang-format should handle it too)

return;
}

auto MD = getSanitizerMetadata();
MD.Memtag = false;
setSanitizerMetadata(MD);
}

StringRef GlobalObject::getSectionImpl() const {
assert(hasSection());
return getContext().pImpl->GlobalObjectSections[this];
Expand Down
5 changes: 4 additions & 1 deletion llvm/lib/Transforms/IPO/GlobalOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,7 @@ processInternalGlobal(GlobalVariable *GV, const GlobalStatus &GS,
if (GS.Ordering == AtomicOrdering::NotAtomic) {
assert(!GV->isConstant() && "Expected a non-constant global");
GV->setConstant(true);
GV->disableSanitizerMetadataGlobalTagging();
Changed = true;
}

Expand Down Expand Up @@ -2257,8 +2258,10 @@ static bool EvaluateStaticConstructor(Function *F, const DataLayout &DL,
<< " stores.\n");
for (const auto &Pair : NewInitializers)
Pair.first->setInitializer(Pair.second);
for (GlobalVariable *GV : Eval.getInvariants())
for (GlobalVariable *GV : Eval.getInvariants()) {
GV->setConstant(true);
GV->disableSanitizerMetadataGlobalTagging();
}
}

return EvalSuccess;
Expand Down