This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8ac137acefc0: [NFC] Add checks for self-assignment. 
(authored by schittir).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155776/new/

https://reviews.llvm.org/D155776

Files:
  clang/lib/AST/APValue.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Interpreter/Value.cpp


Index: clang/lib/Interpreter/Value.cpp
===================================================================
--- clang/lib/Interpreter/Value.cpp
+++ 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;
 }
 
Index: clang/lib/CodeGen/CGDebugInfo.h
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -832,8 +832,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;
   }
 
Index: clang/lib/AST/APValue.cpp
===================================================================
--- clang/lib/AST/APValue.cpp
+++ 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;
 }
 


Index: clang/lib/Interpreter/Value.cpp
===================================================================
--- clang/lib/Interpreter/Value.cpp
+++ 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;
 }
 
Index: clang/lib/CodeGen/CGDebugInfo.h
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -832,8 +832,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;
   }
 
Index: clang/lib/AST/APValue.cpp
===================================================================
--- clang/lib/AST/APValue.cpp
+++ 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;
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to