diff options
author | Guozhi Wei <carrot@google.com> | 2021-03-25 14:50:18 -0700 |
---|---|---|
committer | Guozhi Wei <carrot@google.com> | 2021-03-25 14:53:22 -0700 |
commit | 3240910f000625957a6a01ff8758c892f72a3a0d (patch) | |
tree | dfc79ee9528c9599649ae4be0b85756f30f4c84f /llvm/lib/IR/Attributes.cpp | |
parent | 4f5e92cc0562629ad2180b3ed2b0dad31ef7797c (diff) | |
download | llvm-3240910f000625957a6a01ff8758c892f72a3a0d.zip llvm-3240910f000625957a6a01ff8758c892f72a3a0d.tar.gz llvm-3240910f000625957a6a01ff8758c892f72a3a0d.tar.bz2 |
[DAE] Adjust param/arg attributes when changing parameter to undef
In DeadArgumentElimination pass, if a function's argument is never used, corresponding caller's parameter can be changed to undef. If the param/arg has attribute noundef or other related attributes, LLVM LangRef(https://llvm.org/docs/LangRef.html#parameter-attributes) says its behavior is undefined. SimplifyCFG(D97244) takes advantage of this behavior and does bad transformation on valid code.
To avoid this undefined behavior when change caller's parameter to undef, this patch removes noundef attribute and other attributes imply noundef on param/arg.
Differential Revision: https://reviews.llvm.org/D98899
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 4c087c9..831186a 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -1454,6 +1454,17 @@ AttributeList AttributeList::removeAttributes(LLVMContext &C, return getImpl(C, AttrSets); } +AttributeList +AttributeList::removeParamUndefImplyingAttributes(LLVMContext &C, + unsigned ArgNo) const { + AttrBuilder B; + B.addAttribute(Attribute::NoUndef); + B.addAttribute(Attribute::NonNull); + B.addDereferenceableAttr(1); + B.addDereferenceableOrNullAttr(1); + return removeParamAttributes(C, ArgNo, B); +} + AttributeList AttributeList::addDereferenceableAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const { |