[clang] [-Wunsafe-buffer-usage] Fixits for unsafe arguments of function pointer calls (PR #80358)

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 14 14:38:46 PST 2024


================
@@ -282,8 +282,8 @@ isInUnspecifiedPointerContext(internal::Matcher<Stmt> InnerMatcher) {
   //    (i.e., computing the distance between two pointers); or ...
 
   auto CallArgMatcher =
-      callExpr(forEachArgumentWithParam(InnerMatcher,
-                  hasPointerType() /* array also decays to pointer type*/),
+      callExpr(forEachArgumentWithParamType(InnerMatcher,
+                  isAnyPointer() /* array also decays to pointer type*/),
----------------
haoNoQ wrote:

Hmm looks like parameter types are always canonical. Probably because we need them to be the same for overloading purposes even if they're typedef'ed differently. The new code appears to be entirely equivalent to `hasCanonicalType(pointerType())` or just `pointerType()`.

Side note, `isAnyPointer()` only adds ObjC pointer types to the mix. We don't really care about ObjC pointers because you can't do pointer arithmetic on them. So might as well use `pointerType()`.

> Handling or not handling typedefs is the responsibility of `fixVariable` function and perhaps individual FixableGadgets' `getFixits()` method.

In many cases you need to actively skip typedefs in order to get the gadget to match at all. But it looks like, indeed, it doesn't matter in this case.

https://github.com/llvm/llvm-project/pull/80358


More information about the cfe-commits mailing list