[PATCH] D138318: [-Wunsafe-buffer-usage] Improve pointer match pattern
Ziqing Luo via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 1 12:15:52 PST 2022
ziqingluo-90 added inline comments.
================
Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:30-39
+ return anyOf(
+ hasType(pointerType()),
+ hasType(autoType(
+ hasDeducedType(hasUnqualifiedDesugaredType(pointerType())))),
+ // DecayedType, e.g., array type in formal parameter decl
+ hasType(decayedType(hasDecayedType(pointerType()))),
+ // ElaboratedType, e.g., typedef
----------------
================
Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:31
+ return anyOf(
+ hasType(pointerType()),
+ hasType(autoType(
----------------
aaron.ballman wrote:
> I shudder to ask this question, but ... pointer to member types?
My understanding is that a pointer-to-member type pointer cannot be used to do buffer access, i.e., one cannot do pointer addition on it. So we do not warn pointer-to-member themselves. In cases where the member type is a pointer, it has been covered.
I have added a test involving pointer to member types.
================
Comment at: clang/lib/Analysis/UnsafeBufferUsage.cpp:35
+ // DecayedType, e.g., array type in formal parameter decl
+ hasType(decayedType(hasDecayedType(pointerType()))),
+ // ElaboratedType, e.g., typedef
----------------
aaron.ballman wrote:
> hmmm, do you need to check `hasDecayedType(pointerType())`? What decay type *isn't* a pointer type?
you are right! Thanks for pointing this out.
================
Comment at: clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp:164
+}
+
+#endif
----------------
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138318/new/
https://reviews.llvm.org/D138318
More information about the cfe-commits
mailing list