This is an archive of the discontinued LLVM Phabricator instance.

[IR] Add NODISCARD to attribute functions
ClosedPublic

Authored by modocache on Dec 3 2018, 7:07 AM.

Details

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.

Diff Detail

Event Timeline

modocache created this revision.Dec 3 2018, 7:07 AM
rnk accepted this revision.Dec 3 2018, 2:56 PM

Looks good, assuming this doesn't trigger new warnings in LLVM & clang.

This revision is now accepted and ready to land.Dec 3 2018, 2:56 PM
This revision was automatically updated to reflect the committed changes.

Thanks! Yup, I confirmed no new warnings when building check-llvm and check-clang.

Oops, sorry, I didn't check hard enough. There's code for AMDGPU that runs up against this warning, causing some buildbots to fail: http://lab.llvm.org:8011/builders/lld-perf-testsuite/builds/9637/steps/build-bin%2Flld/logs/stdio

I can revert this, build all targets and fix the warnings, and then re-commit.