[clang] Guard against self-assignment; NFC (PR #145743)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 25 10:52:18 PDT 2025


================
@@ -6410,9 +6410,11 @@ class SpirvOperand {
   ~SpirvOperand() {}
 
   SpirvOperand &operator=(const SpirvOperand &Other) {
-    this->Kind = Other.Kind;
-    this->ResultType = Other.ResultType;
-    this->Value = Other.Value;
+    if (this != &Other) {
----------------
erichkeane wrote:

For comparison yes.  Sorry, my suggestion was for THIS, not for `operator==` (though TBH, I expected you to try both and tell my why it wouldn't work, and I hadn't recalled that we only added it for compare then :) ).  

But `operator=` should work with just `= default`.

My problem with the guard is how inexpensive the copy is (though I see `llvm::APInt` doesn't actually support self-move-assign, but DOES have the `this = &RHS` for copy) compared to a branch.

So `=default` would 'get it right'.



https://github.com/llvm/llvm-project/pull/145743


More information about the cfe-commits mailing list