Should this function be omitted?

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;
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:


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.