[cfe-dev] clang/library collusion

Bernard Ogden via cfe-dev cfe-dev at lists.llvm.org
Fri May 27 07:15:59 PDT 2016


On 25 May 2016, at 01:44, Richard Smith <richard at metafoo.co.uk> wrote:

> It could be marginally better to have the library provide a weak _Main_noargv() entry point that computes argc and argv then calls main(), and have the compiler emit _Main_noargv as an alias to main if main doesn't use its argc and argv. But either way, sure.

Yes, that does feel a bit neater.

> Not by manipulating the AST, no, for a couple of reasons:
> 1) You may not know that argc and argv are unused until you perform some optimizations
> 2) It doesn't make sense to model this in the AST as it's a property of the lowering to machine code, not a property of the source program
> 
> If you really want to do this in clang (per the above, I don't think that's a good idea), you should do it in clang's IR generation pass rather than modifying the AST. But I'd suggest you instead look at teaching LLVM to do this (maybe in dead argument elimination), and from Clang just inform the relevant LLVM pass that it can do this transformation.

That makes sense - I'll see if I can do it in LLVM.

Thanks for the advice.

Regards,

Bernie




More information about the cfe-dev mailing list