[all-commits] [llvm/llvm-project] 7c3ad9: [-Wunsafe-buffer-usage] Fix fixits for span initia...
jkorous-apple via All-commits
all-commits at lists.llvm.org
Fri Feb 16 13:11:04 PST 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 7c3ad9e72bc034ad655a7e16aa73b9864c58768b
https://github.com/llvm/llvm-project/commit/7c3ad9e72bc034ad655a7e16aa73b9864c58768b
Author: jkorous-apple <32549412+jkorous-apple at users.noreply.github.com>
Date: 2024-02-16 (Fri, 16 Feb 2024)
Changed paths:
M clang/lib/Analysis/UnsafeBufferUsage.cpp
A clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-array-inits-ptr.cpp
M clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp
Log Message:
-----------
[-Wunsafe-buffer-usage] Fix fixits for span initialized from const size array (#81927)
Example:
int arr[10];
int * ptr = arr;
If ptr is unsafe and we transform it to std::span then the fixit we'd
currently provide transforms the code to:
std::span<int> ptr{arr, 10};
That's suboptimal as that repeats the size of the array in the code.
The idiomatic transformation should rely on the span constructor
that takes just the array argument and relies on template
parameter autodeduction to set the span size.
The transformed code should look like:
std::span<int> ptr = arr;
Note that it just should not change the initializer at all and that also
works for other forms of initialization like:
int * ptr {arr};
becoming:
std::span<int> ptr{arr};
This patch changes the initializer handling to the desired (empty)
fixit.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list