[clang] b4fbc4b - [NFC][Clang][Coverity] Fix Static Code Analysis Concerns with copy without assign
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 18 18:21:13 PDT 2023
Author: Manna, Soumi
Date: 2023-05-18T18:14:07-07:00
New Revision: b4fbc4bdbf58b9cecc9c66e8b8d97d3cebb5a976
URL: https://github.com/llvm/llvm-project/commit/b4fbc4bdbf58b9cecc9c66e8b8d97d3cebb5a976
DIFF: https://github.com/llvm/llvm-project/commit/b4fbc4bdbf58b9cecc9c66e8b8d97d3cebb5a976.diff
LOG: [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
Added:
Modified:
clang/include/clang/AST/ASTContext.h
clang/include/clang/Analysis/Analyses/Consumed.h
clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
clang/include/clang/Analysis/Analyses/ThreadSafetyUtil.h
clang/include/clang/Analysis/Support/BumpVector.h
clang/include/clang/Rewrite/Core/RewriteRope.h
clang/include/clang/Sema/Lookup.h
clang/include/clang/Sema/ParsedAttr.h
clang/include/clang/Sema/Sema.h
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/CodeGen/EHScopeStack.h
clang/lib/Sema/SemaAccess.cpp
clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index 8f0a82a7a50da..06ba21a3bf391 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -3210,7 +3210,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
public:
ObjCEncOptions() : Bits(0) {}
- ObjCEncOptions(const ObjCEncOptions &RHS) : Bits(RHS.Bits) {}
#define OPT_LIST(V) \
V(ExpandPointedToStructures, 0) \
diff --git a/clang/include/clang/Analysis/Analyses/Consumed.h b/clang/include/clang/Analysis/Analyses/Consumed.h
index d333fadff0478..7da4f75ecc027 100644
--- a/clang/include/clang/Analysis/Analyses/Consumed.h
+++ b/clang/include/clang/Analysis/Analyses/Consumed.h
@@ -155,6 +155,10 @@ namespace consumed {
ConsumedStateMap(const ConsumedStateMap &Other)
: Reachable(Other.Reachable), From(Other.From), VarMap(Other.VarMap) {}
+ // The copy assignment operator is defined as deleted pending further
+ // motivation.
+ ConsumedStateMap &operator=(const ConsumedStateMap &) = delete;
+
/// Warn if any of the parameters being tracked are not in the state
/// they were declared to be in upon return from a function.
void checkParamsForReturnTypestate(SourceLocation BlameLoc,
diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h b/clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
index eac402a791067..9e03b4badd121 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
@@ -488,6 +488,10 @@ class Undefined : public SExpr {
Undefined(const Stmt *S = nullptr) : SExpr(COP_Undefined), Cstmt(S) {}
Undefined(const Undefined &U) : SExpr(U), Cstmt(U.Cstmt) {}
+ // The copy assignment operator is defined as deleted pending further
+ // motivation.
+ Undefined &operator=(const Undefined &) = delete;
+
static bool classof(const SExpr *E) { return E->opcode() == COP_Undefined; }
template <class V>
@@ -566,6 +570,10 @@ class LiteralT : public Literal {
LiteralT(T Dat) : Literal(ValueType::getValueType<T>()), Val(Dat) {}
LiteralT(const LiteralT<T> &L) : Literal(L), Val(L.Val) {}
+ // The copy assignment operator is defined as deleted pending further
+ // motivation.
+ LiteralT &operator=(const LiteralT<T> &) = delete;
+
T value() const { return Val;}
T& value() { return Val; }
diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyUtil.h b/clang/include/clang/Analysis/Analyses/ThreadSafetyUtil.h
index 7792707e50250..ac7b24cdb4a6c 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyUtil.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyUtil.h
@@ -240,6 +240,10 @@ class CopyOnWriteVector {
VectorData() = default;
VectorData(const VectorData &VD) : Vect(VD.Vect) {}
+
+ // The copy assignment operator is defined as deleted pending further
+ // motivation.
+ VectorData &operator=(const VectorData &) = delete;
};
public:
diff --git a/clang/include/clang/Analysis/Support/BumpVector.h b/clang/include/clang/Analysis/Support/BumpVector.h
index 74092dabbfda9..6c3f11e993067 100644
--- a/clang/include/clang/Analysis/Support/BumpVector.h
+++ b/clang/include/clang/Analysis/Support/BumpVector.h
@@ -42,6 +42,15 @@ class BumpVectorContext {
Other.Alloc.setPointer(nullptr);
}
+ // The move assignment operator is defined as deleted pending further
+ // motivation.
+ BumpVectorContext &operator=(BumpVectorContext &&) = delete;
+
+ // The copy constrcutor and copy assignment operator is defined as deleted
+ // pending further motivation.
+ BumpVectorContext(const BumpVectorContext &) = delete;
+ BumpVectorContext &operator=(const BumpVectorContext &) = delete;
+
/// Construct a new BumpVectorContext that reuses an existing
/// BumpPtrAllocator. This BumpPtrAllocator is not destroyed when the
/// BumpVectorContext object is destroyed.
diff --git a/clang/include/clang/Rewrite/Core/RewriteRope.h b/clang/include/clang/Rewrite/Core/RewriteRope.h
index 8fa7af245eb81..73e66e111f574 100644
--- a/clang/include/clang/Rewrite/Core/RewriteRope.h
+++ b/clang/include/clang/Rewrite/Core/RewriteRope.h
@@ -181,6 +181,10 @@ class RewriteRope {
RewriteRope() = default;
RewriteRope(const RewriteRope &RHS) : Chunks(RHS.Chunks) {}
+ // The copy assignment operator is defined as deleted pending further
+ // motivation.
+ RewriteRope &operator=(const RewriteRope &) = delete;
+
using iterator = RopePieceBTree::iterator;
using const_iterator = RopePieceBTree::iterator;
diff --git a/clang/include/clang/Sema/Lookup.h b/clang/include/clang/Sema/Lookup.h
index 39d980a857b33..351fa0c6ca0cb 100644
--- a/clang/include/clang/Sema/Lookup.h
+++ b/clang/include/clang/Sema/Lookup.h
@@ -657,6 +657,15 @@ class LookupResult {
F.CalledDone = true;
}
+ // The move assignment operator is defined as deleted pending
+ // further motivation.
+ Filter &operator=(Filter &&) = delete;
+
+ // The copy constrcutor and copy assignment operator is defined as deleted
+ // pending further motivation.
+ Filter(const Filter &) = delete;
+ Filter &operator=(const Filter &) = delete;
+
~Filter() {
assert(CalledDone &&
"LookupResult::Filter destroyed without done() call");
diff --git a/clang/include/clang/Sema/ParsedAttr.h b/clang/include/clang/Sema/ParsedAttr.h
index cb27dd727f0ff..3612e9244f328 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -696,6 +696,8 @@ class AttributePool {
AttributePool(AttributeFactory &factory) : Factory(factory) {}
AttributePool(const AttributePool &) = delete;
+ // The copy assignment operator is defined as deleted pending further
+ // motivation.
AttributePool &operator=(const AttributePool &) = delete;
~AttributePool() { Factory.reclaimPool(*this); }
@@ -703,6 +705,10 @@ class AttributePool {
/// Move the given pool's allocations to this pool.
AttributePool(AttributePool &&pool) = default;
+ // The move assignment operator is defined as deleted pending further
+ // motivation.
+ AttributePool &operator=(AttributePool &&pool) = delete;
+
AttributeFactory &getFactory() const { return Factory; }
void clear() {
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5296d7000b5cc..aae1d9ce3208e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1787,6 +1787,12 @@ class Sema final {
const FunctionDecl *Fn, Sema &S);
SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D);
SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default;
+
+ // The copy and move assignment operator is defined as deleted pending
+ // further motivation.
+ SemaDiagnosticBuilder &operator=(const SemaDiagnosticBuilder &) = delete;
+ SemaDiagnosticBuilder &operator=(SemaDiagnosticBuilder &&) = delete;
+
~SemaDiagnosticBuilder();
bool isImmediate() const { return ImmediateDiag.has_value(); }
diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
index c479daea67838..9c81e02245ecd 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
@@ -51,6 +51,12 @@ class BugReporterVisitor : public llvm::FoldingSetNode {
BugReporterVisitor() = default;
BugReporterVisitor(const BugReporterVisitor &) = default;
BugReporterVisitor(BugReporterVisitor &&) {}
+
+ // The copy and move assignment operator is defined as deleted pending further
+ // motivation.
+ BugReporterVisitor &operator=(const BugReporterVisitor &) = delete;
+ BugReporterVisitor &operator=(BugReporterVisitor &&) = delete;
+
virtual ~BugReporterVisitor();
/// Return a diagnostic piece which should be associated with the
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
index b7ce6ebe98786..363eeba82d4c1 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -672,6 +672,11 @@ class SymbolVisitor {
SymbolVisitor(const SymbolVisitor &) = default;
SymbolVisitor(SymbolVisitor &&) {}
+ // The copy and move assignment operator is defined as deleted pending further
+ // motivation.
+ SymbolVisitor &operator=(const SymbolVisitor &) = delete;
+ SymbolVisitor &operator=(SymbolVisitor &&) = delete;
+
/// A visitor method invoked by ProgramStateManager::scanReachableSymbols.
///
/// The method returns \c true if symbols should continue be scanned and \c
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 5c42d3620bdbd..58ee6dd64c4fc 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -829,7 +829,13 @@ class ApplyDebugLocation {
ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) {
Other.CGF = nullptr;
}
- ApplyDebugLocation &operator=(ApplyDebugLocation &&) = default;
+
+ // Define copy assignment operator.
+ ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
+ CGF = Other.CGF;
+ Other.CGF = nullptr;
+ return *this;
+ }
~ApplyDebugLocation();
diff --git a/clang/lib/CodeGen/EHScopeStack.h b/clang/lib/CodeGen/EHScopeStack.h
index cd649cb11f9bc..4893689f856ea 100644
--- a/clang/lib/CodeGen/EHScopeStack.h
+++ b/clang/lib/CodeGen/EHScopeStack.h
@@ -148,6 +148,12 @@ class EHScopeStack {
public:
Cleanup(const Cleanup &) = default;
Cleanup(Cleanup &&) {}
+
+ // The copy and move assignment operator is defined as deleted pending
+ // further motivation.
+ Cleanup &operator=(const Cleanup &) = delete;
+ Cleanup &operator=(Cleanup &&) = delete;
+
Cleanup() = default;
virtual bool isRedundantBeforeReturn() { return false; }
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index 4a39c2d065e60..4af3c0f30a8e8 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -199,6 +199,16 @@ struct AccessTarget : public AccessedEntity {
: Target(S.Target), Has(S.Has) {
S.Target = nullptr;
}
+
+ // The move assignment operator is defined as deleted pending further
+ // motivation.
+ SavedInstanceContext &operator=(SavedInstanceContext &&) = delete;
+
+ // The copy constrcutor and copy assignment operator is defined as deleted
+ // pending further motivation.
+ SavedInstanceContext(const SavedInstanceContext &) = delete;
+ SavedInstanceContext &operator=(const SavedInstanceContext &) = delete;
+
~SavedInstanceContext() {
if (Target)
Target->HasInstanceContext = Has;
diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index 0b553254682ca..d412db62576eb 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -653,6 +653,14 @@ struct DiagnosticTextBuilder {
Root(O.Root) {
O.Root = nullptr;
}
+ // The move assignment operator is defined as deleted pending further
+ // motivation.
+ DiagText &operator=(DiagText &&) = delete;
+
+ // The copy constrcutor and copy assignment operator is defined as deleted
+ // pending further motivation.
+ DiagText(const DiagText &) = delete;
+ DiagText &operator=(const DiagText &) = delete;
~DiagText() {
for (Piece *P : AllocatedPieces)
More information about the cfe-commits
mailing list