[PATCH] D47499: [analyzer] Annotate program state update methods with LLVM_NODISCARD.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 29 14:59:52 PDT 2018


NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet, rnkovacs, baloghadamsoftware.
Herald added a subscriber: cfe-commits.

A follow-up to https://reviews.llvm.org/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.

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.


Repository:
  rC Clang

https://reviews.llvm.org/D47499

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47499.148988.patch
Type: text/x-patch
Size: 10982 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180529/235bb38a/attachment-0001.bin>


More information about the cfe-commits mailing list