https://bugs.llvm.org/show_bug.cgi?id=44228
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: unassignedclangb...@nondot.org
Reporter: emi...@crisal.io
CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
richard-l...@metafoo.co.uk
Created attachment 22899
--> https://bugs.llvm.org/attachment.cgi?id=22899&action=edit
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 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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs