<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 5, 2014 at 3:01 AM, Dennis Luehring <span dir="ltr"><<a href="mailto:dl.soluz@gmx.net" target="_blank">dl.soluz@gmx.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am <a href="tel:31.05.2014%2016" value="+13105201416" target="_blank">31.05.2014 16</a>:14, schrieb Marshall Clow:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> but i do not understand why its so hard to track overridden allocations - or why<br>
> they can't be removed - in the end there is an malloc/free or __builtin_operator_new/delete<br>
<br>
Well, consider the following code:<br>
<br>
int * foo () { return new int; }<br>
<br>
Does that call the default operator new?<br>
Or some overridden one?<br>
</blockquote>
<br>
and why is then clang 3.4.1<br>
even without Richard Smith latest patch with __builtin_operator_new/delete<br>
allowed to remove this new?<br>
<br>
#include <memory><br>
<br>
int main()<br>
{<br>
return *new int(10);<br>
}<br>
<br>
clang 3.4.1, -O3 -std=c++11<br>
<br>
main: # @main<br>
movl $10, %eax<br>
ret<br>
<br>
gcc 4.9.0 20130909, -O3 -std=c++11<br>
<br>
main:<br>
subq $8, %rsp<br>
movl $4, %edi<br>
call operator new(unsigned long)<br>
movl $10, (%rax)<br>
movl $10, %eax<br>
addq $8, %rsp<br>
ret<br></blockquote><div><br></div><div>GCC's codegen could be improved. However, Clang's appears to be a little be too eager and potentially non-legit. E.g. it is legit if that translation unit is the only unit of the entire program. However, it isn't if that translation unit was linked with another unit providing a replacement for 'operator new'. This is something that LTO could handle very well.</div>
<div><br></div><div><br></div><div>-- Gaby</div></div></div></div>