[cfe-dev] missing optimization opportunity for const std::vector compared to std::array

Dennis Luehring dl.soluz at gmx.net
Thu Jun 5 03:01:56 PDT 2014


Am 31.05.2014 16:14, schrieb Marshall Clow:
> > but i do not understand why its so hard to track overridden allocations - or why
> > they can't be removed - in the end there is an malloc/free or __builtin_operator_new/delete
>
> Well, consider the following code:
>
> 	int * foo () { return new int; }
>
> Does that call the default operator new?
> Or some overridden one?

and why is then clang 3.4.1
even without Richard Smith latest patch with __builtin_operator_new/delete
allowed to remove this new?

#include <memory>

int main()
{
   return *new int(10);
}

clang 3.4.1, -O3 -std=c++11

main:                                   # @main
     movl    $10, %eax
     ret

gcc 4.9.0 20130909, -O3 -std=c++11

main:
     subq    $8, %rsp
     movl    $4, %edi
     call    operator new(unsigned long)
     movl    $10, (%rax)
     movl    $10, %eax
     addq    $8, %rsp
     ret





More information about the cfe-dev mailing list