[llvm] f9a7935 - [Demangle][Rust] Parse const backreferences

Tomasz Miąsko via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 8 01:03:28 PDT 2021


Author: Tomasz Miąsko
Date: 2021-06-08T10:01:50+02:00
New Revision: f9a79356f223035ccf0b4d0666f8779061eddc61

URL: https://github.com/llvm/llvm-project/commit/f9a79356f223035ccf0b4d0666f8779061eddc61
DIFF: https://github.com/llvm/llvm-project/commit/f9a79356f223035ccf0b4d0666f8779061eddc61.diff

LOG: [Demangle][Rust] Parse const backreferences

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D103848

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Demangle/RustDemangle.cpp b/llvm/lib/Demangle/RustDemangle.cpp
index 4a8f35b8df7a..919a668a5e5f 100644
--- a/llvm/lib/Demangle/RustDemangle.cpp
+++ b/llvm/lib/Demangle/RustDemangle.cpp
@@ -625,8 +625,15 @@ void Demangler::demangleOptionalBinder() {
 //         | "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 @@ void Demangler::demangleConst() {
       print('_');
       break;
     default:
-      // FIXME demangle backreferences.
       Error = true;
       break;
     }
+  } else if (C == 'B') {
+    demangleBackref([&] { demangleConst(); });
   } else {
     Error = true;
   }

diff  --git a/llvm/test/Demangle/rust.test b/llvm/test/Demangle/rust.test
index 1c1236d93177..7e421d04742f 100644
--- a/llvm/test/Demangle/rust.test
+++ b/llvm/test/Demangle/rust.test
@@ -428,6 +428,9 @@ CHECK: backref::<backref::ident>
 CHECK: backref::<(), ()>
        _RIC7backrefuB9_E
 
+CHECK: backref::<7, 7>
+       _RIC7backrefKi7_KBa_E
+
 ; Invalid backreferences
 
 CHECK: _RB_
@@ -442,6 +445,9 @@ CHECK: _RNvB_1a
 CHECK: _RIC7backrefSB9_E
        _RIC7backrefSB9_E
 
+CHECK: _RIC7backrefKBa_E
+       _RIC7backrefKBa_E
+
 ; Invalid mangled characters
 
 CHECK: _RNvC2a.1c


        


More information about the llvm-commits mailing list