This is an archive of the discontinued LLVM Phabricator instance.

[-Wunsafe-buffer-usage] Improve pointer match pattern
ClosedPublic

Authored by ziqingluo-90 on Nov 18 2022, 12:09 PM.

Details

Summary

This patch Improves the pointer-type matcher used by UnsafeBufferUsage checking by adding matchers for pointer types involving typedef, template instantiation, and decayed types. Corresponding tests are added.

Diff Detail

Event Timeline

ziqingluo-90 created this revision.Nov 18 2022, 12:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 18 2022, 12:09 PM
Herald added a subscriber: rnkovacs. · View Herald Transcript
ziqingluo-90 requested review of this revision.Nov 18 2022, 12:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 18 2022, 12:09 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
xazax.hun added inline comments.Nov 18 2022, 3:03 PM
clang/lib/Analysis/UnsafeBufferUsage.cpp
31–39

Isn't it possible to reduce the number of cases by using hasCanonicalType?

ziqingluo-90 added inline comments.Nov 28 2022, 3:30 PM
clang/lib/Analysis/UnsafeBufferUsage.cpp
31–39

aha, it simply works!

aaron.ballman added inline comments.Nov 30 2022, 9:51 AM
clang/lib/Analysis/UnsafeBufferUsage.cpp
31

I shudder to ask this question, but ... pointer to member types?

35

hmmm, do you need to check hasDecayedType(pointerType())? What decay type *isn't* a pointer type?

ziqingluo-90 added inline comments.Dec 1 2022, 12:15 PM
clang/lib/Analysis/UnsafeBufferUsage.cpp
30–31
31

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.

35

you are right! Thanks for pointing this out.

clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
164

Addressing comments.

NoQ accepted this revision.Dec 16 2022, 4:46 PM

Great!

This revision is now accepted and ready to land.Dec 16 2022, 4:46 PM
This revision was landed with ongoing or failed builds.Dec 16 2022, 8:41 PM
This revision was automatically updated to reflect the committed changes.