public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc vs clang for non-power-2 atomic structures
@ 2019-08-22 23:56 Jim Wilson
  2019-08-23  7:21 ` Iain Sandoe
  0 siblings, 1 reply; 8+ messages in thread
From: Jim Wilson @ 2019-08-22 23:56 UTC (permalink / raw)
  To: GCC Development

We got a change request for the RISC-V psABI to define the atomic
structure size and alignment.  And looking at this, it turned out that
gcc and clang are implementing this differently.  Consider this
testcase

rohan:2274$ cat tmp.c
#include <stdio.h>
struct s { int a; int b; int c;};
int
main(void)
{
  printf("size=%ld align=%ld\n", sizeof (struct s), _Alignof(struct s));
  printf("size=%ld align=%ld\n", sizeof (_Atomic (struct s)),
_Alignof(_Atomic (struct s)));
  return 0;
}
rohan:2275$ gcc tmp.c
rohan:2276$ ./a.out
size=12 align=4
size=12 align=4
rohan:2277$ clang tmp.c
rohan:2278$ ./a.out
size=12 align=4
size=16 align=16
rohan:2279$

This is with an x86 compiler.  I get the same result with a RISC-V
compiler.  This is an ABI incompatibility between gcc and clang.  gcc
has code in build_qualified_type in tree.c that sets alignment for
power-of-2 structs to the same size integer alignment, but we don't
change alignment for non-power-of-2 structs.  Clang is padding the
size of non-power-of-2 structs to the next power-of-2 and giving them
that alignment.

Unfortunately, I don't know who to contact on the clang side, but we
need to have a discussion here, and we probably need to fix one of the
compilers to match the other one, as we should not have ABI
incompatibilities like this between gcc and clang.

The original RISC-V bug report is at
    https://github.com/riscv/riscv-elf-psabi-doc/pull/112
There is a pointer to a gist with a larger testcase with RISC-V results.

Jim

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-08-23 18:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-22 23:56 gcc vs clang for non-power-2 atomic structures Jim Wilson
2019-08-23  7:21 ` Iain Sandoe
2019-08-23  9:36   ` Jonathan Wakely
2019-08-23 10:13     ` Iain Sandoe
2019-08-23 11:17       ` Jonathan Wakely
2019-08-23 16:14       ` Joseph Myers
2019-08-23 18:49         ` Jim Wilson
2019-08-23 18:59         ` Iain Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).