[LLVMbugs] [Bug 21145] New: clang does not omit unnecessary memory allocations with -std=c++1{y, z}

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Oct 2 20:40:46 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=21145

            Bug ID: 21145
           Summary: clang does not omit unnecessary memory allocations
                    with -std=c++1{y,z}
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++1y
          Assignee: unassignedclangbugs at nondot.org
          Reporter: sneves at dei.uc.pt
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Consider the following function:

int f() {
  int * x = new int(123);
  int z = *x;
  delete x;
  return z;
}

N3664, which is implemented on clang 3.4 onward, states that the above `new`
expression is allowed not to result in an explicit allocation. However, it
appears that clang only avoids the allocation when using -std=c++98 or
-std=c++11. Here is the abridged output of `clang -std=c++11 -O3 f.cpp`:

f():                                  # @f()
    movl    $123, %eax
    retq

And here is the output of `clang -std=c++1y -O3 f.cpp`:

f():                                  # @f()
    pushq    %rax
    movl    $4, %edi
    callq    operator new(unsigned long)
    movl    $123, (%rax)
    movl    $4, %esi
    movq    %rax, %rdi
    callq    operator delete(void*, unsigned long)
    movl    $123, %eax
    popq    %rdx
    retq

It would seem that C++14 mode actually disables N3664, instead of enabling it.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141003/a93df434/attachment.html>


More information about the llvm-bugs mailing list