[llvm] Guard against self-assignment in the DominatorTreeBase move assignment operator. (PR #116464)

Tom Honermann via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 15 18:44:12 PST 2024


https://github.com/tahonermann created https://github.com/llvm/llvm-project/pull/116464

The `DominatorTreeBase` move assignment operator was not self-assignment safe because the last thing it does before returning is to release all resources held by the source object. This issue was reported by a static analysis tool; no self-assignment is known to occur in practice.

>From 895a59ccce4311c840a555dd864fbce7c5605705 Mon Sep 17 00:00:00 2001
From: Tom Honermann <tom.honermann at intel.com>
Date: Fri, 15 Nov 2024 18:26:09 -0800
Subject: [PATCH] Guard against self-assignment in the DominatorTreeBase move
 assignment operator.

The DominatorTreeBase move assignment operator was not self-assignment safe
because the last thing it does before returning is to release all resources
held by the source object. This issue was reported by a static analysis tool;
no self-assignment is known to occur in practice.
---
 llvm/include/llvm/Support/GenericDomTree.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/include/llvm/Support/GenericDomTree.h b/llvm/include/llvm/Support/GenericDomTree.h
index 45ef38b965b752..d0eec2070b4d7e 100644
--- a/llvm/include/llvm/Support/GenericDomTree.h
+++ b/llvm/include/llvm/Support/GenericDomTree.h
@@ -287,6 +287,8 @@ class DominatorTreeBase {
   }
 
   DominatorTreeBase &operator=(DominatorTreeBase &&RHS) {
+    if (this == &RHS)
+      return *this;
     Roots = std::move(RHS.Roots);
     DomTreeNodes = std::move(RHS.DomTreeNodes);
     NodeNumberMap = std::move(RHS.NodeNumberMap);



More information about the llvm-commits mailing list