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
This commit is contained in:
Nathan Sidwell 2022-10-20 07:10:47 -04:00
parent a401ce4416
commit c7ca21436d
2 changed files with 24 additions and 10 deletions

View File

@ -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()

View File

@ -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()