Skip to content

Conversation

kazutakahirata
Copy link
Contributor

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.

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

llvmbot commented Oct 19, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

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.


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

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/SCCIterator.h (+4-4)
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. 
@kazutakahirata kazutakahirata merged commit 04623af into llvm:main Oct 20, 2025
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20251019_ADT_SCCIterator branch October 20, 2025 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 participants