From 82b7e822d00596ec8a02490f1d662ed0fa872b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Mon, 7 Jun 2021 23:34:34 +0200 Subject: [PATCH] [Demangle][Rust] Parse path backreferences Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D103459 --- llvm/include/llvm/Demangle/RustDemangle.h | 15 +++++++++++++++ llvm/lib/Demangle/RustDemangle.cpp | 6 +++++- llvm/test/Demangle/rust.test | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/Demangle/RustDemangle.h b/llvm/include/llvm/Demangle/RustDemangle.h index c2372cd8acb1..b377e618cda9 100644 --- a/llvm/include/llvm/Demangle/RustDemangle.h +++ b/llvm/include/llvm/Demangle/RustDemangle.h @@ -102,6 +102,21 @@ private: void demangleConstBool(); void demangleConstChar(); + template void demangleBackref(Callable Demangler) { + uint64_t Backref = parseBase62Number(); + if (Error || Backref >= Position) { + Error = true; + return; + } + + if (!Print) + return; + + SwapAndRestore SavePosition(Position, Position); + Position = Backref; + Demangler(); + } + Identifier parseIdentifier(); uint64_t parseOptionalBase62Number(char Tag); uint64_t parseBase62Number(); diff --git a/llvm/lib/Demangle/RustDemangle.cpp b/llvm/lib/Demangle/RustDemangle.cpp index 582cdbc9f749..3ce73f5d935f 100644 --- a/llvm/lib/Demangle/RustDemangle.cpp +++ b/llvm/lib/Demangle/RustDemangle.cpp @@ -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; } diff --git a/llvm/test/Demangle/rust.test b/llvm/test/Demangle/rust.test index cef5d20275ac..64255336857c 100644 --- a/llvm/test/Demangle/rust.test +++ b/llvm/test/Demangle/rust.test @@ -420,6 +420,22 @@ CHECK: char::<'\u{10ffff}'> CHECK: _RIC4charKc1234567_E _RIC4charKc1234567_E +; Backreferences + +CHECK: backref:: + _RIC7backrefNvB0_5identE + +; Invalid backreferences + +CHECK: _RB_ + _RB_ + +CHECK: _RB5_ + _RB5_ + +CHECK: _RNvB_1a + _RNvB_1a + ; Invalid mangled characters CHECK: _RNvC2a.1c