I am writing a llvm pass. I have a Function object from llvm and I want to know if this one is a constructor of a class or not. How can I do it? Any suggestion?
Asked
Active
Viewed 186 times
2 Answers
0
Well... Looks like the only thing you could do is to try to demangle the function name and try to deduce whether it's constructor or not. Though, it's not 100% precise since one would need to handle multiple mangling schemes.

Anton Korobeynikov
- 9,074
- 25
- 28
0
As Anton said, we can demangle the function name.
LLVM has a demangler in llvm/Demangle/Demangle.h
.
The usage can be seen in
how to get function base name from managled function name using llvm ItaniumDemangle api
ItaniumPartialDemangler Demangler;
Demangler.partialDemangle(F.getName().str().c_str());
if (Demangler.isCtorOrDtor()){
outs() << MF.getName() << " is constructor !\n";
}
This may not be an elegant way to determine whether a function is a constructor or not as it may cause performance issues in compilation. I am still waiting for a better approach.

Randolph
- 56
- 6