[PATCH] D55217: [IR] Add NODISCARD to attribute functions

Brian Gesiak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 3 07:07:55 PST 2018


modocache created this revision.
modocache added reviewers: rnk, javed.absar.

Many functions on `llvm::AttributeList` and `llvm::AttributeSet` are
documented with "returns a new {list,set} because attribute
{lists,sets} are immutable." This documentation can be aided by the
addition of an attribute, `LLVM_NODISCARD`. Adding this prevents
unsuspecting users of the API from expecting
`AttributeList::setAttributes` from modifying the underlying list.

At the very least, it would have saved me a few hours of debugging, since I
had been doing just that! I had a bug in my program where I was calling
`setAttributes` but then passing in the unmutated `AttributeList`.
I tried adding LLVM_NODISCARD and confirmed that it would have made my bug
immediately obvious.


Repository:
  rL LLVM

https://reviews.llvm.org/D55217

Files:
  include/llvm/IR/Attributes.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55217.176399.patch
Type: text/x-patch
Size: 12755 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181203/71fe55b0/attachment.bin>


More information about the llvm-commits mailing list