Demangled function name in FunctionPass?

If I use the "Hello World Pass" example from "Writing an LLVM Pass",
then the C++ function names (from Function::getName) are mangled.

Is it possible to get the demangled function name instead?

You should be able to demangle it yourself. libstdc++ provides the __cxa_demangle function that will do this for you:

LLVM doesn't provide any direct capabilities to do this.


Is there any way to detect that the function names have been mangled
by the C++ ABI rules (or that we are optimizing C++ code)?

Every mangling under the Itanium C++ ABI starts with _Z.

Of course it's still possible to declare a C function called, say,
  int _ZN3foo3barEi(int x);
which would then have the same mangling as the C++ function
  namespace foo { int bar(int x); }
That these collide is okay under the standard because names starting with
underscores are reserved for future use, so programs using them do so at
their own risk.