<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - Miscompilation when devirtualization is aborted due to covariant return types"
   href="http://llvm.org/bugs/show_bug.cgi?id=20116">20116</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Miscompilation when devirtualization is aborted due to covariant return types
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>izbyshev@ispras.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=12699" name="attach_12699" title="A failing test case">attachment 12699</a> <a href="attachment.cgi?id=12699&action=edit" title="A failing test case">[details]</a></span>
A failing test case

When compiling the attached code, clang doesn't emit 'this' adjustment code for
'static_cast<A*>(z)' expression and ends up using a wrong vtable for the
virtual call. As a result, B.g() is called instead of Z.f().

Inspection of CodeGenFunction::EmitCXXMemberCallExpr() code shows that clang
can stop devirtualization in the middle if it finds out that return types are
covariant. At that moment, 'Base' expression that is later used for emission of
'this' pointer has already been assigned to 'Inner' expression (with casts
stripped), so no 'this' adjustment code is generated.</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>