[PATCH] D91055: [clang-tidy] Introduce misc No Integer To Pointer Cast check

Aaron Ballman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 8 09:38:52 PST 2020


aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!



================
Comment at: clang-tools-extra/clang-tidy/performance/NoIntToPtrCheck.cpp:21
+  Finder->addMatcher(castExpr(hasCastKind(CK_IntegralToPointer),
+                              unless(hasSourceExpression(integerLiteral())))
+                         .bind("x"),
----------------
aaron.ballman wrote:
> Do we also want to exclude the case where the destination is a `volatile` pointer on the assumption that something out of the ordinary is going on. e.g.,
> ```
> intptr_t addr;
> if (something) {
>   addr = SOME_CONSTANT;
> } else {
>   addr = SOME_OTHER_CONSTANT;
> }
> volatile int *register_bank = (volatile int *)addr;
> ```
On reflection, I think we can make an adjustment here if there's user feedback that it's a frequent false positive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91055



More information about the llvm-commits mailing list