aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Demangle/MicrosoftDemangle.cpp
diff options
context:
space:
mode:
authorNick Desaulniers <ndesaulniers@google.com>2023-04-20 15:59:10 -0700
committerNick Desaulniers <ndesaulniers@google.com>2023-04-20 16:41:09 -0700
commit6bad76c7ae93a94fbac39db08fee23ce46d97fdb (patch)
tree617e9a464bd0511f462dbc259921510cb9cd30dc /llvm/lib/Demangle/MicrosoftDemangle.cpp
parentba38640b9901d239e32e12c6569f7364d00af922 (diff)
downloadllvm-6bad76c7ae93a94fbac39db08fee23ce46d97fdb.zip
llvm-6bad76c7ae93a94fbac39db08fee23ce46d97fdb.tar.gz
llvm-6bad76c7ae93a94fbac39db08fee23ce46d97fdb.tar.bz2
[Demangle] fix windows tests
My reland of https://reviews.llvm.org/D148546 has caused a few windows demangler tests to fail when run with -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON on windows. I have a sneaking suspicion that MSVC's std::string_view::iterator::operator* may be missing a nullptr check. Link: https://lab.llvm.org/buildbot/#/builders/42/builds/9723/steps/7/logs/stdio Reviewed By: ayzhao Differential Revision: https://reviews.llvm.org/D148852
Diffstat (limited to 'llvm/lib/Demangle/MicrosoftDemangle.cpp')
-rw-r--r--llvm/lib/Demangle/MicrosoftDemangle.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp b/llvm/lib/Demangle/MicrosoftDemangle.cpp
index 4013de7..8283500 100644
--- a/llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -793,6 +793,7 @@ SymbolNode *Demangler::demangleMD5Name(std::string_view &MangledName) {
return nullptr;
}
const char *Start = &*MangledName.begin();
+ const size_t StartSize = MangledName.size();
MangledName.remove_prefix(MD5Last + 1);
// There are two additional special cases for MD5 names:
@@ -807,7 +808,9 @@ SymbolNode *Demangler::demangleMD5Name(std::string_view &MangledName) {
// either.
consumeFront(MangledName, "??_R4@");
- std::string_view MD5(Start, &*MangledName.begin() - Start);
+ assert(MangledName.size() < StartSize);
+ const size_t Count = StartSize - MangledName.size();
+ std::string_view MD5(Start, Count);
SymbolNode *S = Arena.alloc<SymbolNode>(NodeKind::Md5Symbol);
S->Name = synthesizeQualifiedName(Arena, MD5);
@@ -2402,7 +2405,7 @@ char *llvm::microsoftDemangle(const char *MangledName, size_t *NMangled,
std::string_view Name{MangledName};
SymbolNode *AST = D.parse(Name);
if (!D.Error && NMangled)
- *NMangled = &*Name.begin() - MangledName;
+ *NMangled = Name.empty() ? 0 : &*Name.begin() - MangledName;
if (Flags & MSDF_DumpBackrefs)
D.dumpBackReferences();