[llvm-dev] How to force an unused function declaration in clang

Hans Wennborg via llvm-dev llvm-dev at lists.llvm.org
Tue Jun 26 08:24:52 PDT 2018


It works for me:

https://godbolt.org/g/3QzqAH

Can you share an example?

On Tue, Jun 26, 2018 at 5:21 PM, Soham Sinha via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> For the same reason GCC allowed the attribute. Even if I want to use/inline
> a function later on in the pipeline.
>
> Regards,
> Soham Sinha
> PhD Student, Department of Computer Science
> Boston University
>
>
> On Tue, Jun 26, 2018 at 8:30 AM mayuyu.io <admin at mayuyu.io> wrote:
>>
>> Out of curiosity, how does an unused declaration affect the emitted object
>> file
>>
>> Zhang
>>
>> > 在 2018年6月26日,08:48,Soham Sinha via llvm-dev <llvm-dev at lists.llvm.org>
>> > 写道:
>> >
>> > 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.
>> >
>> > Regards,
>> > Soham Sinha
>> > PhD Student, Department of Computer Science
>> > Boston University
>> > _______________________________________________
>> > LLVM Developers mailing list
>> > llvm-dev at lists.llvm.org
>> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>


More information about the llvm-dev mailing list