isExternC for llvm::Function?

Hi all,
Is there anything similar to clang::FunctionDecl::isExternC for llvm::Function ?
What is a way to figure out if llvm::Function is a function with external, C linkage?

Thanks!

There are really two things going on here. First, external linkage is the default for LLVM. You can check it with Function::getLinkage (inherited from GlobalValue), though there are values other than ExternalLinkage that are very similar and you may care about too.

The other part is extern "C" linkage, which is a C++ concept. It affects what you’re allowed to do with.a function in that language (you can’t overload it for example) and disables name mangling so that the name you’ve chosen is what’s seen by the outside world (e.g. foo instead of something like _Z3fooi for void foo(int)). This all makes the function easier to call from C (or vice versa).

Neither of those matter in LLVM: overloading has to be implemented manually, and it doesn’t care whether you start your function name with _Z or have any other naming quirks. You can quite easily write an LLVM function to work with a C++ one that’s not marked extern "C".

1 Like

Thanks. I’ll rethink my approach.
The case is that I have llvm::Function and I need to figure out if it came from “C” context.

What is it about your use case that makes you think you need to know about C vs C++ linkage? Some aspect of the ABI? If you’re able to elaborate on your end goal (rather than the mechanism by which you think you need to achieve it) we might be able to point you towards a solution.

Thanks for your reply.
I need to distinguish C and C++ functions in the backend.
I came up with another solution, to have and set a custom attribute in the frotnend(clang) and use it for C and C++ functions separation in the backend.