Skip to content

Commit

Permalink
[Demangle][Rust] Parse path backreferences
Browse files Browse the repository at this point in the history
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D103459
  • Loading branch information
tmiasko committed Jun 8, 2021
1 parent 392af6a commit 82b7e82
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
15 changes: 15 additions & 0 deletions llvm/include/llvm/Demangle/RustDemangle.h
Expand Up @@ -102,6 +102,21 @@ class Demangler {
void demangleConstBool();
void demangleConstChar();

template <typename Callable> void demangleBackref(Callable Demangler) {
uint64_t Backref = parseBase62Number();
if (Error || Backref >= Position) {
Error = true;
return;
}

if (!Print)
return;

SwapAndRestore<size_t> SavePosition(Position, Position);
Position = Backref;
Demangler();
}

Identifier parseIdentifier();
uint64_t parseOptionalBase62Number(char Tag);
uint64_t parseBase62Number();
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/Demangle/RustDemangle.cpp
Expand Up @@ -232,8 +232,12 @@ bool Demangler::demanglePath(InType InType, LeaveOpen LeaveOpen) {
print(">");
break;
}
case 'B': {
bool IsOpen = false;
demangleBackref([&] { IsOpen = demanglePath(InType, LeaveOpen); });
return IsOpen;
}
default:
// FIXME parse remaining productions.
Error = true;
break;
}
Expand Down
16 changes: 16 additions & 0 deletions llvm/test/Demangle/rust.test
Expand Up @@ -420,6 +420,22 @@ CHECK: char::<'\u{10ffff}'>
CHECK: _RIC4charKc1234567_E
_RIC4charKc1234567_E

; Backreferences

CHECK: backref::<backref::ident>
_RIC7backrefNvB0_5identE

; Invalid backreferences

CHECK: _RB_
_RB_

CHECK: _RB5_
_RB5_

CHECK: _RNvB_1a
_RNvB_1a

; Invalid mangled characters

CHECK: _RNvC2a.1c
Expand Down

0 comments on commit 82b7e82

Please sign in to comment.