diff --git a/llvm/include/llvm/Demangle/RustDemangle.h b/llvm/include/llvm/Demangle/RustDemangle.h --- a/llvm/include/llvm/Demangle/RustDemangle.h +++ b/llvm/include/llvm/Demangle/RustDemangle.h @@ -83,6 +83,7 @@ void demangleImplPath(); 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 --- a/llvm/lib/Demangle/RustDemangle.cpp +++ b/llvm/lib/Demangle/RustDemangle.cpp @@ -470,6 +470,9 @@ print("*mut "); demangleType(); break; + case 'F': + demangleFnSig(); + break; case 'C': case 'M': case 'X': @@ -485,6 +488,49 @@ } } +// := [] ["U"] ["K" ] {} "E" +// = "C" +// | +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(); + size_t Start = Output.getCurrentPosition(); + print(Ident.Name); + size_t End = Output.getCurrentPosition(); + // When mangling ABI string, the "-" is replaced with "_". + char *Buffer = Output.getBuffer(); + for (size_t I = Start; I != End; ++I) + if (Buffer[I] == '_') + Buffer[I] = '-'; + } + 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(); + } +} + // = // | "p" // placeholder // | diff --git a/llvm/test/Demangle/rust.test b/llvm/test/Demangle/rust.test --- a/llvm/test/Demangle/rust.test +++ b/llvm/test/Demangle/rust.test @@ -190,6 +190,35 @@ CHECK: types::<*mut u8> _RIC5typesOhE +; Function signatures + +CHECK: function:: + _RIC8functionFEuE + +CHECK: function:: _> + _RIC8functionFEpE + +CHECK: function:: + _RIC8functionFpEuE + +CHECK: function:: + _RIC8functionFppEuE + +CHECK: function:: + _RIC8functionFpppEuE + +CHECK: function:: + _RIC8functionFUEuE + +CHECK: function:: + _RIC8functionFKCEuE + +CHECK: function:: + _RIC8functionFK5cdeclEuE + +CHECK: function:: + _RIC8functionFUK21C_cmse_nonsecure_callEuE + ; Integer constants. Test value demangling. CHECK: integer::<0>