[PATCH] D108808: [clang-tidy] bugprone-infinite-loop: Fix false positives with volatile addresses.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 27 02:23:06 PDT 2021


NoQ added a comment.

In D108808#2968721 <https://reviews.llvm.org/D108808#2968721>, @whisperity wrote:

> What happens for something like the following? Maybe it's also worth a test case?
>
>   bool wait_analogue_pin(volatile int* address, int threshold) {
>     while (*address < threshold) {}
>     return true;
>   }

These checkers dodge these cases by noticing that a loop condition relying on pointer-type variables, regardless of volatileness, may potentially alias with other things in the program and therefore be mutated at any moment without us noticing. The problem with concrete addresses wasn't that the check didn't know pointers cause problems, but that there weren't any variables in the expression to pay attention to. So I taught this sub-system to recognize these non-variables.

Banning pointer defererence operations entirely may still be a nicer solution that'd also allow us to simplify some code. I'll take a look.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D108808



More information about the cfe-commits mailing list