<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [missed optimization] failure to drop unused string if initialized after construction"
   href="https://bugs.llvm.org/show_bug.cgi?id=45288">45288</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[missed optimization] failure to drop unused string if initialized after construction
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>eyalroz@technion.ac.il
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>(GodBolt example: <a href="https://godbolt.org/z/tYM3kS">https://godbolt.org/z/tYM3kS</a> )

Consider the following two functions:

  void foo() {
      std::string s { "This is not a small string" };
  }

  void bar() {
      std::string s;
      s = "This is not a small string";
  }

clang++ is allowed, and should, optimize away the local string, and just have
these functions do nothing, compiling to :

  foo():
          ret
  bar():
          ret

but in fact (and with libc++), the string is dropped only for the first
function, not the second one:

foo():                                # @foo()
        ret
bar():                                # @bar()
        push    rbx
        sub     rsp, 32
        xorps   xmm0, xmm0
        movaps  xmmword ptr [rsp], xmm0
        mov     qword ptr [rsp + 16], 0
        mov     rdi, rsp
        mov     esi, offset .L.str
        call    std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >::assign(char const*)
        test    byte ptr [rsp], 1
        je      .LBB1_3
        mov     rdi, qword ptr [rsp + 16]
        call    operator delete(void*)
.LBB1_3:
        add     rsp, 32
        pop     rbx
        ret
        mov     rbx, rax
        test    byte ptr [rsp], 1
        je      .LBB1_6
        mov     rdi, qword ptr [rsp + 16]
        call    operator delete(void*)
.LBB1_6:
        mov     rdi, rbx
        call    _Unwind_Resume
.L.str:
        .asciz  "This is not a small string"

This bug seems very much related to 45287, although here it's all libc++ code,
no libstdc++ involved. Still, I'm seeing exception code, which makes me assume
this also depends on 35052.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>