[cfe-dev] How to use clang without any dead-code elimination

Török Edwin edwintorok at gmail.com
Mon Jan 17 04:56:20 PST 2011


On 2011-01-17 14:33, Wen-Han Gu wrote:
> Hi all,
> 
> I have some functions definition to be used in another place.

If the function is not declared as "static", then clang must already
assume it can be used externally, and can't eliminate the code (even if
optimizing up to O3).
Unless you perform LTO, -internalize, or other such whole program
transformations, the code should be emitted.

The linker might still eliminate the function if no function from a
.o/.a is needed.

> I want to generate LLVM IR without any dead-code elimination, or the
> output will contains nothing.

-O0 should work, but obviously won't have any other optimization.

> 
> Did anyone know how to achive that without any change of source code?

> If not this way, which source file should I modify?

__attribute__((used)) if you use the function from assembly and compiler
can't see its used.

Best regards,
--Edwin



More information about the cfe-dev mailing list