[all-commits] [llvm/llvm-project] a29e67: [-Wunsafe-buffer-usage] Generate fix-it for local ...

Ziqing Luo via All-commits all-commits at lists.llvm.org
Tue Feb 7 13:18:16 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a29e67614c3b7018287e5f68c57bba7618aa880e
      https://github.com/llvm/llvm-project/commit/a29e67614c3b7018287e5f68c57bba7618aa880e
  Author: Ziqing Luo <ziqing at udel.edu>
  Date:   2023-02-07 (Tue, 07 Feb 2023)

  Changed paths:
    M clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
    M clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/Analysis/UnsafeBufferUsage.cpp
    M clang/lib/Sema/AnalysisBasedWarnings.cpp
    A clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp
    M clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp

  Log Message:
  -----------
  [-Wunsafe-buffer-usage] Generate fix-it for local variable declarations

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:
- it only transforms local variable declarations (no parameter declaration);
- it only considers single level pointers, i.e., pointers of type T * regardless of whether T is again a pointer;
- it only transforms to std::span types (no std::array, or std::span::iterator, or ...);
- 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.

Reviewed by: NoQ, jkorous

Differential revision: https://reviews.llvm.org/D139737




More information about the All-commits mailing list