This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Annotate program state update methods with LLVM_NODISCARD.
ClosedPublic

Authored by NoQ on May 29 2018, 2:59 PM.

Details

Summary

A follow-up to D47496.

This would warn the developer on the very common bug that consists in writing, eg., State->set<Trait>(Key, Value) instead of State = State->set<Trait>(Key, Value). Because in the first snippet the updated State object is discarded while the original object remains unchanged (because it's, well, immutable), which isn't what you ever want to do.

LLVM_NODISCARD is essentially warn_unused_result.

For now no such bugs were found in the analyzer, but i made these mistakes myself knowingly and i see many such bugs during code review.

Diff Detail

Repository
rL LLVM

Event Timeline

NoQ created this revision.May 29 2018, 2:59 PM
NoQ edited the summary of this revision. (Show Details)May 29 2018, 3:00 PM
george.karpenkov accepted this revision.May 29 2018, 3:02 PM
This revision is now accepted and ready to land.May 29 2018, 3:02 PM
This revision was automatically updated to reflect the committed changes.