From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 96742 invoked by alias); 22 Aug 2019 23:56:45 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 96732 invoked by uid 89); 22 Aug 2019 23:56:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: mail-vs1-f42.google.com Received: from mail-vs1-f42.google.com (HELO mail-vs1-f42.google.com) (209.85.217.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Aug 2019 23:56:43 +0000 Received: by mail-vs1-f42.google.com with SMTP id b187so5072283vsc.9 for ; Thu, 22 Aug 2019 16:56:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=rQ1USmBPqtH6z/un4iR55kYWUkIoT9pJnPm/pG0DC9c=; b=dgC4LJwefAo8ddgFzUnuxZhNzyTqNHq2LlVe37M6paDs4YGDL4f/SxYTBYLhVbjYWO 1wJCY7qxOEN7Y6RGXcP1m+dMqgu40+R8Cxm6Hy5ODQ8l70yWK8C3k0xHrzB5Xk998Uyw k0L2Y9J0MEr/d+pAmKeCwHsUqrSmyKO65ZuL94TncIydHb8gFXcgd8WuU1kANX2e4sxJ KaP4Yuv6fMJ/tMzPhqQVZsK4DvWfoYwtczLGR3R8c8jnk9TcjwJhA1Yfz+k1SAYa99bw q2hz7gu6YmNTTzOOKsYEk4wpWxFkDvVCS5TssW9XXXcKOBnk4kGV7cq6KTsBQPFLSIIr B9hA== MIME-Version: 1.0 From: Jim Wilson Date: Thu, 22 Aug 2019 23:56:00 -0000 Message-ID: Subject: gcc vs clang for non-power-2 atomic structures To: GCC Development Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2019-08/txt/msg00191.txt.bz2 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 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