Skip to content

Commit 4ad8913

Browse files
committed
[NFC] Add checks for self-assignment.
Differential Revision: https://reviews.llvm.org/D155776
1 parent ba7cb62 commit 4ad8913

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

clang/lib/AST/APValue.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,13 @@ APValue &APValue::operator=(const APValue &RHS) {
390390
}
391391

392392
APValue &APValue::operator=(APValue &&RHS) {
393-
if (Kind != None && Kind != Indeterminate)
394-
DestroyDataAndMakeUninit();
395-
Kind = RHS.Kind;
396-
Data = RHS.Data;
397-
RHS.Kind = None;
393+
if (this != &RHS) {
394+
if (Kind != None && Kind != Indeterminate)
395+
DestroyDataAndMakeUninit();
396+
Kind = RHS.Kind;
397+
Data = RHS.Data;
398+
RHS.Kind = None;
399+
}
398400
return *this;
399401
}
400402

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,10 @@ class ApplyDebugLocation {
835835

836836
// Define copy assignment operator.
837837
ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
838-
CGF = Other.CGF;
839-
Other.CGF = nullptr;
838+
if (this != &Other) {
839+
CGF = Other.CGF;
840+
Other.CGF = nullptr;
841+
}
840842
return *this;
841843
}
842844

clang/lib/Interpreter/Value.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,17 @@ Value &Value::operator=(const Value &RHS) {
201201
}
202202

203203
Value &Value::operator=(Value &&RHS) noexcept {
204-
if (IsManuallyAlloc)
205-
ValueStorage::getFromPayload(getPtr())->Release();
204+
if (this != &RHS) {
205+
if (IsManuallyAlloc)
206+
ValueStorage::getFromPayload(getPtr())->Release();
206207

207-
Interp = std::exchange(RHS.Interp, nullptr);
208-
OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
209-
ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
210-
IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
211-
212-
Data = RHS.Data;
208+
Interp = std::exchange(RHS.Interp, nullptr);
209+
OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
210+
ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
211+
IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
213212

213+
Data = RHS.Data;
214+
}
214215
return *this;
215216
}
216217

0 commit comments

Comments
 (0)