[all-commits] [llvm/llvm-project] a046d1: [-Wunsafe-buffer-usage] FixableGadget for handling...

Malavika Samak via All-commits all-commits at lists.llvm.org
Fri Apr 7 15:32:36 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a046d187720137d944cece4aa4561f4bceb54e3c
      https://github.com/llvm/llvm-project/commit/a046d187720137d944cece4aa4561f4bceb54e3c
  Author: MalavikaSamak <malavika2 at apple.com>
  Date:   2023-04-07 (Fri, 07 Apr 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-access.cpp

  Log Message:
  -----------
  [-Wunsafe-buffer-usage] FixableGadget for handling stand alone pointers under UPC

This patch introduces UPCStandalonePointerGadget, a FixableGadget that emits fixits to
handle cases where a pointer identified as unsafe is simply referenced. An example of
such a case is when the pointer is input as an argument to a method call, where we can
not change the type of the argument. For cases where the strategy for the unsafe pointer is
to use std::span, the idea is to extract the underlying pointer by invoking the "data()"
method on the span instance.

For example, the gadget emits a fixit for S3, where S1, S2 are handled by other gadgets:
  S1: int *ptr = new int[10];
  S2: int val1 = ptr[k]; // Unsafe operation on ptr
  S3: foo(ptr); // Some method that accepts raw pointer => FIXIT: foo(ptr.data());

Reviewed by: NoQ, ziqingluo-90, jkorous

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




More information about the All-commits mailing list