[cfe-dev] "You don't pay for what you don't use" principle violation?
Fernando Pelliccioni
fpelliccioni at gmail.com
Sun May 4 15:10:55 PDT 2014
Sorry, here the assembly code
http://pastebin.com/aY8rAXyQ
On Sun, May 4, 2014 at 7:08 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
> 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/dc8a4a64/attachment.html>
More information about the cfe-dev
mailing list