Skip to content

Commit 774b584

Browse files
committed
-Wdeprecated-clean: Fix cases of violating the rule of 5 in ways that are deprecated in C++11
Various value handles needed to be copy constructible and copy assignable (mostly for their use in DenseMap). But to avoid an API that might allow accidental slicing, make these members protected in the base class and make derived classes final (the special members become implicitly public there - but disallowing further derived classes that might be sliced to the intermediate type). Might be worth having a warning a bit like -Wnon-virtual-dtor that catches public move/copy assign/ctors in classes with virtual functions. (suppressable in the same way - by making them protected in the base, and making the derived classes final) Could be fancier and only diagnose them when they're actually called, potentially. Also allow a few default implementations where custom implementations (especially with non-standard return types) were implemented. llvm-svn: 243909
1 parent 5ff020a commit 774b584

12 files changed

+32
-34
lines changed

llvm/include/llvm/Analysis/AliasSetTracker.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ inline raw_ostream& operator<<(raw_ostream &OS, const AliasSet &AS) {
286286
class AliasSetTracker {
287287
/// CallbackVH - A CallbackVH to arrange for AliasSetTracker to be
288288
/// notified whenever a Value is deleted.
289-
class ASTCallbackVH : public CallbackVH {
289+
class ASTCallbackVH final : public CallbackVH {
290290
AliasSetTracker *AST;
291291
void deleted() override;
292292
void allUsesReplacedWith(Value *) override;

llvm/include/llvm/Analysis/AssumptionCache.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class AssumptionPrinterPass {
140140
class AssumptionCacheTracker : public ImmutablePass {
141141
/// A callback value handle applied to function objects, which we use to
142142
/// delete our cache of intrinsics for a function when it is deleted.
143-
class FunctionCallbackVH : public CallbackVH {
143+
class FunctionCallbackVH final : public CallbackVH {
144144
AssumptionCacheTracker *ACT;
145145
void deleted() override;
146146

llvm/include/llvm/Analysis/IVUsers.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DataLayout;
3434
/// The Expr member keeps track of the expression, User is the actual user
3535
/// instruction of the operand, and 'OperandValToReplace' is the operand of
3636
/// the User that is the use.
37-
class IVStrideUse : public CallbackVH, public ilist_node<IVStrideUse> {
37+
class IVStrideUse final : public CallbackVH, public ilist_node<IVStrideUse> {
3838
friend class IVUsers;
3939
public:
4040
IVStrideUse(IVUsers *P, Instruction* U, Value *O)

llvm/include/llvm/Analysis/ScalarEvolution.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ namespace llvm {
210210
private:
211211
/// SCEVCallbackVH - A CallbackVH to arrange for ScalarEvolution to be
212212
/// notified whenever a Value is deleted.
213-
class SCEVCallbackVH : public CallbackVH {
213+
class SCEVCallbackVH final : public CallbackVH {
214214
ScalarEvolution *SE;
215215
void deleted() override;
216216
void allUsesReplacedWith(Value *New) override;

llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ namespace llvm {
404404
/// value, and only represent it as its LLVM Value. This is the "bottom"
405405
/// value for the analysis.
406406
///
407-
class SCEVUnknown : public SCEV, private CallbackVH {
407+
class SCEVUnknown final : public SCEV, private CallbackVH {
408408
friend class ScalarEvolution;
409409

410410
// Implement CallbackVH.

llvm/include/llvm/IR/ValueHandle.h

+15-15
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,21 @@ class ValueHandleBase {
5252
Weak
5353
};
5454

55+
ValueHandleBase(const ValueHandleBase &RHS)
56+
: ValueHandleBase(RHS.PrevPair.getInt(), RHS) {}
57+
58+
ValueHandleBase(HandleBaseKind Kind, const ValueHandleBase &RHS)
59+
: PrevPair(nullptr, Kind), Next(nullptr), V(RHS.V) {
60+
if (isValid(V))
61+
AddToExistingUseList(RHS.getPrevPtr());
62+
}
63+
5564
private:
5665
PointerIntPair<ValueHandleBase**, 2, HandleBaseKind> PrevPair;
5766
ValueHandleBase *Next;
5867

5968
Value* V;
6069

61-
ValueHandleBase(const ValueHandleBase&) = delete;
6270
public:
6371
explicit ValueHandleBase(HandleBaseKind Kind)
6472
: PrevPair(nullptr, Kind), Next(nullptr), V(nullptr) {}
@@ -67,11 +75,7 @@ class ValueHandleBase {
6775
if (isValid(V))
6876
AddToUseList();
6977
}
70-
ValueHandleBase(HandleBaseKind Kind, const ValueHandleBase &RHS)
71-
: PrevPair(nullptr, Kind), Next(nullptr), V(RHS.V) {
72-
if (isValid(V))
73-
AddToExistingUseList(RHS.getPrevPtr());
74-
}
78+
7579
~ValueHandleBase() {
7680
if (isValid(V))
7781
RemoveFromUseList();
@@ -145,6 +149,8 @@ class WeakVH : public ValueHandleBase {
145149
WeakVH(const WeakVH &RHS)
146150
: ValueHandleBase(Weak, RHS) {}
147151

152+
WeakVH &operator=(const WeakVH &RHS) = default;
153+
148154
Value *operator=(Value *RHS) {
149155
return ValueHandleBase::operator=(RHS);
150156
}
@@ -314,7 +320,6 @@ class TrackingVH : public ValueHandleBase {
314320
public:
315321
TrackingVH() : ValueHandleBase(Tracking) {}
316322
TrackingVH(ValueTy *P) : ValueHandleBase(Tracking, GetAsValue(P)) {}
317-
TrackingVH(const TrackingVH &RHS) : ValueHandleBase(Tracking, RHS) {}
318323

319324
operator ValueTy*() const {
320325
return getValPtr();
@@ -324,10 +329,6 @@ class TrackingVH : public ValueHandleBase {
324329
setValPtr(RHS);
325330
return getValPtr();
326331
}
327-
ValueTy *operator=(const TrackingVH<ValueTy> &RHS) {
328-
setValPtr(RHS.getValPtr());
329-
return getValPtr();
330-
}
331332

332333
ValueTy *operator->() const { return getValPtr(); }
333334
ValueTy &operator*() const { return *getValPtr(); }
@@ -344,10 +345,9 @@ class TrackingVH : public ValueHandleBase {
344345
class CallbackVH : public ValueHandleBase {
345346
virtual void anchor();
346347
protected:
347-
CallbackVH(const CallbackVH &RHS)
348-
: ValueHandleBase(Callback, RHS) {}
349-
350-
virtual ~CallbackVH() {}
348+
~CallbackVH() = default;
349+
CallbackVH(const CallbackVH &) = default;
350+
CallbackVH &operator=(const CallbackVH &) = default;
351351

352352
void setValPtr(Value *P) {
353353
ValueHandleBase::operator=(P);

llvm/include/llvm/IR/ValueMap.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ class ValueMap {
214214

215215
// This CallbackVH updates its ValueMap when the contained Value changes,
216216
// according to the user's preferences expressed through the Config object.
217-
template<typename KeyT, typename ValueT, typename Config>
218-
class ValueMapCallbackVH : public CallbackVH {
217+
template <typename KeyT, typename ValueT, typename Config>
218+
class ValueMapCallbackVH final : public CallbackVH {
219219
friend class ValueMap<KeyT, ValueT, Config>;
220220
friend struct DenseMapInfo<ValueMapCallbackVH>;
221221
typedef ValueMap<KeyT, ValueT, Config> ValueMapT;

llvm/lib/Analysis/CFLAliasAnalysis.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,13 @@ struct FunctionInfo {
153153

154154
struct CFLAliasAnalysis;
155155

156-
struct FunctionHandle : public CallbackVH {
156+
struct FunctionHandle final : public CallbackVH {
157157
FunctionHandle(Function *Fn, CFLAliasAnalysis *CFLAA)
158158
: CallbackVH(Fn), CFLAA(CFLAA) {
159159
assert(Fn != nullptr);
160160
assert(CFLAA != nullptr);
161161
}
162162

163-
~FunctionHandle() override {}
164-
165163
void deleted() override { removeSelfFromCache(); }
166164
void allUsesReplacedWith(Value *) override { removeSelfFromCache(); }
167165

llvm/lib/Analysis/LazyValueInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ raw_ostream &operator<<(raw_ostream &OS, const LVILatticeVal &Val) {
295295
namespace {
296296
/// A callback value handle updates the cache when values are erased.
297297
class LazyValueInfoCache;
298-
struct LVIValueHandle : public CallbackVH {
298+
struct LVIValueHandle final : public CallbackVH {
299299
LazyValueInfoCache *Parent;
300300

301301
LVIValueHandle(Value *V, LazyValueInfoCache *P)

llvm/lib/CodeGen/MachineModuleInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ char MachineModuleInfo::ID = 0;
3535
MachineModuleInfoImpl::~MachineModuleInfoImpl() {}
3636

3737
namespace llvm {
38-
class MMIAddrLabelMapCallbackPtr : CallbackVH {
38+
class MMIAddrLabelMapCallbackPtr final : CallbackVH {
3939
MMIAddrLabelMap *Map;
4040
public:
4141
MMIAddrLabelMapCallbackPtr() : Map(nullptr) {}

llvm/lib/ExecutionEngine/ExecutionEngine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ ExecutionEngine::~ExecutionEngine() {
9595
namespace {
9696
/// \brief Helper class which uses a value handler to automatically deletes the
9797
/// memory block when the GlobalVariable is destroyed.
98-
class GVMemoryBlock : public CallbackVH {
98+
class GVMemoryBlock final : public CallbackVH {
9999
GVMemoryBlock(const GlobalVariable *GV)
100100
: CallbackVH(const_cast<GlobalVariable*>(GV)) {}
101101

llvm/unittests/IR/ValueHandleTest.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ValueHandle : public testing::Test {
2929
}
3030
};
3131

32-
class ConcreteCallbackVH : public CallbackVH {
32+
class ConcreteCallbackVH final : public CallbackVH {
3333
public:
3434
ConcreteCallbackVH(Value *V) : CallbackVH(V) {}
3535
};
@@ -235,7 +235,7 @@ TEST_F(ValueHandle, CallbackVH_Comparisons) {
235235
}
236236

237237
TEST_F(ValueHandle, CallbackVH_CallbackOnDeletion) {
238-
class RecordingVH : public CallbackVH {
238+
class RecordingVH final : public CallbackVH {
239239
public:
240240
int DeletedCalls;
241241
int AURWCalls;
@@ -261,7 +261,7 @@ TEST_F(ValueHandle, CallbackVH_CallbackOnDeletion) {
261261
}
262262

263263
TEST_F(ValueHandle, CallbackVH_CallbackOnRAUW) {
264-
class RecordingVH : public CallbackVH {
264+
class RecordingVH final : public CallbackVH {
265265
public:
266266
int DeletedCalls;
267267
Value *AURWArgument;
@@ -291,7 +291,7 @@ TEST_F(ValueHandle, CallbackVH_CallbackOnRAUW) {
291291
}
292292

293293
TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) {
294-
class RecoveringVH : public CallbackVH {
294+
class RecoveringVH final : public CallbackVH {
295295
public:
296296
int DeletedCalls;
297297
Value *AURWArgument;
@@ -339,7 +339,7 @@ TEST_F(ValueHandle, DestroyingOtherVHOnSameValueDoesntBreakIteration) {
339339
// arrangement of other VHs so that the bad behavior would be
340340
// triggered in whichever order callbacks run.
341341

342-
class DestroyingVH : public CallbackVH {
342+
class DestroyingVH final : public CallbackVH {
343343
public:
344344
std::unique_ptr<WeakVH> ToClear[2];
345345
DestroyingVH(Value *V) {
@@ -384,7 +384,7 @@ TEST_F(ValueHandle, AssertingVHCheckedLast) {
384384
// Value deletion, the CallbackVH should get a chance to do so
385385
// before the AssertingVHs assert.
386386

387-
class ClearingVH : public CallbackVH {
387+
class ClearingVH final : public CallbackVH {
388388
public:
389389
AssertingVH<Value> *ToClear[2];
390390
ClearingVH(Value *V,

0 commit comments

Comments
 (0)