[-Wunsafe-buffer-usage] Improve fix-its for local variable declarations with null...
authorziqingluo-90 <ziqing@udel.edu>
Mon, 10 Apr 2023 18:54:11 +0000 (11:54 -0700)
committerziqingluo-90 <ziqing@udel.edu>
Mon, 10 Apr 2023 19:08:30 +0000 (12:08 -0700)
commit63413015099bc8aaa45cba7551e8fe432b2b795f
treedb96406a9b02d659828184f31fc4431f994d8e09
parent5e57f1bf52834cd5133011624c9bbc8cbf58c272
[-Wunsafe-buffer-usage] Improve fix-its for local variable declarations with null pointer initializers

For a local pointer declaration of the form `T * p = 0` or `T * p = std::nullptr`,

Before this patch, we generate fix-its that convert the declaration to
`std::span<T> p{nullptr, <# placeholder #>}`, in cases where `p` is
used in some unsafe operations.  This patch improves the fix-its to
result in a simpler form `std::span<T> p`. It gets rid of the
placeholder and keeps the result concise.

Reviewed by: NoQ (Artem Dergachev)

Differential Revision: https://reviews.llvm.org/D143680
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp