<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 - clang assumes zero-extension of 8-bit arguments in x86, causing interop issues with gcc"
   href="https://bugs.llvm.org/show_bug.cgi?id=44228">44228</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang assumes zero-extension of 8-bit arguments in x86, causing interop issues with gcc
          </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>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>emilio@crisal.io
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=22899" name="attach_22899" title="test-case">attachment 22899</a> <a href="attachment.cgi?id=22899&action=edit" title="test-case">[details]</a></span>
test-case

When receiving 8-bit-wide arguments in extern function, clang seems to assume
the argument has been zero-extended by the caller.

According to <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92821#c2">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92821#c2</a>:

<span class="quote">> I believe it is a LLVM bug.
> At least, reading <a href="https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf">https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf</a>, I can't find in the Parameter Passing section anything that would say that arguments smaller than 64-bit are passed sign or zero extended to 64-bit like some other psABIs require.  The only related thing is
> "When a value of type _Bool is returned or passed in a register or on the stack, bit 0 contains the truth value and bits 1 to 7 shall be zero."
> with a footnote:
> "Other bits are left unspecified, hence the consumer side of those values can rely on it being 0 or 1 when truncated to 8 bit."
> which says that _Bool has only significant low 8 bits and the rest is unspecified.</span >

<a href="https://godbolt.org/z/BNHxEY">https://godbolt.org/z/BNHxEY</a> has a comparison of clang and gcc output for the
attached test-case. GCC correctly does an 8-bit load, disregarding the rest of
the bits in the register.

This causes real problems when gcc-built functions call into llvm-built
functions. See <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1600735">https://bugzilla.mozilla.org/show_bug.cgi?id=1600735</a> for an
example that happens on Firefox. GCC may not always sign-extend in the caller.

In the Firefox case the LLVM-built function is Rust code, but per the above
godbolt link it also seems to reproduce with C / C++.</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>