[llvm-dev] Function name demangling in llvm ir

413 views
Skip to first unread message

sangeeta chowdhary via llvm-dev

unread,
Jun 24, 2020, 3:11:06 PM6/24/20
to LLVM Developers Mailing List
Hello,

I am doing some program analysis with C++ programs. I need to check if some particular function is called in the program, for that I need the name of the function being called in the call instruction. Since C++ mangles the name of the function, I need a way to demangle the function name in llvm IR. Is there any way to achieve that in llvm pass?

Regards,
Sangeeta

Johannes Doerfert via llvm-dev

unread,
Jun 24, 2020, 3:48:49 PM6/24/20
to sangeeta chowdhary, LLVM Developers Mailing List

I have not tried it but maybe

`std::string llvm::demangle(const std::string &MangledName)`

in `llvm/Demangle/Demangle.h`

is already what you want.

_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

David Blaikie via llvm-dev

unread,
Jun 24, 2020, 4:23:10 PM6/24/20
to Johannes Doerfert, LLVM Developers Mailing List, sangeeta chowdhary
(though, usual caveat: you /usually/ shouldn't be doing that - instead
relying only on whatever semantics the IR actually carries, rather
than implying extra semantics based on the demangled name)

sangeeta chowdhary via llvm-dev

unread,
Jun 24, 2020, 4:26:50 PM6/24/20
to David Blaikie, LLVM Developers Mailing List
Any particular reason to avoid demangling?

David Blaikie via llvm-dev

unread,
Jun 24, 2020, 4:33:51 PM6/24/20
to sangeeta chowdhary, LLVM Developers Mailing List
On Wed, Jun 24, 2020 at 1:26 PM sangeeta chowdhary
<sangitac...@gmail.com> wrote:
>
> Any particular reason to avoid demangling?

It's not part of the semantics of LLVM IR - so optimization should not
rely on it (different mangling schemes might be used on different
platforms - breaking the analysis/optimizations based on them - other
optimizations might not preserve the properties you're looking
for/assuming exist because of the mangled name, etc)

Reply all
Reply to author
Forward
0 new messages