[llvm] 04623af - [ADT] Use try_emplace in SCCIterator.h (NFC) (#164187)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 19 21:56:20 PDT 2025


Author: Kazu Hirata
Date: 2025-10-19T21:56:16-07:00
New Revision: 04623afefcb9b3f84270b2a5c22476b1033e0384

URL: https://github.com/llvm/llvm-project/commit/04623afefcb9b3f84270b2a5c22476b1033e0384
DIFF: https://github.com/llvm/llvm-project/commit/04623afefcb9b3f84270b2a5c22476b1033e0384.diff

LOG: [ADT] Use try_emplace in SCCIterator.h (NFC) (#164187)

This patch replaces an unidiomatic operator[] usage with try_emplace
to ensure in-place NodeInfo construction and correct Group field
initialization.

This patch also clarifies the comment.  In particular, "insertion
operation" by itself isn't clear whether it's referring to insert() or
all of insertion operations like insert(), insert_or_assign(),
try_emplace(), etc.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/SCCIterator.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/SCCIterator.h b/llvm/include/llvm/ADT/SCCIterator.h
index 64ee217eeed61..205fa669a12de 100644
--- a/llvm/include/llvm/ADT/SCCIterator.h
+++ b/llvm/include/llvm/ADT/SCCIterator.h
@@ -313,10 +313,10 @@ scc_member_iterator<GraphT, GT>::scc_member_iterator(
   // Initialize auxilary node information.
   NodeInfoMap.clear();
   for (auto *Node : InputNodes) {
-    // This is specifically used to construct a `NodeInfo` object in place. An
-    // insert operation will involve a copy construction which invalidate the
-    // initial value of the `Group` field which should be `this`.
-    (void)NodeInfoMap[Node].Group;
+    // Construct a `NodeInfo` object in place.  `insert()` would involve a copy
+    // construction, invalidating the initial value of the `Group` field, which
+    // should be `this`.
+    NodeInfoMap.try_emplace(Node);
   }
 
   // Sort edges by weights.


        


More information about the llvm-commits mailing list