Skip to content

Commit b4fbc4b

Browse files
committed
[NFC][Clang][Coverity] Fix Static Code Analysis Concerns with copy without assign
This patch adds copy/move assignment operator to the class which has user-defined copy/move constructor. Reviewed By: tahonermann, NoQ, aaronpuchert Differential Revision: https://reviews.llvm.org/D150411
1 parent 8f061ed commit b4fbc4b

File tree

15 files changed

+92
-2
lines changed

15 files changed

+92
-2
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3210,7 +3210,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
32103210

32113211
public:
32123212
ObjCEncOptions() : Bits(0) {}
3213-
ObjCEncOptions(const ObjCEncOptions &RHS) : Bits(RHS.Bits) {}
32143213

32153214
#define OPT_LIST(V) \
32163215
V(ExpandPointedToStructures, 0) \

clang/include/clang/Analysis/Analyses/Consumed.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ namespace consumed {
155155
ConsumedStateMap(const ConsumedStateMap &Other)
156156
: Reachable(Other.Reachable), From(Other.From), VarMap(Other.VarMap) {}
157157

158+
// The copy assignment operator is defined as deleted pending further
159+
// motivation.
160+
ConsumedStateMap &operator=(const ConsumedStateMap &) = delete;
161+
158162
/// Warn if any of the parameters being tracked are not in the state
159163
/// they were declared to be in upon return from a function.
160164
void checkParamsForReturnTypestate(SourceLocation BlameLoc,

clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ class Undefined : public SExpr {
488488
Undefined(const Stmt *S = nullptr) : SExpr(COP_Undefined), Cstmt(S) {}
489489
Undefined(const Undefined &U) : SExpr(U), Cstmt(U.Cstmt) {}
490490

491+
// The copy assignment operator is defined as deleted pending further
492+
// motivation.
493+
Undefined &operator=(const Undefined &) = delete;
494+
491495
static bool classof(const SExpr *E) { return E->opcode() == COP_Undefined; }
492496

493497
template <class V>
@@ -566,6 +570,10 @@ class LiteralT : public Literal {
566570
LiteralT(T Dat) : Literal(ValueType::getValueType<T>()), Val(Dat) {}
567571
LiteralT(const LiteralT<T> &L) : Literal(L), Val(L.Val) {}
568572

573+
// The copy assignment operator is defined as deleted pending further
574+
// motivation.
575+
LiteralT &operator=(const LiteralT<T> &) = delete;
576+
569577
T value() const { return Val;}
570578
T& value() { return Val; }
571579

clang/include/clang/Analysis/Analyses/ThreadSafetyUtil.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ class CopyOnWriteVector {
240240

241241
VectorData() = default;
242242
VectorData(const VectorData &VD) : Vect(VD.Vect) {}
243+
244+
// The copy assignment operator is defined as deleted pending further
245+
// motivation.
246+
VectorData &operator=(const VectorData &) = delete;
243247
};
244248

245249
public:

clang/include/clang/Analysis/Support/BumpVector.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ class BumpVectorContext {
4242
Other.Alloc.setPointer(nullptr);
4343
}
4444

45+
// The move assignment operator is defined as deleted pending further
46+
// motivation.
47+
BumpVectorContext &operator=(BumpVectorContext &&) = delete;
48+
49+
// The copy constrcutor and copy assignment operator is defined as deleted
50+
// pending further motivation.
51+
BumpVectorContext(const BumpVectorContext &) = delete;
52+
BumpVectorContext &operator=(const BumpVectorContext &) = delete;
53+
4554
/// Construct a new BumpVectorContext that reuses an existing
4655
/// BumpPtrAllocator. This BumpPtrAllocator is not destroyed when the
4756
/// BumpVectorContext object is destroyed.

clang/include/clang/Rewrite/Core/RewriteRope.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ class RewriteRope {
181181
RewriteRope() = default;
182182
RewriteRope(const RewriteRope &RHS) : Chunks(RHS.Chunks) {}
183183

184+
// The copy assignment operator is defined as deleted pending further
185+
// motivation.
186+
RewriteRope &operator=(const RewriteRope &) = delete;
187+
184188
using iterator = RopePieceBTree::iterator;
185189
using const_iterator = RopePieceBTree::iterator;
186190

clang/include/clang/Sema/Lookup.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,15 @@ class LookupResult {
657657
F.CalledDone = true;
658658
}
659659

660+
// The move assignment operator is defined as deleted pending
661+
// further motivation.
662+
Filter &operator=(Filter &&) = delete;
663+
664+
// The copy constrcutor and copy assignment operator is defined as deleted
665+
// pending further motivation.
666+
Filter(const Filter &) = delete;
667+
Filter &operator=(const Filter &) = delete;
668+
660669
~Filter() {
661670
assert(CalledDone &&
662671
"LookupResult::Filter destroyed without done() call");

clang/include/clang/Sema/ParsedAttr.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,13 +696,19 @@ class AttributePool {
696696
AttributePool(AttributeFactory &factory) : Factory(factory) {}
697697

698698
AttributePool(const AttributePool &) = delete;
699+
// The copy assignment operator is defined as deleted pending further
700+
// motivation.
699701
AttributePool &operator=(const AttributePool &) = delete;
700702

701703
~AttributePool() { Factory.reclaimPool(*this); }
702704

703705
/// Move the given pool's allocations to this pool.
704706
AttributePool(AttributePool &&pool) = default;
705707

708+
// The move assignment operator is defined as deleted pending further
709+
// motivation.
710+
AttributePool &operator=(AttributePool &&pool) = delete;
711+
706712
AttributeFactory &getFactory() const { return Factory; }
707713

708714
void clear() {

clang/include/clang/Sema/Sema.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,12 @@ class Sema final {
17871787
const FunctionDecl *Fn, Sema &S);
17881788
SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D);
17891789
SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default;
1790+
1791+
// The copy and move assignment operator is defined as deleted pending
1792+
// further motivation.
1793+
SemaDiagnosticBuilder &operator=(const SemaDiagnosticBuilder &) = delete;
1794+
SemaDiagnosticBuilder &operator=(SemaDiagnosticBuilder &&) = delete;
1795+
17901796
~SemaDiagnosticBuilder();
17911797

17921798
bool isImmediate() const { return ImmediateDiag.has_value(); }

clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ class BugReporterVisitor : public llvm::FoldingSetNode {
5151
BugReporterVisitor() = default;
5252
BugReporterVisitor(const BugReporterVisitor &) = default;
5353
BugReporterVisitor(BugReporterVisitor &&) {}
54+
55+
// The copy and move assignment operator is defined as deleted pending further
56+
// motivation.
57+
BugReporterVisitor &operator=(const BugReporterVisitor &) = delete;
58+
BugReporterVisitor &operator=(BugReporterVisitor &&) = delete;
59+
5460
virtual ~BugReporterVisitor();
5561

5662
/// Return a diagnostic piece which should be associated with the

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,11 @@ class SymbolVisitor {
672672
SymbolVisitor(const SymbolVisitor &) = default;
673673
SymbolVisitor(SymbolVisitor &&) {}
674674

675+
// The copy and move assignment operator is defined as deleted pending further
676+
// motivation.
677+
SymbolVisitor &operator=(const SymbolVisitor &) = delete;
678+
SymbolVisitor &operator=(SymbolVisitor &&) = delete;
679+
675680
/// A visitor method invoked by ProgramStateManager::scanReachableSymbols.
676681
///
677682
/// The method returns \c true if symbols should continue be scanned and \c

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,13 @@ class ApplyDebugLocation {
829829
ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) {
830830
Other.CGF = nullptr;
831831
}
832-
ApplyDebugLocation &operator=(ApplyDebugLocation &&) = default;
832+
833+
// Define copy assignment operator.
834+
ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
835+
CGF = Other.CGF;
836+
Other.CGF = nullptr;
837+
return *this;
838+
}
833839

834840
~ApplyDebugLocation();
835841

clang/lib/CodeGen/EHScopeStack.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ class EHScopeStack {
148148
public:
149149
Cleanup(const Cleanup &) = default;
150150
Cleanup(Cleanup &&) {}
151+
152+
// The copy and move assignment operator is defined as deleted pending
153+
// further motivation.
154+
Cleanup &operator=(const Cleanup &) = delete;
155+
Cleanup &operator=(Cleanup &&) = delete;
156+
151157
Cleanup() = default;
152158

153159
virtual bool isRedundantBeforeReturn() { return false; }

clang/lib/Sema/SemaAccess.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ struct AccessTarget : public AccessedEntity {
199199
: Target(S.Target), Has(S.Has) {
200200
S.Target = nullptr;
201201
}
202+
203+
// The move assignment operator is defined as deleted pending further
204+
// motivation.
205+
SavedInstanceContext &operator=(SavedInstanceContext &&) = delete;
206+
207+
// The copy constrcutor and copy assignment operator is defined as deleted
208+
// pending further motivation.
209+
SavedInstanceContext(const SavedInstanceContext &) = delete;
210+
SavedInstanceContext &operator=(const SavedInstanceContext &) = delete;
211+
202212
~SavedInstanceContext() {
203213
if (Target)
204214
Target->HasInstanceContext = Has;

clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,14 @@ struct DiagnosticTextBuilder {
653653
Root(O.Root) {
654654
O.Root = nullptr;
655655
}
656+
// The move assignment operator is defined as deleted pending further
657+
// motivation.
658+
DiagText &operator=(DiagText &&) = delete;
659+
660+
// The copy constrcutor and copy assignment operator is defined as deleted
661+
// pending further motivation.
662+
DiagText(const DiagText &) = delete;
663+
DiagText &operator=(const DiagText &) = delete;
656664

657665
~DiagText() {
658666
for (Piece *P : AllocatedPieces)

0 commit comments

Comments
 (0)