[llvm] b33350f - [ADT] Fix RadixTree singular iterator use in findOrCreate (#181510)

via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 14 21:10:03 PST 2026


Author: Brian Cain
Date: 2026-02-14T23:09:59-06:00
New Revision: b33350f5ff3a29508cf3ba69b10683afc378e905

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

LOG: [ADT] Fix RadixTree singular iterator use in findOrCreate (#181510)

The root node's Key is initialized with default-constructed (singular)
iterators. When findOrCreate calls llvm::mismatch(Key, Curr->Key) on the
first loop iteration where Curr is the root, these singular iterators
are passed to std::mismatch. _GLIBCXX_DEBUG correctly rejects them as
not forming a valid iterator range.

Skip the mismatch when Curr is the root node since its key is
conceptually empty, making the mismatch a no-op.

Fixes a test failure in ADTTests/RadixTreeTypeTest introduced by
5fda2a5d9c1a ("[NFC][ADT] Add RadixTree (#164524)").

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/RadixTree.h b/llvm/include/llvm/ADT/RadixTree.h
index 87e2a3ebecc06..694471e806e78 100644
--- a/llvm/include/llvm/ADT/RadixTree.h
+++ b/llvm/include/llvm/ADT/RadixTree.h
@@ -166,17 +166,22 @@ template <typename KeyType, typename T> class RadixTree {
       return *Curr;
 
     for (;;) {
-      auto [I1, I2] = llvm::mismatch(Key, Curr->Key);
-      Key = make_range(I1, Key.end());
-
-      if (I2 != Curr->Key.end()) {
-        // Match is partial. Either query is too short, or there is mismatching
-        // character. Split either way, and put new node in between of the
-        // current and its children.
-        Curr->split(I2);
-
-        // Split was caused by mismatch, so `findChild` would fail.
-        break;
+      // The root node's Key is default-constructed with singular iterators
+      // that cannot be passed to std::mismatch.  Since the root's key is
+      // conceptually empty the mismatch is a no-op: skip it.
+      if (Curr != &Root) {
+        auto [I1, I2] = llvm::mismatch(Key, Curr->Key);
+        Key = make_range(I1, Key.end());
+
+        if (I2 != Curr->Key.end()) {
+          // Match is partial. Either query is too short, or there is
+          // mismatching character. Split either way, and put new node in
+          // between of the current and its children.
+          Curr->split(I2);
+
+          // Split was caused by mismatch, so `findChild` would fail.
+          break;
+        }
       }
 
       Node *Child = Curr->findChild(Key);


        


More information about the llvm-commits mailing list