[LLVMdev] Should this function be omitted?

Eric Christopher echristo at gmail.com
Sun May 4 19:11:20 PDT 2014


I've replied on the cfe-dev thread for this, but basically you need to
tell the linker to dead strip out unused code. Since you're on darwin
you can pass -Wl,-dead_strip.

-eric

On Sun, May 4, 2014 at 4:17 PM, Fernando Pelliccioni
<fpelliccioni at gmail.com> wrote:
> Hi all,
>
> Is there any reason why the following code produces the attached assembly
> code?
>
>     struct X { int v; };
>
>     int func( X** x, int n )
>     {
>         int sum = 0;
>
>         while ( n > 0 )
>         {
>             sum += (*x)->v;
>             ++x;
>             --n;
>         }
>         return sum;
>     }
>
>     int main() {}
>
> The "func" function is not used, I think it should be omitted by the linked.
> Should it?
>
> Compiled using:
>     clang++ -S -O3 -std=c++11 -S code.cpp
>
> clang++ --version
>     clang version 3.5 (trunk 200620)
>     Target: x86_64-apple-darwin13.1.0
>     Thread model: posix
>
> Assembly code generated:
>     http://pastebin.com/aY8rAXyQ
>
> Best,
> Fernando.
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>



More information about the llvm-dev mailing list