From patchwork Tue Jun 7 16:24:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 54892 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 95204393BC01 for ; Tue, 7 Jun 2022 16:25:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95204393BC01 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1654619138; bh=09H5qgZXxvh1P/OYgvXTbEiAH9TPoZ9lPejJ7/AFcJ8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=RfA4BSz0E/3FCokNKmgYeyL6IBJzm0vUT72KscmZXU2Tr3MqmhVuUXEgKnc3BzX4t 3cbEhm8XkHqVeAtuAuEBG+Uicj1bKatqISa+EEr+9J0c175DkWBU5tVklAQbjPV9Be X1bN4ouvjnJU2+d8YW/flwdnySLCk0O/FYNWx92U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2041.outbound.protection.outlook.com [40.107.21.41]) by sourceware.org (Postfix) with ESMTPS id D6D4A382D52F for ; Tue, 7 Jun 2022 16:25:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D6D4A382D52F ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=DAsg+wtJtgE2EHROn++WNIsCGBMe1Mu89WPa+I3TAy+tMOsvAbzY5h79BmNJCLi8JzATLbFkN8USpNK3kWKk6Co+voe49SHgykWcLfs7cHUDvN1WO7xv+U3qVp35u7F6pUogQ8Uhx6QB80WUh3hZZo25qbPOZXiusqDHUUR8YynztGgd8VJ0PH4OmbYi6nV1rx+cEZ9QefXf7oyCJtrg2ntJVhuxunmANhVrDefOby1uQpGbG3SN0pW3N1OLV6b5RnZpiJHu83fx84mUeDNDYShCIySDSukv67WYYJ3OaSLs4zkIYWaJJ+oVX9xRn3FlNYYgkAiXG2Fw+u2CZysDTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=09H5qgZXxvh1P/OYgvXTbEiAH9TPoZ9lPejJ7/AFcJ8=; b=NmRDJPyesedm02JxqYoNUOQfTdtZBTC7UfrzvajFSL/3WFbloFl6c6J6aEYE9sWq295+bT/XtBHJTLWdCYmOLwjHAY2at/U0dfcnETzUxsdYDhvs/0o66SYgARBi78kHRoDsuAUp5givjR2+Rj6ynlNqgKoXcLV4R/KTScZM1rBJqN0Q7C48fWyELM9ynWvZa8lRL5eZwIu75o8pXruZqpzZBD02LIw5B7xEKpm6TI1Q2iV6bWTYDsZHRrwO3I/aUMpLOXBKH1iai4mQUOgeed3oegAh3QyhIKNgISjrh8FDf3Mv0XVze1b0Yr9wVD1y7eOps8EcL6erKCxtEUMeUg== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from AS9PR06CA0772.eurprd06.prod.outlook.com (2603:10a6:20b:484::27) by DB6PR08MB2872.eurprd08.prod.outlook.com (2603:10a6:6:24::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.17; Tue, 7 Jun 2022 16:25:03 +0000 Received: from VE1EUR03FT054.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:484:cafe::3c) by AS9PR06CA0772.outlook.office365.com (2603:10a6:20b:484::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12 via Frontend Transport; Tue, 7 Jun 2022 16:25:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT054.mail.protection.outlook.com (10.152.19.64) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12 via Frontend Transport; Tue, 7 Jun 2022 16:25:02 +0000 Received: ("Tessian outbound 5b5a41c043d3:v120"); Tue, 07 Jun 2022 16:25:02 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 1e805af6ca2a8e73 X-CR-MTA-TID: 64aa7808 Received: from a8cee748b3ae.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 270B2F7F-3CDE-4D8F-A1DE-5EBB242789E4.1; Tue, 07 Jun 2022 16:24:51 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a8cee748b3ae.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 07 Jun 2022 16:24:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HBVBDFkV70doMvZzvJc0Vn8RSMo/PVYn46q6toDsuTacBk/HsK8rL7vivlnGU3nQ5hHHZOnFvz++vAa8CgIvAZduzxyiACeF/ptka9gVQf4yE5zYiS0uzwEPBRJudFlfPo32hXsBYtBGj77Om09th1lsaMK2a8l4vNEA5qeqrdylyO3LNEaZN6ASqCTGlPx//6SWt7XQiyEDA+5Dhcb8CeRFbEazKvq1oViESHYvaAfXDtBU3qfEY7bUhqXYWLx7Uk11vZtFGLbENf8jBXyWIdNCbys0jnV/JQRuhj6Fy6e5U+ujIJZlP9alR+rCvD3nw/tMQIxiwVW7DbXiqjbiMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=09H5qgZXxvh1P/OYgvXTbEiAH9TPoZ9lPejJ7/AFcJ8=; b=RVlxWfR02cJmg2IMbNt08fTqI2+lPUPFC2jP613UvZU0e85h2WBqKlDikyHkG+Ro9tZ/X5zBEuW5i6omwsSjaRxrQpKI3x/+XFHT1Wjx2A5XzAHA1O/zVWEeAiRb2933sk6ef0+15ucbyRieE45tPGJ4cK0zZVADg54nLoUUx+OwjbdbUR6fmjDVKW7VttZjPwQgVyxes6UlvUeTJrpoJ6dwAoAz40qm6LQu/qqjy56oKmsEhMnduPeo7s/bTl6QNPETAlSkVjxdceWGxdIMwxxE254ashMQ0kDIy3n9/EYEKqfrPKckx8mxQmBoZ7J5StAtBxU7ErLQzQNSBan64g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from AS9PR06CA0722.eurprd06.prod.outlook.com (2603:10a6:20b:487::30) by DB8PR08MB3964.eurprd08.prod.outlook.com (2603:10a6:10:a4::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.17; Tue, 7 Jun 2022 16:24:38 +0000 Received: from VE1EUR03FT046.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:487:cafe::2c) by AS9PR06CA0722.outlook.office365.com (2603:10a6:20b:487::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13 via Frontend Transport; Tue, 7 Jun 2022 16:24:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by VE1EUR03FT046.mail.protection.outlook.com (10.152.19.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Tue, 7 Jun 2022 16:24:38 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Tue, 7 Jun 2022 16:24:36 +0000 Received: from e129018.arm.com (10.57.83.43) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Tue, 7 Jun 2022 16:24:36 +0000 To: Subject: aarch64: Fix bitfield alignment in param passing [PR105549] Date: Tue, 7 Jun 2022 18:24:31 +0200 Message-ID: <20220607162431.243236-1-christophe.lyon@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: bf87d48b-4b6f-4abb-f9e7-08da48a2465e X-MS-TrafficTypeDiagnostic: DB8PR08MB3964:EE_|VE1EUR03FT054:EE_|DB6PR08MB2872:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: wr8tGPY3mnsvaxfumoyRgqRmeSjUdA/X+qEqkWrEza55m9664tP9NRiU+8zb9QhHknd0Xz6781kcOx6Nbnofg5psz+rsLgRV0skoDnA+9onPQe7Yl9iL5qPYxW7KDwuWYvLWqiVF5Le1pisth9vXX3mZFlpZVm5M67SlwUjt1mk5zjawC53G9UdPVIixKAoCamAtkijMDLP+idTIRq8/f3t8bFyfKHzurz+0JbvqBXUZ5apH8tFiZvlPnyacXTCFOizKqKYaPvscApwKnzsGtQpAWKi/Fhnk/3oTgqxbD82ZF5pFXJBV/qLH/IXlsy1Kj2YZW6dJ9KfVd+PzDYh2bK+w7yGsUiMpp3zigv4M42Om4dlfT/tSrXuEK+uCshJdklotpNptb1jcqr4+GHdNXIonvPksxO43FI+R9yF24H/XLwGtWuEqsqLmVp0kNMqt5DTea5aBtyooj+MJns2HOJI8UuDiIY1TMmSFKYcaCvz84cT5rBCgnxjyN9921GUpv8w4EF5l5Wlo6rjba/MCrUf+kUvhRc70pLTsuKGkFfhAWeY2DHD3axI9SVp275PZUN/e3ySoSbjwKY3EOL0uEzLIldic5awTpFvwrHxO9urXgWe/zsRf+0jfDlmh0PrrcLzNau6z+c4mBZXbh8UmCKrCD8pCqtB2jLR6KYcecWEMJHjjwsST1cX7WbHjfFq6F33MP2dFRx5hlgEgo9dvTRKcr9vjb5qcxQzLSdBeZT4bY8sKFyX5M1OJY5tqZMdL+RmS6MoBH9bvRPy7NTvAaKFNeajiK27FukIW0JhEvaT9+d02Az/Fj2QqTOhV2kVMJ5UGlWs0A8NlkiPTMvHu8Q== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(356005)(44832011)(83380400001)(6666004)(8936002)(84970400001)(81166007)(40460700003)(70206006)(5660300002)(6916009)(54906003)(70586007)(235185007)(2906002)(316002)(86362001)(8676002)(4326008)(82310400005)(508600001)(186003)(2616005)(1076003)(36756003)(426003)(47076005)(336012)(7696005)(33964004)(36860700001)(26005)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB3964 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT054.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 2da832a9-8352-42cf-7c5e-08da48a237a5 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7lbnBdJvlfRbaxUDoTrc63XL6vsWAwbrtEIXu5OasyeFn9AzhYrRnd7CDOUMuTX57cSssVfky73HfrW0Rm47Lt4gG9JxtWyHCSuLbJwRlRSYIzu17y1MZDpcm3xhMDiZ5tY1ns2FqlSAsJefRqdnP8rN+ZQGP9X+nlRc5VwYq1RpBW2CeUt4W7g9krdHw1N9PY8TYOJEf9NNoaAOHdS0gSHHpUlWBxhpB56Q6J5tkIy6WXQyNez/DgorCCnaEijb/+sRxV2QSzo8/JGfU3yGKaU9Xh4Lmndsz47/AUqrbRUP7sjbXXnUt1N2L5ELCbzqd/LJBoFvAYLk3LhS4QVB5i9rYgUOgIiBj2jmzw1mUgxNxJaCSjdWtWsiv8yyNTacFGLb+oGLjrPp70Uu7KAC64ckSw5HWnzE4f8+heHxcoq7EXNf8s8IUOz66SI2V3j3G7Y0RoChM5+/WG9yMM1oeLHLvDs0P62fYT1/4FhEIQLvaCqf/q0ZNCVuWeEEScbkschOFsqfCVhTK3i2avvOc2nIxo8OeZFzuYdUOx1eDaHCpj8hU/gE7n+Gaj12zgio1otdlqX6m3Vkp/h3kaVLdP7jdCpL3N22OwLpEd0PyvhLZ1dc+8DmvFSFHJMgjw3hkVksAM3CnyBXe45TPGVFR/mPQbWxnKwVkcJ/nE8DTuG2Z6aKS9xCQmz7HphqyGV5MbBl77o744I3t9yQYuuXKB16cw3dpvtIza6q8D9DhqFKz/80hwvKbbRK9jqVx34FjyqicRAOeJ2jFyMbNpa7gtK31GDou3ctMrsnv6IuXIxBwvLC0lCQF1AGsXemSpwB X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(508600001)(83380400001)(84970400001)(8936002)(36756003)(186003)(1076003)(26005)(33964004)(336012)(426003)(2616005)(47076005)(7696005)(6666004)(40460700003)(82310400005)(86362001)(2906002)(6916009)(54906003)(5660300002)(44832011)(70206006)(4326008)(70586007)(235185007)(8676002)(36860700001)(81166007)(316002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2022 16:25:02.7520 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf87d48b-4b6f-4abb-f9e7-08da48a2465e X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT054.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR08MB2872 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY 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: Christophe Lyon via Gcc-patches From: Christophe Lyon Reply-To: Christophe Lyon Cc: nd@arm.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" While working on enabling DFP for AArch64, I noticed new failures in gcc.dg/compat/struct-layout-1.exp (t028) which were not actually caused by DFP types handling. These tests are generated during 'make check' and enabling DFP made generation different (not sure if new non-DFP tests are generated, or if existing ones are generated differently, the tests in question are huge and difficult to compare). Anyway, I reduced the problem to what I attach at the end of the new gcc.target/aarch64/aapcs64/va_arg-17.c test and rewrote it in the same scheme as other va_arg* AArch64 tests. Richard Sandiford further reduced this to a non-vararg function, added as a second testcase. This is a tough case mixing bitfields and alignment, where aarch64_function_arg_alignment did not follow what its descriptive comment says: we want to use the natural alignment of the bitfield type only if the user didn't override the alignment for the bitfield itself. The fix is thus very small, and this patch adds two new tests (va_arg-17.c and pr105549.c). va_arg-17.c contains the reduced offending testcase from struct-layout-1.exp for reference. We also take the opportunity to fix the comment above aarch64_function_arg_alignment since the value of the abi_break parameter was changed in a previous commit, no longer match the description. 2022-06-02 Christophe Lyon gcc/ PR target/105549 * config/aarch64/aarch64.cc (aarch64_function_arg_alignment): Check DECL_USER_ALIGN for bitfield. gcc/testsuite/ PR target/105549 * gcc.target/aarch64/aapcs64/va_arg-17.c: New. * gcc.target/aarch64/pr105549.c: New. ############### Attachment also inlined for ease of reply ############### diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 40fc5e633992036a2c06867857a681792178ef00..2c6ccce7cb5dc32097d24514ee525729efb6b7ff 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -7262,9 +7262,9 @@ aarch64_vfp_is_call_candidate (cumulative_args_t pcum_v, machine_mode mode, /* Given MODE and TYPE of a function argument, return the alignment in bits. The idea is to suppress any stronger alignment requested by the user and opt for the natural alignment (specified in AAPCS64 \S - 4.1). ABI_BREAK is set to true if the alignment was incorrectly - calculated in versions of GCC prior to GCC-9. This is a helper - function for local use only. */ + 4.1). ABI_BREAK is set to the old alignment if the alignment was + incorrectly calculated in versions of GCC prior to GCC-9. This is + a helper function for local use only. */ static unsigned int aarch64_function_arg_alignment (machine_mode mode, const_tree type, @@ -7304,7 +7304,10 @@ aarch64_function_arg_alignment (machine_mode mode, const_tree type, "s" contains only one Fundamental Data Type (the int field) but gains 8-byte alignment and size thanks to "e". */ alignment = std::max (alignment, DECL_ALIGN (field)); - if (DECL_BIT_FIELD_TYPE (field)) + + /* Take bit-field type's alignment into account only if the + user didn't override this field's alignment. */ + if (DECL_BIT_FIELD_TYPE (field) && !DECL_USER_ALIGN (field)) bitfield_alignment = std::max (bitfield_alignment, TYPE_ALIGN (DECL_BIT_FIELD_TYPE (field))); diff --git a/gcc/testsuite/gcc.target/aarch64/aapcs64/va_arg-17.c b/gcc/testsuite/gcc.target/aarch64/aapcs64/va_arg-17.c new file mode 100644 index 0000000000000000000000000000000000000000..24895c3ab48309b601f6f22c176f1e52350c2257 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/aapcs64/va_arg-17.c @@ -0,0 +1,105 @@ +/* Test AAPCS64 layout and __builtin_va_arg. + + This test covers a corner case where a composite type parameter fits in one + register: we do not need a double-word alignment when accessing it in the + va_arg stack area. */ + +/* { dg-do run { target aarch64*-*-* } } */ + +#ifndef IN_FRAMEWORK +#define AAPCS64_TEST_STDARG +#define TESTFILE "va_arg-17.c" +#include "type-def.h" + +enum E6 { e6_0, e6_1, e6_2, e6_3, e6_65533 = 65533, e6_65534, e6_65535 }; +typedef enum E6 Tal16E6 __attribute__((aligned (16))); +typedef unsigned int Tuint; + +int fails; + +union S2844 { + Tuint a:((((10) - 1) & 31) + 1); + Tal16E6 __attribute__((aligned (2), packed)) b:31; + struct{}c[0]; +} ; +union S2844 s2844; +union S2844 a2844[5]; + +#define HAS_DATA_INIT_FUNC +void init_data () +{ + memset (&s2844, '\0', sizeof (s2844)); + memset (a2844, '\0', sizeof (a2844)); + s2844.a = 799U; + a2844[2].a = 586U; +} + +#include "abitest.h" +#else + ARG (int , 1 , W0 , LAST_NAMED_ARG_ID) + DOTS + ANON_PROMOTED (float , 1.0f, double, 1.0, D0, 1) + ANON (union S2844 , s2844 , X1 , 2) + ANON (long long , 2LL , X2 , 3) + ANON (union S2844 , a2844[2] , X3 , 4) + LAST_ANON (union S2844 , a2844[2] , X4 , 5) +#endif + +#if 0 + /* This test is derived from a case generated by struct-layout-1.exp: */ + +enum E6 { e6_0, e6_1, e6_2, e6_3, e6_65533 = 65533, e6_65534, e6_65535 }; +typedef enum E6 Tal16E6 __attribute__((aligned (16))); +typedef unsigned int Tuint; + +int fails; + +union S2844 { + Tuint a:((((10) - 1) & 31) + 1); + Tal16E6 __attribute__((aligned (2), packed)) b:31; + struct{}c[0]; +} ; +union S2844 s2844; +union S2844 a2844[5]; + +typedef __builtin_va_list __gnuc_va_list; +typedef __gnuc_va_list va_list; + +void check2844va (int z, ...) { + union S2844 arg, *p; + va_list ap; + + __builtin_va_start(ap,z); + if (__builtin_va_arg(ap,double) != 1.0) + printf ("fail %d.%d\n", 2844, 0), ++fails; + + p = &s2844; + arg = __builtin_va_arg(ap,union S2844); /* This would fail. */ + if (p->a != arg.a) + printf ("fail %d.%d\n", 2844, 1), ++fails; + + if (__builtin_va_arg(ap,long long) != 3LL) + printf ("fail %d.%d\n", 2844, 2), ++fails; + + p = &a2844[2]; + arg = __builtin_va_arg(ap,union S2844); /* This would fail. */ + if (p->a != arg.a) + printf ("fail %d.%d\n", 2844, 3), ++fails; + + arg = __builtin_va_arg(ap,union S2844); /* This would fail. */ + if (p->a != arg.a) + printf ("fail %d.%d\n", 2844, 4), ++fails; + + __builtin_va_end(ap); +} + +int main (void) { + int i, j; + memset (&s2844, '\0', sizeof (s2844)); + memset (a2844, '\0', sizeof (a2844)); + s2844.a = 799U; + a2844[2].a = 586U; + check2844va (1, 1.0, s2844, 2LL, a2844[2], a2844[2]); + exit (fails != 0); +} +#endif /* 0 */ diff --git a/gcc/testsuite/gcc.target/aarch64/pr105549.c b/gcc/testsuite/gcc.target/aarch64/pr105549.c new file mode 100644 index 0000000000000000000000000000000000000000..55a91ed6bc48b56eed61d668971e890dbd3250ef --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr105549.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-save-temps" } */ + +enum e { E1 }; +typedef enum e e __attribute__((aligned(16))); +union u { + __attribute__((aligned(2), packed)) e a : 1; + int x[4]; +}; +union u g(int a, union u u2) { return u2; } + +/* { dg-final { scan-assembler "stp\tx1, x2, \\\[sp, 8\\\]" } } */ diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 40fc5e633992036a2c06867857a681792178ef00..2c6ccce7cb5dc32097d24514ee525729efb6b7ff 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -7262,9 +7262,9 @@ aarch64_vfp_is_call_candidate (cumulative_args_t pcum_v, machine_mode mode, /* Given MODE and TYPE of a function argument, return the alignment in bits. The idea is to suppress any stronger alignment requested by the user and opt for the natural alignment (specified in AAPCS64 \S - 4.1). ABI_BREAK is set to true if the alignment was incorrectly - calculated in versions of GCC prior to GCC-9. This is a helper - function for local use only. */ + 4.1). ABI_BREAK is set to the old alignment if the alignment was + incorrectly calculated in versions of GCC prior to GCC-9. This is + a helper function for local use only. */ static unsigned int aarch64_function_arg_alignment (machine_mode mode, const_tree type, @@ -7304,7 +7304,10 @@ aarch64_function_arg_alignment (machine_mode mode, const_tree type, "s" contains only one Fundamental Data Type (the int field) but gains 8-byte alignment and size thanks to "e". */ alignment = std::max (alignment, DECL_ALIGN (field)); - if (DECL_BIT_FIELD_TYPE (field)) + + /* Take bit-field type's alignment into account only if the + user didn't override this field's alignment. */ + if (DECL_BIT_FIELD_TYPE (field) && !DECL_USER_ALIGN (field)) bitfield_alignment = std::max (bitfield_alignment, TYPE_ALIGN (DECL_BIT_FIELD_TYPE (field))); diff --git a/gcc/testsuite/gcc.target/aarch64/aapcs64/va_arg-17.c b/gcc/testsuite/gcc.target/aarch64/aapcs64/va_arg-17.c new file mode 100644 index 0000000000000000000000000000000000000000..24895c3ab48309b601f6f22c176f1e52350c2257 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/aapcs64/va_arg-17.c @@ -0,0 +1,105 @@ +/* Test AAPCS64 layout and __builtin_va_arg. + + This test covers a corner case where a composite type parameter fits in one + register: we do not need a double-word alignment when accessing it in the + va_arg stack area. */ + +/* { dg-do run { target aarch64*-*-* } } */ + +#ifndef IN_FRAMEWORK +#define AAPCS64_TEST_STDARG +#define TESTFILE "va_arg-17.c" +#include "type-def.h" + +enum E6 { e6_0, e6_1, e6_2, e6_3, e6_65533 = 65533, e6_65534, e6_65535 }; +typedef enum E6 Tal16E6 __attribute__((aligned (16))); +typedef unsigned int Tuint; + +int fails; + +union S2844 { + Tuint a:((((10) - 1) & 31) + 1); + Tal16E6 __attribute__((aligned (2), packed)) b:31; + struct{}c[0]; +} ; +union S2844 s2844; +union S2844 a2844[5]; + +#define HAS_DATA_INIT_FUNC +void init_data () +{ + memset (&s2844, '\0', sizeof (s2844)); + memset (a2844, '\0', sizeof (a2844)); + s2844.a = 799U; + a2844[2].a = 586U; +} + +#include "abitest.h" +#else + ARG (int , 1 , W0 , LAST_NAMED_ARG_ID) + DOTS + ANON_PROMOTED (float , 1.0f, double, 1.0, D0, 1) + ANON (union S2844 , s2844 , X1 , 2) + ANON (long long , 2LL , X2 , 3) + ANON (union S2844 , a2844[2] , X3 , 4) + LAST_ANON (union S2844 , a2844[2] , X4 , 5) +#endif + +#if 0 + /* This test is derived from a case generated by struct-layout-1.exp: */ + +enum E6 { e6_0, e6_1, e6_2, e6_3, e6_65533 = 65533, e6_65534, e6_65535 }; +typedef enum E6 Tal16E6 __attribute__((aligned (16))); +typedef unsigned int Tuint; + +int fails; + +union S2844 { + Tuint a:((((10) - 1) & 31) + 1); + Tal16E6 __attribute__((aligned (2), packed)) b:31; + struct{}c[0]; +} ; +union S2844 s2844; +union S2844 a2844[5]; + +typedef __builtin_va_list __gnuc_va_list; +typedef __gnuc_va_list va_list; + +void check2844va (int z, ...) { + union S2844 arg, *p; + va_list ap; + + __builtin_va_start(ap,z); + if (__builtin_va_arg(ap,double) != 1.0) + printf ("fail %d.%d\n", 2844, 0), ++fails; + + p = &s2844; + arg = __builtin_va_arg(ap,union S2844); /* This would fail. */ + if (p->a != arg.a) + printf ("fail %d.%d\n", 2844, 1), ++fails; + + if (__builtin_va_arg(ap,long long) != 3LL) + printf ("fail %d.%d\n", 2844, 2), ++fails; + + p = &a2844[2]; + arg = __builtin_va_arg(ap,union S2844); /* This would fail. */ + if (p->a != arg.a) + printf ("fail %d.%d\n", 2844, 3), ++fails; + + arg = __builtin_va_arg(ap,union S2844); /* This would fail. */ + if (p->a != arg.a) + printf ("fail %d.%d\n", 2844, 4), ++fails; + + __builtin_va_end(ap); +} + +int main (void) { + int i, j; + memset (&s2844, '\0', sizeof (s2844)); + memset (a2844, '\0', sizeof (a2844)); + s2844.a = 799U; + a2844[2].a = 586U; + check2844va (1, 1.0, s2844, 2LL, a2844[2], a2844[2]); + exit (fails != 0); +} +#endif /* 0 */ diff --git a/gcc/testsuite/gcc.target/aarch64/pr105549.c b/gcc/testsuite/gcc.target/aarch64/pr105549.c new file mode 100644 index 0000000000000000000000000000000000000000..55a91ed6bc48b56eed61d668971e890dbd3250ef --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr105549.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-save-temps" } */ + +enum e { E1 }; +typedef enum e e __attribute__((aligned(16))); +union u { + __attribute__((aligned(2), packed)) e a : 1; + int x[4]; +}; +union u g(int a, union u u2) { return u2; } + +/* { dg-final { scan-assembler "stp\tx1, x2, \\\[sp, 8\\\]" } } */