https://bugs.llvm.org/show_bug.cgi?id=34797
Bug ID: 34797
Summary: Memory allocation is not omitted in simple case
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++14
Assignee: unassignedclangb...@nondot.org
Reporter: antosh...@gmail.com
CC: llvm-bugs@lists.llvm.org
For the following function
unsigned lame_zero(unsigned count) {
unsigned res = 0;
// erase `count +` for omitting `call operator new`
unsigned *p = new unsigned[count + 1]();
res = p[0]; // or erase this line for omitting `call operator new`
delete[] p;
return res;
}
clang generates calls to `operator new` even in C++1z mode:
lame_zero(unsigned int): # @lame_zero(unsigned int)
push r14
push rbx
push rax
mov ebx, edi
inc ebx
shl rbx, 2
mov rdi, rbx
call operator new[](unsigned long)
mov r14, rax
xor esi, esi
mov rdi, r14
mov rdx, rbx
call memset
mov ebx, dword ptr [r14]
mov rdi, r14
call operator delete[](void*)
mov eax, ebx
add rsp, 8
pop rbx
pop r14
ret
This seems suboptimal and affects common code, like std::stable_sort usages:
#include <algorithm>
#include <array>
std::array<unsigned, 6> my_sorted_array() {
std::array<unsigned, 6> data = {1, 2, 7, 7, 7, 0};
// Multiple calls to operator new[] are not omitted
std::stable_sort(data.begin(), data.end());
return data;
}
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs