[PATCH] D138321: [-Wunsafe-buffer-usage] Ignore array subscript on literal zero

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 15 19:03:46 PST 2022


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

LGTM!



================
Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:219
+        arraySubscriptExpr(hasBase(ignoringParenImpCasts(hasPointerType())),
+                           unless(hasIndex(integerLiteral(equals(0)))))
             .bind("arraySubscr"));
----------------
xazax.hun wrote:
> Isn't it the case you still want to cover zero indices but as a safe gadget to make sure fixits can be emitted? 
> Having to add another gadget for this makes me think maybe categorizing the safety of gadgets upfront is not the right model. 
So according to the discussion in D140062 it actually *is* the right model to decide safety up front, and then maybe even have some duplication, because the safe gadget has to provide a lot more context in the matcher in order for us to emit any fix at all. So the fixable gadget wouldn't be "same thing but with different index". It'd be "a completely different thing with completely arbitrary index".


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

https://reviews.llvm.org/D138321



More information about the cfe-commits mailing list