diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp --- a/clang/lib/AST/APValue.cpp +++ b/clang/lib/AST/APValue.cpp @@ -390,11 +390,13 @@ } 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; } diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -835,8 +835,10 @@ // 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; } diff --git a/clang/lib/Interpreter/Value.cpp b/clang/lib/Interpreter/Value.cpp --- a/clang/lib/Interpreter/Value.cpp +++ b/clang/lib/Interpreter/Value.cpp @@ -201,16 +201,17 @@ } 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; }