Skip to content

Commit

Permalink
[NFC] Add checks for self-assignment.
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D155776
  • Loading branch information
schittir committed Aug 24, 2023
1 parent ba7cb62 commit 4ad8913
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
12 changes: 7 additions & 5 deletions clang/lib/AST/APValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,13 @@ APValue &APValue::operator=(const APValue &RHS) {
}

APValue &APValue::operator=(APValue &&RHS) {
if (Kind != None && Kind != Indeterminate)
DestroyDataAndMakeUninit();
Kind = RHS.Kind;
Data = RHS.Data;
RHS.Kind = None;
if (this != &RHS) {
if (Kind != None && Kind != Indeterminate)
DestroyDataAndMakeUninit();
Kind = RHS.Kind;
Data = RHS.Data;
RHS.Kind = None;
}
return *this;
}

Expand Down
6 changes: 4 additions & 2 deletions clang/lib/CodeGen/CGDebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,10 @@ class ApplyDebugLocation {

// Define copy assignment operator.
ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
CGF = Other.CGF;
Other.CGF = nullptr;
if (this != &Other) {
CGF = Other.CGF;
Other.CGF = nullptr;
}
return *this;
}

Expand Down
17 changes: 9 additions & 8 deletions clang/lib/Interpreter/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,17 @@ Value &Value::operator=(const Value &RHS) {
}

Value &Value::operator=(Value &&RHS) noexcept {
if (IsManuallyAlloc)
ValueStorage::getFromPayload(getPtr())->Release();
if (this != &RHS) {
if (IsManuallyAlloc)
ValueStorage::getFromPayload(getPtr())->Release();

Interp = std::exchange(RHS.Interp, nullptr);
OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);

Data = RHS.Data;
Interp = std::exchange(RHS.Interp, nullptr);
OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);

Data = RHS.Data;
}
return *this;
}

Expand Down

0 comments on commit 4ad8913

Please sign in to comment.