[cfe-dev] "You don't pay for what you don't use" principle violation?
Fernando Pelliccioni
fpelliccioni at gmail.com
Sun May 4 15:08:38 PDT 2014
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
compiler.
If I change the function to a template function
template <typename T>
int func( T** x, int n )
{
int sum = 0;
while ( n > 0 )
{
sum += (*x)->v;
++x;
--n;
}
return sum;
}
Then, no code is generated.
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
Best,
Fernando.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140504/4655cb81/attachment.html>
More information about the cfe-dev
mailing list