Skip to content

Commit 33f6161

Browse files
committed
[-Wunsafe-buffer-usage] Group parameter fix-its
For a function `F` whose parameters need to be fixed, we group fix-its of F's parameters together so that either all of the parameters get fixed or none of them gets fixed. Reviewed by: NoQ (Artem Dergachev), t-rasmud (Rashmi Mudduluru), jkorous (Jan Korous) Differential revision: https://reviews.llvm.org/D153059
1 parent f548d19 commit 33f6161

File tree

7 files changed

+567
-104
lines changed

7 files changed

+567
-104
lines changed

clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class VariableGroupsManager {
3131
/// together in one step.
3232
///
3333
/// `Var` must be a variable that needs fix (so it must be in a group).
34-
virtual VarGrpRef getGroupOfVar(const VarDecl *Var) const =0;
34+
/// `HasParm` is an optional argument that will be set to true if the set of
35+
/// variables, where `Var` is in, contains parameters.
36+
virtual VarGrpRef getGroupOfVar(const VarDecl *Var,
37+
bool *HasParm = nullptr) const =0;
3538
};
3639

3740
/// The interface that lets the caller handle unsafe buffer usage analysis
@@ -62,11 +65,14 @@ class UnsafeBufferUsageHandler {
6265
bool IsRelatedToDecl) = 0;
6366

6467
/// Invoked when a fix is suggested against a variable. This function groups
65-
/// all variables that must be fixed together (i.e their types must be changed to the
66-
/// same target type to prevent type mismatches) into a single fixit.
68+
/// all variables that must be fixed together (i.e their types must be changed
69+
/// to the same target type to prevent type mismatches) into a single fixit.
70+
///
71+
/// `D` is the declaration of the callable under analysis that owns `Variable`
72+
/// and all of its group mates.
6773
virtual void handleUnsafeVariableGroup(const VarDecl *Variable,
6874
const VariableGroupsManager &VarGrpMgr,
69-
FixItList &&Fixes) = 0;
75+
FixItList &&Fixes, const Decl *D) = 0;
7076

7177
#ifndef NDEBUG
7278
public:

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11916,6 +11916,9 @@ def note_unsafe_buffer_operation : Note<
1191611916
"used%select{| in pointer arithmetic| in buffer access}0 here">;
1191711917
def note_unsafe_buffer_variable_fixit_group : Note<
1191811918
"change type of %0 to '%select{std::span|std::array|std::span::iterator}1' to preserve bounds information%select{|, and change %2 to '%select{std::span|std::array|std::span::iterator}1' to propagate bounds information between them}3">;
11919+
def note_unsafe_buffer_variable_fixit_together : Note<
11920+
"change type of %0 to '%select{std::span|std::array|std::span::iterator}1' to preserve bounds information"
11921+
"%select{|, and change %2 to safe types to make function %4 bounds-safe}3">;
1191911922
def note_safe_buffer_usage_suggestions_disabled : Note<
1192011923
"pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions">;
1192111924
#ifndef NDEBUG

0 commit comments

Comments
 (0)