[PATCH] D139737: [-Wunsafe-buffer-usage] Initiate Fix-it generation for local variable declarations

Ziqing Luo via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 9 12:10:06 PST 2022


ziqingluo-90 created this revision.
ziqingluo-90 added reviewers: jkorous, NoQ, t-rasmud, malavikasamak, aaron.ballman, xazax.hun, gribozavr.
Herald added a subscriber: rnkovacs.
Herald added a project: All.
ziqingluo-90 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Use clang fix-its to transform declarations of local variables, which are used for buffer access , to be of `std::span` type.

We placed a few limitations to keep the solution simple:

1. it only transforms local variable declarations (no parameter declaration)
2. it only considers single level pointers, i.e., pointers of type `T *` regardless of whether `T` is again a pointer.
3. it only transforms to `std::span` types (no `std::array`, or `std::span::iterator`, or ...)
4. it can only transform a `VarDecl` that belongs to a `DeclStmt` whose has a single child.

One of the purposes of keeping this patch simple enough is to first evaluate if fix-it is an appropriate approach to do the transformation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139737

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139737.481714.patch
Type: text/x-patch
Size: 12588 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221209/9e2c46e4/attachment.bin>


More information about the cfe-commits mailing list