[-Wunsafe-buffer-usage] Add Fixable for dereference of simple ptr arithmetic
authorziqingluo-90 <ziqing@udel.edu>
Mon, 20 Mar 2023 23:57:50 +0000 (16:57 -0700)
committerziqingluo-90 <ziqing@udel.edu>
Tue, 21 Mar 2023 00:07:03 +0000 (17:07 -0700)
commit6a0f2e539b8ef1f510f62aceb36430b95e40f0d3
treea94a2b245bdf9e2657b0b48474d37a6fad280258
parentb6f7e598ac1d72377cdcf5da84526f6289af13ca
[-Wunsafe-buffer-usage] Add Fixable for dereference of simple ptr arithmetic

For each expression `e` of the form `*(DRE + n)` (or `*(n + DRE)`), where
`DRE` has a pointer type and `n` is an integer literal, `e` will be
transformed to `DRE[n]` (or `n[DRE]` respectively), if
- `e` is at the left-hand side of an assignment or is an lvalue being casted to an rvalue; and
- the variable referred by `DRE` is going to be transformed to be of `std::span` type.

Reviewed by: jkorous, NoQ

Differential revision: https://reviews.llvm.org/D142795
clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-deref-simple-ptr-arith.cpp [new file with mode: 0644]