[llvm] 75cc1cf - [Demangle][Rust] Parse function signatures

Tomasz Miąsko via llvm-commits llvm-commits at lists.llvm.org
Sat May 22 02:51:43 PDT 2021


Author: Tomasz Miąsko
Date: 2021-05-22T11:49:08+02:00
New Revision: 75cc1cf0181a78d1e79c96b5d318f58a72050939

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

LOG: [Demangle][Rust] Parse function signatures

Reviewed By: dblaikie

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Demangle/RustDemangle.h b/llvm/include/llvm/Demangle/RustDemangle.h
index 86641f2bea426..78f577088e5c2 100644
--- a/llvm/include/llvm/Demangle/RustDemangle.h
+++ b/llvm/include/llvm/Demangle/RustDemangle.h
@@ -88,6 +88,7 @@ class Demangler {
   void demangleImplPath(InType InType);
   void demangleGenericArg();
   void demangleType();
+  void demangleFnSig();
   void demangleConst();
   void demangleConstInt();
   void demangleConstBool();

diff  --git a/llvm/lib/Demangle/RustDemangle.cpp b/llvm/lib/Demangle/RustDemangle.cpp
index 8d43b6efcab04..d81ee33c1b792 100644
--- a/llvm/lib/Demangle/RustDemangle.cpp
+++ b/llvm/lib/Demangle/RustDemangle.cpp
@@ -472,6 +472,9 @@ void Demangler::demangleType() {
     print("*mut ");
     demangleType();
     break;
+  case 'F':
+    demangleFnSig();
+    break;
   default:
     Position = Start;
     demanglePath(rust_demangle::InType::Yes);
@@ -479,6 +482,47 @@ void Demangler::demangleType() {
   }
 }
 
+// <fn-sig> := [<binder>] ["U"] ["K" <abi>] {<type>} "E" <type>
+// <abi> = "C"
+//       | <undisambiguated-identifier>
+void Demangler::demangleFnSig() {
+  // FIXME demangle binder.
+
+  if (consumeIf('U'))
+    print("unsafe ");
+
+  if (consumeIf('K')) {
+    print("extern \"");
+    if (consumeIf('C')) {
+      print("C");
+    } else {
+      Identifier Ident = parseIdentifier();
+      for (char C : Ident.Name) {
+        // When mangling ABI string, the "-" is replaced with "_".
+        if (C == '_')
+          C = '-';
+        print(C);
+      }
+    }
+    print("\" ");
+  }
+
+  print("fn(");
+  for (size_t I = 0; !Error && !consumeIf('E'); ++I) {
+    if (I > 0)
+      print(", ");
+    demangleType();
+  }
+  print(")");
+
+  if (consumeIf('u')) {
+    // Skip the unit type from the output.
+  } else {
+    print(" -> ");
+    demangleType();
+  }
+}
+
 // <const> = <basic-type> <const-data>
 //         | "p"                          // placeholder
 //         | <backref>

diff  --git a/llvm/test/Demangle/rust.test b/llvm/test/Demangle/rust.test
index 0634f451099b7..227e97070e073 100644
--- a/llvm/test/Demangle/rust.test
+++ b/llvm/test/Demangle/rust.test
@@ -187,6 +187,35 @@ CHECK: types::<*const _>
 CHECK: types::<*mut _>
        _RIC5typesOpE
 
+; Function signatures
+
+CHECK: function::<fn()>
+       _RIC8functionFEuE
+
+CHECK: function::<fn() -> _>
+       _RIC8functionFEpE
+
+CHECK: function::<fn(_)>
+       _RIC8functionFpEuE
+
+CHECK: function::<fn(_, _)>
+       _RIC8functionFppEuE
+
+CHECK: function::<fn(_, _, _)>
+       _RIC8functionFpppEuE
+
+CHECK: function::<unsafe fn()>
+       _RIC8functionFUEuE
+
+CHECK: function::<extern "C" fn()>
+       _RIC8functionFKCEuE
+
+CHECK: function::<extern "cdecl" fn()>
+       _RIC8functionFK5cdeclEuE
+
+CHECK: function::<unsafe extern "C-cmse-nonsecure-call" fn()>
+       _RIC8functionFUK21C_cmse_nonsecure_callEuE
+
 ; Integer constants. Test value demangling.
 
 CHECK: integer::<0>


        


More information about the llvm-commits mailing list