[IR] Add NODISCARD to attribute functions
authorBrian Gesiak <modocache@gmail.com>
Wed, 5 Dec 2018 15:33:55 +0000 (15:33 +0000)
committerBrian Gesiak <modocache@gmail.com>
Wed, 5 Dec 2018 15:33:55 +0000 (15:33 +0000)
commitdf843bddfbf53b20b995c154546d57b1ada90c20
treeee4b93adb2af352f58ec5d893b936051b91c87f7
parent5b4db77b13525458d970c6bd85d726ba2f48da5a
[IR] Add NODISCARD to attribute functions

Summary:
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.

Reviewers: rnk, javed.absar

Reviewed By: rnk

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D55217

llvm-svn: 348372
llvm/include/llvm/IR/Attributes.h