[llvm-bugs] [Bug 44228] New: clang assumes zero-extension of 8-bit arguments in x86, causing interop issues with gcc

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 5 05:26:57 PST 2019


            Bug ID: 44228
           Summary: clang assumes zero-extension of 8-bit arguments in
                    x86, causing interop issues with gcc
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: emilio at crisal.io
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

Created attachment 22899
  --> https://bugs.llvm.org/attachment.cgi?id=22899&action=edit

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

According to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92821#c2:

> I believe it is a LLVM bug.
> At least, reading https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf, 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.

https://godbolt.org/z/BNHxEY 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 https://bugzilla.mozilla.org/show_bug.cgi?id=1600735 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++.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191205/268e304f/attachment-0001.html>

More information about the llvm-bugs mailing list