diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h index fa121cc1f3256b..339982584f5f92 100644 --- a/libcxxabi/src/demangle/ItaniumDemangle.h +++ b/libcxxabi/src/demangle/ItaniumDemangle.h @@ -3032,14 +3032,21 @@ AbstractManglingParser::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]; } // ::= See parseOperatorEncoding() diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h index aa19b29a1cca42..ea55f4a635e282 100644 --- a/llvm/include/llvm/Demangle/ItaniumDemangle.h +++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -3032,14 +3032,21 @@ AbstractManglingParser::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]; } // ::= See parseOperatorEncoding()