From patchwork Fri Jun 2 19:11:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 70556 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3820D3857725 for ; Fri, 2 Jun 2023 19:12:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3820D3857725 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685733149; bh=UfE2dn1kaBMRaf6OdxjLReyq/4JpQoyB+pGCKG8n2JU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=DoURi2ze+sKOw071ybxG0TV9gm5wCSslnHl6EFiqschr3Vtp1NOHUVcm7AfM0Uenb db3a3Y1JaW/FT5JD6x6RWeZH9zXW4sn0aeR6eFz04IPbJFMWNY3aYFr6WlCx0MCb5+ N56T9dp+WvHw+eYKm1xuvvEYA94fTXWQvL02MafE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 94B813858D3C for ; Fri, 2 Jun 2023 19:11:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94B813858D3C Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-30af86a966eso2185887f8f.2 for ; Fri, 02 Jun 2023 12:11:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685733118; x=1688325118; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UfE2dn1kaBMRaf6OdxjLReyq/4JpQoyB+pGCKG8n2JU=; b=P5AhL2YGkXh+6na7ApgK90UoMfrcSAgTrq2WlMhqiADI+JGWGM1jJEb2m6UpjlH/WM rwkdYvzPCX8npHYr2VV2pu5tkLW1MSUSG7yfglIqOmhgYhnVduecyP+CpBzxmnRv9k+L 9suTmaYJY56LlnXmrXVIEgNj2jlKbMMhWVP++qaZCCUYtyikWr2EBqhxV7C/zZkrXPdI NuaD5oJkcHDOQQG9W8OkRWn3Cp8cjF/FBzr58cvUZtF9mg4aCeU7GzxjBWGJtZyAfpEz ykP/7Hk6caNZMjZvBlCSw2cjZsLbbukYkzkvLcNBttCrFY9x7kVwSB0JziD4UEeQP5ur iMjQ== X-Gm-Message-State: AC+VfDxJuQDVMQJMc82cQ4fqclbyFeALZXu1m9+T9I2k+U0GSb7/EP9A fNnz27lor01LxwOF5VcpmJhXSrD5DKs= X-Google-Smtp-Source: ACHHUZ6JAxt0yD33FuPrVO5e6PpG59gcVLHtLB6wcyvX6TS3UxwXN4kprg7Ab9wktskTglHRQy5cTQ== X-Received: by 2002:adf:fed2:0:b0:306:368d:8a1c with SMTP id q18-20020adffed2000000b00306368d8a1cmr658398wrs.45.1685733118008; Fri, 02 Jun 2023 12:11:58 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id d24-20020a1c7318000000b003f6129d2e30sm6427419wmb.1.2023.06.02.12.11.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 02 Jun 2023 12:11:57 -0700 (PDT) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [pushed] Darwin, PPC: Fix struct layout with pragma pack [PR110044]. Date: Fri, 2 Jun 2023 20:11:53 +0100 Message-Id: <20230602191153.78156-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe , segher@kernel.crashing.org, dje.gcc@gmail.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" @David: I am not sure what sets the ABI on AIX (for Darwin, it is effectively "whatever the system compiler [Apple gcc-4] does") but from an inspection of the code, it seems that (if the platform should honour #pragma pack) a similar effect could be present there too. Tested on powerpc-apple-darwin9, powerpc64-linux-gnu and on i686 and x86_64 Darwin. Checked that the testcases also pass for Apple gcc-4.2.1. pushed to trunk, thanks Iain --- 8< --- This bug was essentially that darwin_rs6000_special_round_type_align() was ignoring externally-imposed capping of field alignment. Signed-off-by: Iain Sandoe PR target/110044 gcc/ChangeLog: * config/rs6000/rs6000.cc (darwin_rs6000_special_round_type_align): Make sure that we do not have a cap on field alignment before altering the struct layout based on the type alignment of the first entry. gcc/testsuite/ChangeLog: * gcc.target/powerpc/darwin-abi-13-0.c: New test. * gcc.target/powerpc/darwin-abi-13-1.c: New test. * gcc.target/powerpc/darwin-abi-13-2.c: New test. * gcc.target/powerpc/darwin-structs-0.h: New test. --- gcc/config/rs6000/rs6000.cc | 3 +- .../gcc.target/powerpc/darwin-abi-13-0.c | 23 +++++++++++++++ .../gcc.target/powerpc/darwin-abi-13-1.c | 27 +++++++++++++++++ .../gcc.target/powerpc/darwin-abi-13-2.c | 27 +++++++++++++++++ .../gcc.target/powerpc/darwin-structs-0.h | 29 +++++++++++++++++++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/darwin-abi-13-0.c create mode 100644 gcc/testsuite/gcc.target/powerpc/darwin-abi-13-1.c create mode 100644 gcc/testsuite/gcc.target/powerpc/darwin-abi-13-2.c create mode 100644 gcc/testsuite/gcc.target/powerpc/darwin-structs-0.h diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 5b3b8b52e7e..42f49e4a56b 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -8209,7 +8209,8 @@ darwin_rs6000_special_round_type_align (tree type, unsigned int computed, type = TREE_TYPE (type); } while (AGGREGATE_TYPE_P (type)); - if (! AGGREGATE_TYPE_P (type) && type != error_mark_node) + if (type != error_mark_node && ! AGGREGATE_TYPE_P (type) + && ! TYPE_PACKED (type) && maximum_field_alignment == 0) align = MAX (align, TYPE_ALIGN (type)); return align; diff --git a/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-0.c b/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-0.c new file mode 100644 index 00000000000..d8d3c63a083 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-0.c @@ -0,0 +1,23 @@ +/* { dg-do compile { target powerpc*-*-darwin* } } */ +/* { dg-require-effective-target ilp32 } */ +/* { dg-options "-Wno-long-long" } */ + +#include "darwin-structs-0.h" + +int tcd[sizeof(cd) != 12 ? -1 : 1]; +int acd[__alignof__(cd) != 4 ? -1 : 1]; + +int sdc[sizeof(dc) != 16 ? -1 : 1]; +int adc[__alignof__(dc) != 8 ? -1 : 1]; + +int scL[sizeof(cL) != 12 ? -1 : 1]; +int acL[__alignof__(cL) != 4 ? -1 : 1]; + +int sLc[sizeof(Lc) != 16 ? -1 : 1]; +int aLc[__alignof__(Lc) != 8 ? -1 : 1]; + +int scD[sizeof(cD) != 32 ? -1 : 1]; +int acD[__alignof__(cD) != 16 ? -1 : 1]; + +int sDc[sizeof(Dc) != 32 ? -1 : 1]; +int aDc[__alignof__(Dc) != 16 ? -1 : 1]; diff --git a/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-1.c b/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-1.c new file mode 100644 index 00000000000..4d888d383fa --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-1.c @@ -0,0 +1,27 @@ +/* { dg-do compile { target powerpc*-*-darwin* } } */ +/* { dg-require-effective-target ilp32 } */ +/* { dg-options "-Wno-long-long" } */ + +#pragma pack(push, 1) + +#include "darwin-structs-0.h" + +int tcd[sizeof(cd) != 9 ? -1 : 1]; +int acd[__alignof__(cd) != 1 ? -1 : 1]; + +int sdc[sizeof(dc) != 9 ? -1 : 1]; +int adc[__alignof__(dc) != 1 ? -1 : 1]; + +int scL[sizeof(cL) != 9 ? -1 : 1]; +int acL[__alignof__(cL) != 1 ? -1 : 1]; + +int sLc[sizeof(Lc) != 9 ? -1 : 1]; +int aLc[__alignof__(Lc) != 1 ? -1 : 1]; + +int scD[sizeof(cD) != 17 ? -1 : 1]; +int acD[__alignof__(cD) != 1 ? -1 : 1]; + +int sDc[sizeof(Dc) != 17 ? -1 : 1]; +int aDc[__alignof__(Dc) != 1 ? -1 : 1]; + +#pragma pack(pop) diff --git a/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-2.c b/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-2.c new file mode 100644 index 00000000000..3bd52c0a8f8 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-2.c @@ -0,0 +1,27 @@ +/* { dg-do compile { target powerpc*-*-darwin* } } */ +/* { dg-require-effective-target ilp32 } */ +/* { dg-options "-Wno-long-long" } */ + +#pragma pack(push, 2) + +#include "darwin-structs-0.h" + +int tcd[sizeof(cd) != 10 ? -1 : 1]; +int acd[__alignof__(cd) != 2 ? -1 : 1]; + +int sdc[sizeof(dc) != 10 ? -1 : 1]; +int adc[__alignof__(dc) != 2 ? -1 : 1]; + +int scL[sizeof(cL) != 10 ? -1 : 1]; +int acL[__alignof__(cL) != 2 ? -1 : 1]; + +int sLc[sizeof(Lc) != 10 ? -1 : 1]; +int aLc[__alignof__(Lc) != 2 ? -1 : 1]; + +int scD[sizeof(cD) != 18 ? -1 : 1]; +int acD[__alignof__(cD) != 2 ? -1 : 1]; + +int sDc[sizeof(Dc) != 18 ? -1 : 1]; +int aDc[__alignof__(Dc) != 2 ? -1 : 1]; + +#pragma pack(pop) diff --git a/gcc/testsuite/gcc.target/powerpc/darwin-structs-0.h b/gcc/testsuite/gcc.target/powerpc/darwin-structs-0.h new file mode 100644 index 00000000000..1db44f7a808 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/darwin-structs-0.h @@ -0,0 +1,29 @@ +typedef struct _cd { + char c; + double d; +} cd; + +typedef struct _dc { + double d; + char c; +} dc; + +typedef struct _cL { + char c; + long long L; +} cL; + +typedef struct _Lc { + long long L; + char c; +} Lc; + +typedef struct _cD { + char c; + long double D; +} cD; + +typedef struct _Dc { + long double D; + char c; +} Dc;