aboutsummaryrefslogtreecommitdiff
path: root/libcxxabi
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2022-10-20 07:10:47 -0400
committerNathan Sidwell <nathan@acm.org>2022-10-20 09:11:24 -0400
commitc7ca21436d626b188d87774044d4c087cbbe7fcf (patch)
treed42aa6f3a4aa7a502af68f44138014bc11f54de7 /libcxxabi
parenta401ce441694612df21e7c29f6aabd89aff6ca6c (diff)
downloadllvm-c7ca21436d626b188d87774044d4c087cbbe7fcf.zip
llvm-c7ca21436d626b188d87774044d4c087cbbe7fcf.tar.gz
llvm-c7ca21436d626b188d87774044d4c087cbbe7fcf.tar.bz2
libcxxabi [PR58117][NFC]: Open code lower bound
This open codes the use of lower-bound when looking for an operator encoding. Using std::lower_bound can result in symbol references to the C++ library and that breaks the ABI demangler, which mandates no such dependency. Differential Revision: https://reviews.llvm.org/D135799 Fixes: https://github.com/llvm/llvm-project/issues/58117
Diffstat (limited to 'libcxxabi')
-rw-r--r--libcxxabi/src/demangle/ItaniumDemangle.h17
1 files changed, 12 insertions, 5 deletions
diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index fa121cc..3399825 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -3032,14 +3032,21 @@ AbstractManglingParser<Derived, Alloc>::parseOperatorEncoding() {
if (numLeft() < 2)
return nullptr;
- auto Op = std::lower_bound(
- &Ops[0], &Ops[NumOps], First,
- [](const OperatorInfo &Op_, const char *Enc_) { return Op_ < Enc_; });
- if (Op == &Ops[NumOps] || *Op != First)
+ // We can't use lower_bound as that can link to symbols in the C++ library,
+ // and this must remain independant of that.
+ size_t lower = 0u, upper = NumOps - 1; // Inclusive bounds.
+ while (upper != lower) {
+ size_t middle = (upper + lower) / 2;
+ if (Ops[middle] < First)
+ lower = middle + 1;
+ else
+ upper = middle;
+ }
+ if (Ops[lower] != First)
return nullptr;
First += 2;
- return Op;
+ return &Ops[lower];
}
// <operator-name> ::= See parseOperatorEncoding()