<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58718>58718</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Miscompilation on i686 windows with opaque pointers + LTO
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          glandium
      </td>
    </tr>
</table>

<pre>
    (For some reason, it doesn't happen outside LTO)
This function call: https://searchfox.org/mozilla-central/rev/2809416b216b498ec3d8b0e65c25a135f4f5f37d/js/src/frontend/Parser.cpp#537-538
(declaration in: https://searchfox.org/mozilla-central/rev/2809416b216b498ec3d8b0e65c25a135f4f5f37d/js/src/frontend/ErrorReporter.h#111-112)
ends up compiled as:
```
movl    %edi, 4(%ebx)
movl    %esi, (%ebx)
movl    12(%ebp), %ecx
movl    %ecx, 8(%ebx)
movl    $32, 12(%ebx)
movl    %eax, 16(%ebx)
movl    -56(%ebp), %eax
movl    %eax, 20(%ebx)
pushl   %ebx
calll   0x14f73040
```
(where `%ebx` has a copy of `%esp`)
The same code, compiled with opaque pointer disabled, is compiled as:
```
movl    %edi, 4(%ebx)
movl    %esi, (%ebx)
movl    12(%ebp), %ecx
movl    %ecx, 8(%ebx)
movl    $32, 12(%ebx)
movl    %eax, 16(%ebx)
movl    -56(%ebp), %eax
movl    %eax, 20(%ebx)
calll   0x14faf0a0
```
Note the `push` is not there.

At the IR level, it looks like this (with opaque pointers):
```
 %46 = alloca inalloca <{ ptr, %"class.mozilla::UniquePtr.84", i32, i32, ptr, ptr }>, align 4
  %47 = load ptr, ptr %7, align 4
  %48 = call noundef ptr @"?DeclarationKindString@frontend@js@@YAPBDW4DeclarationKind@12@@Z"(i8 noundef zeroext %2) #7
  %49 = getelementptr inbounds <{ ptr, %"class.mozilla::UniquePtr.84", i32, i32, ptr, ptr }>, ptr %46, i32 0, i32 1
  store ptr %25, ptr %49, align 4
  store ptr %0, ptr %46, align 4
  %50 = getelementptr inbounds <{ ptr, %"class.mozilla::UniquePtr.84", i32, i32, ptr, ptr }>, ptr %46, i32 0, i32 2
  store i32 %3, ptr %50, align 4
  %51 = getelementptr inbounds <{ ptr, %"class.mozilla::UniquePtr.84", i32, i32, ptr, ptr }>, ptr %46, i32 0, i32 3
  store i32 32, ptr %51, align 4
  %52 = getelementptr inbounds <{ ptr, %"class.mozilla::UniquePtr.84", i32, i32, ptr, ptr }>, ptr %46, i32 0, i32 4
  store ptr %48, ptr %52, align 4
  %53 = getelementptr inbounds <{ ptr, %"class.mozilla::UniquePtr.84", i32, i32, ptr, ptr }>, ptr %46, i32 0, i32 5
  store ptr %47, ptr %53, align 4
  call void (ptr, ...) @"?errorWithNotesAt@ErrorReportMixin@frontend@js@@QBAXV?$UniquePtr@VJSErrorNotes@@U?$DeletePolicy@VJSErrorNotes@@@JS@@@mozilla@@IIZZ"(ptr nonnull inalloca(<{ ptr, %"class.mozilla::UniquePtr.84", i32, i32, ptr, ptr }>) %46)
```
For some reason, after `GlobalOptPass`, the call is transformed to:
```
  call void (ptr, ...) @"?errorWithNotesAt@ErrorReportMixin@frontend@js@@QBAXV?$UniquePtr@VJSErrorNotes@@U?$DeletePolicy@VJSErrorNotes@@@JS@@@mozilla@@IIZZ"(ptr nonnull %46)
```
(it lost the `inalloca`)
and it's when starting to lower to assembly that the push is inserted, presumably because it now thinks it's calling the function as if `%46` was the first argument and the vararg was empty.

The reason it requires LTO is probably that LTO brings in the full declaration of `errorWithNotesAt` and that has an effect on the `Function` the passes see.

Cc: @nikic 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztV0tz2zYQ_jXUBWMNCb4POshW3EnatG6ebW4gCUpIIIABQMvOr-8uSMlSReXUTD2demQSBHYX37cLLBaVbh4XAS1utSFWbzkxnFmtAnpDhCON5hbauSMb1nVcEd07KxpOfnn3W0DLIFwF4fLdRljS9qp2Qit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