[PATCH] D143128: [-Wunsafe-buffer-usage] Fix-Its transforming `&DRE[any]` to `(DRE.data() + any)`

Ziqing Luo via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 7 17:45:09 PST 2023


ziqingluo-90 updated this revision to Diff 503193.
ziqingluo-90 added a comment.

Thanks for the valuable discussion about the philosophy on the ideal forms of fix-its.  In this case, I think `&DRE.data()[any]` and `(DRE.data() + any)` are both straightforward enough for the user to tell what has been changed and why we change that.  And I believe both forms are idiomatic so that the user are likely happy with the form.   I will keep this discussion in mind as we have other cases whose fix-its may be less idiomatic, such as D144304 <https://reviews.llvm.org/D144304>.

Since we have to choose one form for this case, I buy @NoQ 's argument to use `&DRE.data()[any]`.

In addition, thanks to @t-rasmud for reminding me of that `&DRE[0]` can be converted to `DRE.data()` optimally.   In such a specific case, I think we do want it to be the most concise form without confusing the user.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143128/new/

https://reviews.llvm.org/D143128

Files:
  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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143128.503193.patch
Type: text/x-patch
Size: 11470 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230308/0ddce8b4/attachment-0001.bin>


More information about the cfe-commits mailing list