[LLVMdev] Optimization of string.h calls

Iritscen iritscen at yahoo.com
Sun Sep 21 06:58:44 PDT 2014


> Imagine the following:
> 
> First file:
>   void f1(const char* c) {
>     puts(c - 4);
>   }
> 
> Second file:
>   void f2() {
>     f1("the name" + 4);
>   }
> 
> The compiler can't optimize away the 'the ' prefix while compiling the second file because it can't know whether the users of that pointer might subtract from it, walking into well defined memory they should be able to examine/print/etc.

I see what you mean.  To me, this falls under the same category as other odd coding practices that will break if certain optimizations are applied to them.  The developer should be picking build settings cautiously to make sure their code is treated as desired.

I could picture a string-trimming optimization falling under a “small binary” optimization setting, which I thought at first was “-Os" except that apparently this is just a synonym for -O2.  Or simply an optional argument like -fprune-strings could be made available with the understanding that back-tracking from a string pointer is not going to work under this setting.

Anyway, I won’t harp on this subject anymore, but if anyone would like to share their approach for avoiding full machine paths in the binary from the use of __FILE__, I’d appreciate it.  I have written a script which copies the project to a RAM disk and compiles it from there, eliminating the paths above the level of the project, but there’s probably a better way.



More information about the llvm-dev mailing list