[PATCH] D66338: [CGP] Drop llvm.assume calls

Artem Dergachev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 16 13:14:28 PDT 2019


NoQ added a comment.

In D66338#1633249 <https://reviews.llvm.org/D66338#1633249>, @xbolva00 wrote:

> Side note:  As shown in this example, __attribute__((const)) on declarations seems like a bad idea. User may add  __attribute__((const)), then in the future introduce a side effect aaaand... compiler is happy, optimizers are happy, no warnings, weird binary. Can clang-tidy catch it? @aaron.ballman @NoQ GCC folks claim this is hard to do and say __attribute__((const)) is a best effort thing - you simply shouldn't do a mistake.


The Static Analyzer could be taught to catch it (unreliably - it's not a verifier!) as long as the definition of a side effect is precise enough ("doesn't write into global variables" is precise enough, "causes no observable change in program behavior" is not precise enough). I'm generally a big fan of having better purity/constness annotations but these current imprecisions are regularly driving me nuts. Clang-Tidy could catch a subset of cases syntactically (eg., it could catch all writes into global variables as long as they happen within the same function, but finding such bugs in a nested function call will be impossible without involving path-sensitive analysis or suffering from a certain class of false positives).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66338/new/

https://reviews.llvm.org/D66338





More information about the llvm-commits mailing list