[PATCH] D103848: [Demangle][Rust] Parse const backreferences

Tomasz Miąsko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 7 15:03:47 PDT 2021


tmiasko created this revision.
tmiasko added a reviewer: dblaikie.
Herald added subscribers: JDevlieghere, hiraditya.
tmiasko requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Depends on D103847 <https://reviews.llvm.org/D103847>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103848

Files:
  llvm/lib/Demangle/RustDemangle.cpp
  llvm/test/Demangle/rust.test


Index: llvm/test/Demangle/rust.test
===================================================================
--- llvm/test/Demangle/rust.test
+++ llvm/test/Demangle/rust.test
@@ -428,6 +428,9 @@
 CHECK: backref::<(), ()>
        _RIC7backrefuB9_E
 
+CHECK: backref::<7, 7>
+       _RIC7backrefKi7_KBa_E
+
 ; Invalid backreferences
 
 CHECK: _RB_
@@ -442,6 +445,9 @@
 CHECK: _RIC7backrefSB9_E
        _RIC7backrefSB9_E
 
+CHECK: _RIC7backrefKBa_E
+       _RIC7backrefKBa_E
+
 ; Invalid mangled characters
 
 CHECK: _RNvC2a.1c
Index: llvm/lib/Demangle/RustDemangle.cpp
===================================================================
--- llvm/lib/Demangle/RustDemangle.cpp
+++ llvm/lib/Demangle/RustDemangle.cpp
@@ -625,8 +625,15 @@
 //         | "p"                          // placeholder
 //         | <backref>
 void Demangler::demangleConst() {
+  if (Error || RecursionLevel >= MaxRecursionLevel) {
+    Error = true;
+    return;
+  }
+  SwapAndRestore<size_t> SaveRecursionLevel(RecursionLevel, RecursionLevel + 1);
+
+  char C = consume();
   BasicType Type;
-  if (parseBasicType(consume(), Type)) {
+  if (parseBasicType(C, Type)) {
     switch (Type) {
     case BasicType::I8:
     case BasicType::I16:
@@ -652,10 +659,11 @@
       print('_');
       break;
     default:
-      // FIXME demangle backreferences.
       Error = true;
       break;
     }
+  } else if (C == 'B') {
+    demangleBackref([&] { demangleConst(); });
   } else {
     Error = true;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103848.350427.patch
Type: text/x-patch
Size: 1474 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210607/adf55470/attachment-0001.bin>


More information about the llvm-commits mailing list