[all-commits] [llvm/llvm-project] e7596a: [-Wunsafe-buffer-usage] Add Fixable for simple poi...

Malavika Samak via All-commits all-commits at lists.llvm.org
Wed Mar 22 15:38:54 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e7596a99fca6d1df14275f5293e447a4d87af06a
      https://github.com/llvm/llvm-project/commit/e7596a99fca6d1df14275f5293e447a4d87af06a
  Author: MalavikaSamak <malavika2 at apple.com>
  Date:   2023-03-22 (Wed, 22 Mar 2023)

  Changed paths:
    M clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
    M clang/lib/Analysis/UnsafeBufferUsage.cpp
    A clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-deref.cpp

  Log Message:
  -----------
  [-Wunsafe-buffer-usage] Add Fixable for simple pointer dereference

This patch introduces PointerDereferenceGadget, a FixableGadget that emits
fixits to handle cases where a pointer that is identified as unsafe is
dereferenced. The current implementation only handles cases where the strategy
is to change the type of the raw pointer to std::span. The fixit for this
strategy is to fetch the first element from the corresponding span instance.

For example for the code below, the PointerDereferenceGadget emits a fixit for
S3 (S1, S2 are to be handled by other gadgets):

  S1: int *ptr = new int[10];
  S2: int val1 = ptr[k]; // Unsafe operation
  S3: int val2 = *ptr; => Fixit: int val2 = ptr[0];

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




More information about the All-commits mailing list