Bug 83925 - [SPARC/Solaris] __int128 aligned(8) as function argument is passed in wrong register
Summary: [SPARC/Solaris] __int128 aligned(8) as function argument is passed in wrong r...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 5.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ABI
Depends on:
Blocks:
 
Reported: 2018-01-18 14:34 UTC by Марина Полякова
Modified: 2018-01-18 17:23 UTC (History)
3 users (show)

See Also:
Host:
Target: sparc-solaris
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-01-18 00:00:00


Attachments
preprocessed file for PG_ALIGN_128=8 (1.99 KB, text/plain)
2018-01-18 14:34 UTC, Марина Полякова
Details
unpreprocessed input (572 bytes, text/plain)
2018-01-18 16:12 UTC, Rainer Orth
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Марина Полякова 2018-01-18 14:34:38 UTC
Created attachment 43170 [details]
preprocessed file for PG_ALIGN_128=8

If we define a new type int128a as __int128 __attribute__((aligned(8))), and you pass it as not the first function argument, its value in the function may be incorrect. See the output of the test program:

$ gcc -D PG_ALIGN_128=8 -m64 -o int128test2 int128test2.c
$ ./int128test2
basic aritmetic OK
pass int 16 FAILED
pass uint 16 FAILED
pass int 32 FAILED
pass int 64 FAILED
pass int 128 OK

(see its preprocessed file int128test2_8.i as an attachment)

When the alignment is 16, everything is fine:

$ gcc -D PG_ALIGN_128=16 -m64 -o int128test2 int128test2.c
$ ./int128test2
basic aritmetic OK
pass int 16 OK
pass uint 16 OK
pass int 32 OK
pass int 64 OK
pass int 128 OK

As it turns out, Sparc GCC passes function arguments via register ring which is referenced as %on in the calling code and as %in in function. And somehow it happens that alignment attribute of typedef affects access to arguments in the function, but doesn't affect how regiser ring is filled before call.

the system type: sparc-sun-solaris2.10

the options given when GCC was configured/built: /home/dam/mgar/pkg/gcc5/trunk/work/solaris10-sparc/build-isa-sparcv8plus/gcc-5.5.0/configure --prefix=/opt/csw --exec_prefix=/opt/csw --bindir=/opt/csw/bin --sbindir=/opt/csw/sbin --libexecdir=/opt/csw/libexec --datadir=/opt/csw/share --sysconfdir=/etc/opt/csw --sharedstatedir=/opt/csw/share --localstatedir=/var/opt/csw --libdir=/opt/csw/lib --infodir=/opt/csw/share/info --includedir=/opt/csw/include --mandir=/opt/csw/share/man --enable-cloog-backend=isl --enable-java-awt=xlib --enable-languages=ada,c,c++,fortran,go,java,objc --enable-libada --enable-libssp --enable-nls --enable-objc-gc --enable-threads=posix --program-suffix=-5.5 --with-cloog=/opt/csw --with-gmp=/opt/csw --with-included-gettext --with-ld=/usr/ccs/bin/ld --without-gnu-ld --with-libiconv-prefix=/opt/csw --with-mpfr=/opt/csw --with-ppl=/opt/csw --with-system-zlib=/opt/csw --with-as=/usr/ccs/bin/as --without-gnu-as
Comment 1 Richard Biener 2018-01-18 14:42:56 UTC
Note GCC 5 is no longer maintained - can you test a newer version?
Comment 2 Марина Полякова 2018-01-18 14:49:26 UTC
No, I can't because pkgutil has only gcc 4 or 5 :-(
Comment 3 Марина Полякова 2018-01-18 15:12:36 UTC
(In reply to Richard Biener from comment #1)
> Note GCC 5 is no longer maintained - can you test a newer version?

No, I can't because pkgutil has only gcc 4 or 5 :-(
Comment 4 Jakub Jelinek 2018-01-18 16:00:39 UTC
Rainer, can you please test current trunk?  Thanks.
Comment 5 Rainer Orth 2018-01-18 16:12:32 UTC
Created attachment 43175 [details]
unpreprocessed input
Comment 6 Rainer Orth 2018-01-18 16:13:38 UTC
The failure still happens indeed, but only at -O0, -O and -O2 are fine.
Comment 7 Eric Botcazou 2018-01-18 16:22:48 UTC
128-bit types requite 128-bit alignment on SPARC64 so we cannot support that.
Comment 8 Tom Lane 2018-01-18 17:07:41 UTC
(In reply to Eric Botcazou from comment #7)
> 128-bit types requite 128-bit alignment on SPARC64 so we cannot support that.

Fair enough, but wouldn't it be a good idea to throw an error for the alignment atttribute, rather than silently generating incorrect code?
Comment 9 Jakub Jelinek 2018-01-18 17:23:24 UTC
Given the issues we had on ARM, AArch64 (see exempli gratia PR65956 and associated discussions), et cetera with overaligned/underaligned scalars, I think the right thing is not to consider alignment for the argument passing and return value passing decisions at least for scalars.  One can always call a function with a scalar argument expecting some alignment and callee expecting different etc.
So, any reason why e.g. in this case the __int128_t arguments shouldn't be passed always the same, e.g. like normally aligned __int128_t?