[-Wunsafe-buffer-usage] Initial commit - Transition away from raw buffers.
authorArtem Dergachev <adergachev@apple.com>
Fri, 2 Dec 2022 20:58:56 +0000 (12:58 -0800)
committerArtem Dergachev <adergachev@apple.com>
Mon, 5 Dec 2022 23:13:42 +0000 (15:13 -0800)
commit200007ec85f81122fd260a4e68308e54607ca37a
treeeed7b009e719757d3f01708528a6ba6002b7c88e
parentfe3103fa485f67b15efffd11d592a3341eb7bd57
[-Wunsafe-buffer-usage] Initial commit - Transition away from raw buffers.

This is the initial commit for -Wunsafe-buffer-usage, a warning that helps
codebases (especially modern C++ codebases) transition away from raw buffer
pointers.

The warning is implemented in libAnalysis as it's going to become a non-trivial
analysis, mostly the fixit part where we try to figure out if we understand
a variable's use pattern well enough to suggest a safe container/view
as a replacement. Some parts of this analsysis may eventually prove useful
for any similar fixit machine that tries to change types of variables.

The warning is disabled by default.

RFC/discussion in https://discourse.llvm.org/t/rfc-c-buffer-hardening/65734

Differential Revision: https://reviews.llvm.org/D137346
clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h [new file with mode: 0644]
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Analysis/CMakeLists.txt
clang/lib/Analysis/UnsafeBufferUsage.cpp [new file with mode: 0644]
clang/lib/Sema/AnalysisBasedWarnings.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp [new file with mode: 0644]