[LLVMdev] clang optimizer does not remove unused/uneeded variables(and accesses) from global scope

Duncan Sands baldrick at free.fr
Thu Jul 5 04:57:27 PDT 2012


Hi Dimitry,

On 05/07/12 13:30, Dimitry Andric wrote:
> On 2012-07-05 12:53, Dennis Luehring wrote:
>> addition to my last post:
>> http://groups.google.com/group/llvm-dev/browse_thread/thread/afd85c3f303ec2a9
>>
>> i know that using static on my globals will remove them - no other
>> compilation unit can then extern the vars
>>
>> but my question is - in this closed szenario clang is "directly"
>> producing the exe - isn't clang aware of that the vars are not in use?
>
> It can't know that, unless you use link-time optimization.  Which
> optimization level did you use?

it can know: if you looked at his command line you can see that it is producing
a final executable from the file, not just compiling it to object code.  As far
as I know clang relies on an LLVM aware linker to do the link-time optimization,
though I'm not sure why: in this kind of case it could just do it itself.  On
linux you can use the gold linker with the LLVM gold plugin, maybe that can be
used on windows too, I wouldn't know.

Ciao, Duncan.



More information about the llvm-dev mailing list