Skip to content

Commit 463a990

Browse files
committed
[-Wunsafe-buffer-usage] Move Strategy class to the header
It needs to be used from handleUnsafeVariableGroup function.
1 parent 86cd2fb commit 463a990

File tree

2 files changed

+140
-135
lines changed

2 files changed

+140
-135
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,43 @@ class VariableGroupsManager {
4242
virtual VarGrpRef getGroupOfParms() const =0;
4343
};
4444

45+
// FixitStrategy is a map from variables to the way we plan to emit fixes for
46+
// these variables. It is figured out gradually by trying different fixes
47+
// for different variables depending on gadgets in which these variables
48+
// participate.
49+
class FixitStrategy {
50+
public:
51+
enum class Kind {
52+
Wontfix, // We don't plan to emit a fixit for this variable.
53+
Span, // We recommend replacing the variable with std::span.
54+
Iterator, // We recommend replacing the variable with std::span::iterator.
55+
Array, // We recommend replacing the variable with std::array.
56+
Vector // We recommend replacing the variable with std::vector.
57+
};
58+
59+
private:
60+
using MapTy = llvm::DenseMap<const VarDecl *, Kind>;
61+
62+
MapTy Map;
63+
64+
public:
65+
FixitStrategy() = default;
66+
FixitStrategy(const FixitStrategy &) = delete; // Let's avoid copies.
67+
FixitStrategy &operator=(const FixitStrategy &) = delete;
68+
FixitStrategy(FixitStrategy &&) = default;
69+
FixitStrategy &operator=(FixitStrategy &&) = default;
70+
71+
void set(const VarDecl *VD, Kind K) { Map[VD] = K; }
72+
73+
Kind lookup(const VarDecl *VD) const {
74+
auto I = Map.find(VD);
75+
if (I == Map.end())
76+
return Kind::Wontfix;
77+
78+
return I->second;
79+
}
80+
};
81+
4582
/// The interface that lets the caller handle unsafe buffer usage analysis
4683
/// results by overriding this class's handle... methods.
4784
class UnsafeBufferUsageHandler {

0 commit comments

Comments
 (0)