clang doesn’t seem to respect attribute((used)) in C functions. Even if I declare a function like the following: attribute((used)) void function(), then also it doesn’t declare the function in its IR file if I don’t use the function. Is there any other way to force the declaration of “unused” function declarations with clang.
I have hacked in clang 6.0.0 in tools/clang/lib/CodeGen/CodeGenModule.cpp file. I changed in EmitGlobal function to detect if the function has “used” attribute and then if it has then use “GetOrCreateLLVMFunction” this to create the function declaration. However, this hack fails in some other cases. Therefore I am looking for a proper way to do this.
I realize that gcc also doesn’t provide this feature if the function doesn’t have a body. I was wondering if there is any elegant way to achieve this, instead of the “hack” I mentioned earlier.
Regards,
Soham Sinha
PhD Student, Department of Computer Science
Boston University