Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard against self-assignment in the DominatorTreeBase move assignment operator. #116464

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tahonermann
Copy link
Contributor

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.

…t 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.
@llvmbot
Copy link

llvmbot commented Nov 16, 2024

@llvm/pr-subscribers-llvm-support

Author: Tom Honermann (tahonermann)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/116464.diff

1 Files Affected:

  • (modified) llvm/include/llvm/Support/GenericDomTree.h (+2)
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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants