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/Function.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/Function.cpp')
-rw-r--r-- | llvm/lib/IR/Function.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index ab8d425..7389ec6 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -562,6 +562,12 @@ void Function::removeParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) { setAttributes(PAL); } +void Function::removeParamUndefImplyingAttrs(unsigned ArgNo) { + AttributeList PAL = getAttributes(); + PAL = PAL.removeParamUndefImplyingAttributes(getContext(), ArgNo); + setAttributes(PAL); +} + void Function::addDereferenceableAttr(unsigned i, uint64_t Bytes) { AttributeList PAL = getAttributes(); PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes); |