[PATCH] D150338: [-Wunsafe-buffer-usage][WIP] Improving insertion of the [[clang::unsafe_buffer_usage]] attribute

Ziqing Luo via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 10 18:21:03 PDT 2023


ziqingluo-90 created this revision.
ziqingluo-90 added reviewers: jkorous, NoQ, malavikasamak, t-rasmud.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
ziqingluo-90 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For fix-its that insert `[[clang::unsafe_buffer_usage]]` attributes,  they will lookup existing macros defined for `[[clang::unsafe_buffer_usage]]` and use the (last defined such) macro directly.  Fix-its will use raw `[[clang::unsafe_buffer_usage]]` if no such macro is defined.

For example,

  // Suppose `foo` uses `p` in an unsafe way...
  
  void foo(int *p); // A fix-it will insert "[[clang::unsafe_buffer_usage]] " right before the declaration as there is no macro for the attribute defined here
  
  #define MACRO [[clang::unsafe_buffer_usage]]
  
  void foo(int *p); // A fix-it will insert "MACRO " right before the declaration

The implementation mimics how a similar machine for the  `[[fallthrough]]` attribute was implemented. (Mentioned here https://reviews.llvm.org/D143048#inline-1435398 )


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150338

Files:
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-attributes-spelling.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-include-header/warn-unsafe-buffer-usage-fixits-header-exists.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-include-header/warn-unsafe-buffer-usage-fixits-parm-in-header.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span-overload.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span-qualified-names.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-unsupported.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150338.521188.patch
Type: text/x-patch
Size: 22288 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230511/f0023d2f/attachment-0001.bin>


More information about the cfe-commits mailing list