This is an archive of the discontinued LLVM Phabricator instance.

[-Wunsafe-buffer-usage] Ignore array subscript on literal zero
ClosedPublic

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

Details

Summary

Improving unsafe array subscript warning reporting.
For array subscripts with a literal zero index, no warning will be emitted.

Diff Detail

Event Timeline

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

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.

NoQ accepted this revision.Dec 15 2022, 7:03 PM

LGTM!

clang/lib/Analysis/UnsafeBufferUsage.cpp
192

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".

This revision is now accepted and ready to land.Dec 15 2022, 7:03 PM
This revision was landed with ongoing or failed builds.Dec 16 2022, 9:04 PM
This revision was automatically updated to reflect the committed changes.