[llvm] f2c0423 - [msan] Remove readnone and friends from call sites.
Evgenii Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 5 10:41:00 PDT 2020
Author: Evgenii Stepanov
Date: 2020-08-05T10:34:45-07:00
New Revision: f2c04239955a8e0d71aa27f7ffa3bbba6c623aef
URL: https://github.com/llvm/llvm-project/commit/f2c04239955a8e0d71aa27f7ffa3bbba6c623aef
DIFF: https://github.com/llvm/llvm-project/commit/f2c04239955a8e0d71aa27f7ffa3bbba6c623aef.diff
LOG: [msan] Remove readnone and friends from call sites.
MSan removes readnone/readonly and similar attributes from callees,
because after MSan instrumentation those attributes no longer apply.
This change removes the attributes from call sites, as well.
Failing to do this may cause DSE of paramTLS stores before calls to
readonly/readnone functions.
Differential Revision: https://reviews.llvm.org/D85259
Added:
Modified:
llvm/include/llvm/IR/InstrTypes.h
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
llvm/test/Instrumentation/MemorySanitizer/attributes.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index ce0744bbf087..00aa79c4a239 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -1451,6 +1451,12 @@ class CallBase : public Instruction {
setAttributes(PAL);
}
+ void removeAttributes(unsigned i, const AttrBuilder &Attrs) {
+ AttributeList PAL = getAttributes();
+ PAL = PAL.removeAttributes(getContext(), i, Attrs);
+ setAttributes(PAL);
+ }
+
/// Removes the attribute from the given argument
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
assert(ArgNo < getNumArgOperands() && "Out of bounds");
diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index 0f354c1da490..1613dc44b44d 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -3584,14 +3584,15 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
// will become a non-readonly function after it is instrumented by us. To
// prevent this code from being optimized out, mark that function
// non-readonly in advance.
+ AttrBuilder B;
+ B.addAttribute(Attribute::ReadOnly)
+ .addAttribute(Attribute::ReadNone)
+ .addAttribute(Attribute::WriteOnly)
+ .addAttribute(Attribute::ArgMemOnly)
+ .addAttribute(Attribute::Speculatable);
+
+ Call->removeAttributes(AttributeList::FunctionIndex, B);
if (Function *Func = Call->getCalledFunction()) {
- // Clear out readonly/readnone attributes.
- AttrBuilder B;
- B.addAttribute(Attribute::ReadOnly)
- .addAttribute(Attribute::ReadNone)
- .addAttribute(Attribute::WriteOnly)
- .addAttribute(Attribute::ArgMemOnly)
- .addAttribute(Attribute::Speculatable);
Func->removeAttributes(AttributeList::FunctionIndex, B);
}
diff --git a/llvm/test/Instrumentation/MemorySanitizer/attributes.ll b/llvm/test/Instrumentation/MemorySanitizer/attributes.ll
index 16f497109266..763857ebe217 100644
--- a/llvm/test/Instrumentation/MemorySanitizer/attributes.ll
+++ b/llvm/test/Instrumentation/MemorySanitizer/attributes.ll
@@ -13,24 +13,28 @@ declare void @e_() sanitize_memory speculatable
define void @a() sanitize_memory readnone {
entry:
call void @a_()
+ call void @a_() readnone
ret void
}
define void @b() sanitize_memory readonly {
entry:
call void @b_()
+ call void @b_() readonly
ret void
}
define void @c() sanitize_memory writeonly {
entry:
call void @c_()
+ call void @c_() writeonly
ret void
}
define void @d(i32* %p) sanitize_memory writeonly argmemonly {
entry:
call void @d_(i32* %p)
+ call void @d_(i32* %p) writeonly argmemonly
ret void
}
More information about the llvm-commits
mailing list