<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:sanjoy@playingwithpointers.com" title="Sanjoy Das <sanjoy@playingwithpointers.com>"> <span class="fn">Sanjoy Das</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED --- - wrong code at -O1 and above on x86_64-linux-gnu"
   href="https://llvm.org/bugs/show_bug.cgi?id=27002">bug 27002</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>RESOLVED
           </td>
           <td>REOPENED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>INVALID
           </td>
           <td>---
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED --- - wrong code at -O1 and above on x86_64-linux-gnu"
   href="https://llvm.org/bugs/show_bug.cgi?id=27002#c3">Comment # 3</a>
              on <a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED --- - wrong code at -O1 and above on x86_64-linux-gnu"
   href="https://llvm.org/bugs/show_bug.cgi?id=27002">bug 27002</a>
              from <span class="vcard"><a class="email" href="mailto:sanjoy@playingwithpointers.com" title="Sanjoy Das <sanjoy@playingwithpointers.com>"> <span class="fn">Sanjoy Das</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=27002#c2">comment #2</a>)
<span class="quote">> This behavior is intentional and is a result of clang's implementation of
> the previsions of the C++ standard.

> C++14 [expr.new]p10:
> "An implementation is allowed to omit a call to a replaceable global
> allocation function [...]."</span >

In the above specific case the behavior may be fine, since we delete both
the new and the delete; but how about something like

extern "C" void _exit (int);

void operator delete (void *p) throw () {
  _exit (0);
}

void foo(int **escape_loc) {
  int *i = new int;
  *escape_loc = i;
  delete i;
}

?

clang today compiles foo to

define void @_Z3fooPPi(i32** nocapture %escape_loc) #2 {
entry:
  %call = tail call noalias i8* @_Znwm(i64 4) #5
  %0 = bitcast i32** %escape_loc to i8**
  store i8* %call, i8** %0, align 8, !tbaa !2
  ret void
}

i.e. elides the deallocation, but not the allocation, and in
expr.delete[7] we have

"If the allocation call for the new-expression for the object to be
deleted was not omitted (5.3.4), the delete-expression shall call a
deallocation function (3.7.4.2). The value returned from the
allocation call of the new-expression shall be passed as the first
argument to the deallocation function."</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>