0

By using FrontendAction and ASTConsumer API, we can print the name of each function, such as:

  bool VisitFunctionDecl(FunctionDecl *f) {
    DeclarationName DeclName = f->getNameInfo().getName();
    std::string FuncName = DeclName.getAsString();
    out << FuncName << '\n';
    return true;
  }

Now each of FuncName we got is not mangled, and I want to get the mangled name by using API, I have found this API in clang/include/AST/Mangle.h, which is:

void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out);

This API seems to receive a GlobalDecl type param and a raw_ostream& param, but now I have only a FunctionDecl* type param, how can I use this API to get a mangled function name which has type of std::string?

  • 1
    This duplicate question has an answer: https://stackoverflow.com/questions/40740604/how-do-i-get-the-mangled-name-of-a-nameddecl-in-clang – Dmitry Mikushin Jan 13 '23 at 09:32
  • Does this answer your question? [How do I get the mangled name of a NamedDecl in Clang?](https://stackoverflow.com/questions/40740604/how-do-i-get-the-mangled-name-of-a-nameddecl-in-clang) – Scott McPeak May 14 '23 at 02:55

0 Answers0