[-Wunsafe-buffer-usage] Fix-Its transforming `&DRE[any]` to `&DRE.data()[any]`
authorziqingluo-90 <ziqing@udel.edu>
Tue, 4 Apr 2023 19:19:12 +0000 (12:19 -0700)
committerziqingluo-90 <ziqing@udel.edu>
Tue, 4 Apr 2023 20:26:45 +0000 (13:26 -0700)
commit87b5807d3802b932c06d83c4287014872aa2caab
tree824c7933c25c1f978903f10a63f852b37f585bee
parentc0df412ad2a5236a66ff1b608aeddc744b563e79
[-Wunsafe-buffer-usage] Fix-Its transforming `&DRE[any]` to `&DRE.data()[any]`

For an expression of the form `&DRE[any]` under an Unspecified
Pointer Context (UPC), we generate a fix-it for it with respect to a
strategy. In case the strategy is `std::span` (it is the only supported
one for now), the fix-it replaces the expression with
`&DRE.data()[any]`.

A UPC includes at least the contexts where
- the expression is being casted to an integer; and
- the expression is an argument of a call to a function that is not marked unsafe.

Reviewed by: NoQ, malavikasamak, t-rasmud, jkorous

Differential revision: https://reviews.llvm.org/D143128
clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-addressof-arraysubscript.cpp [new file with mode: 0644]