<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 - ESI not preserved on clobber if used as base register"
   href="https://bugs.llvm.org/show_bug.cgi?id=51100">51100</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ESI not preserved on clobber if used as base register
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>Backend: X86
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>klrehm123@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, pengfei.wang@intel.com, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>If esi is used as a base pointer (i.e. in the case of dynamically sized allocas
on Windows x86), it won't properly be preserved even if marked as clobbered in
inline assembly. 

A practical example of this being an issue is with `rep movsb` (and by
extension the __movsb intrinsic): 


int test() {
    // fake dynamic alloca
    volatile auto size = 4;
    auto x = (int*)__builtin_alloca(size);
    *x = 1;

    int g;
    void *ptr = &g;

    int c = 4;

    // replicate __movsb intrinsic
    asm("rep movsb" : "+D"(ptr), "+S"(x), "+c"(c)::"memory");

    // miscompile here as esi is modified
    return g;
}  


<a href="https://godbolt.org/z/v3zqh8E96">https://godbolt.org/z/v3zqh8E96</a>

This caused problems when LTO was used across different libraries that caused
two unrelated functions to be inlined.

`-mllvm -x86-use-base-pointer=false` fixes this by not using esi at all.</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>