llvm-project/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-main.cpp
ziqingluo-90 1e270be088 [-Wunsafe-buffer-usage] Add fix-its for function parameters using the span strategy
Generate fix-its for function parameters that are raw pointers used
unsafely.  Currently, the analyzer fixes one parameter at a time.

Fix-its for a function parameter includes:

- Fix the parameter declaration of the definition, result in a new
  overload of the function. We call the function with the original
  signature the old overload.
- For any other existing declaration of the old overload, mark it with
  the [[unsafe_buffer_usage]] attribute and generate a new overload
  declaration next to it.
- Creates a new definition for the old overload, which is simply
  defined by a call to the new overload.

Reviewed by: NoQ (Artem Dergachev), t-rasmud (Rashmi Mudduluru), and
             jkorous (Jan Korous)

Differential revision: https://reviews.llvm.org/D143048
2023-06-09 15:44:38 -07:00

14 lines
629 B
C++

// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage -fcxx-exceptions -fsafe-buffer-usage-suggestions -verify %s
// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fcxx-exceptions -fdiagnostics-parseable-fixits -fsafe-buffer-usage-suggestions %s 2>&1 | FileCheck %s
// We do not fix parameters of the `main` function
// CHECK-NOT: fix-it:
// main function
int main(int argc, char *argv[]) { // expected-warning{{'argv' is an unsafe pointer used for buffer access}}
char tmp;
tmp = argv[5][5]; // expected-note{{used in buffer access here}} \
expected-warning{{unsafe buffer access}}
}