From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 7294E3858289 for ; Wed, 11 Jan 2023 09:59:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7294E3858289 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x330.google.com with SMTP id j16-20020a05600c1c1000b003d9ef8c274bso7835965wms.0 for ; Wed, 11 Jan 2023 01:59:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=LZJphaVWDWAUVOjz5vsGSLJ8WD9henjpURPwnUCWGxg=; b=Bmc9jq8AI6AldC7sFqjc+F1PIXxHM+T8qvu39cJkj5ddWUxLz+9y5Qm/DkqB1cXu6D cd+1DOi3FfRm5wX2Z4j//jenaRcyE7agZUNzKjV8FcyaWTnD5otzR0AnqBxs1xMBOkCw YiKmu2Hdj4tmJtnXglM4VVf5fg9/uXNxKwm/0QzryG0+xG3c4/ejp4s3qCiSslttD7p0 Qgc5H4RPokjY12NGSm1jfKRrSj4cJjvym3RvgxUok/vsD/omQzlwsh8E6nxj7MGngc9x 3A0l+kBKYn1BVD4olmi0iYjr65roMVWL/lMvFj07h6/yAGJV9ZKEHlGPckMdg6tE/kdc 51aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LZJphaVWDWAUVOjz5vsGSLJ8WD9henjpURPwnUCWGxg=; b=JwjLrf2CMB2DMTyqwe+PoLRiDvt4xKDhHBQPiHDV5WkGCGcUi+toxqYzBOBHjQzogA 2zslN2psBJwQJbV40gSXrl/4UrImUfJrlycXlfjwjxSD1MJVRLigcbNRb5WEOM59bAmP KsinwGurBJvPONVIbu3lArA4E4sLAcEenXZ7mvlP7nJ9A+MEMuW0fCYeQytFQ5Deb5mx MixkQwLdfMw1hVW1gTuVpcVqpalsRF43tRnEGv+VCnIRhw/uq4vzQMJK0W046+bPeEx2 j0ONeVOmggSM+J4M6QCOCwI7uq3XjRXQ/Jy3xSYMkYvmR/okBGOa8Wf2NK7SO6PzYpi7 OjmQ== X-Gm-Message-State: AFqh2kqe8k3l4qKUwPRPQZ4JszbCG4Zz2FDqUarrZaGJC2koevn0h+5Z /V4ahj31F/u1LKWjB/JmDKwFCRFJAgJV+hY0 X-Google-Smtp-Source: AMrXdXvy3Nu3PZTPDnbcp6UXauRfmSGiwGItNRmXyjkbt0Oehpit/2MgL/COk391cwf6g9GBHnvF9g== X-Received: by 2002:a05:600c:5c8:b0:3d1:4145:b3b with SMTP id p8-20020a05600c05c800b003d141450b3bmr53262783wmd.9.1673431180703; Wed, 11 Jan 2023 01:59:40 -0800 (PST) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id p16-20020a05600c469000b003d9b87296a9sm24623953wmo.25.2023.01.11.01.59.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 01:59:40 -0800 (PST) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR tree-optimization/108199 Date: Wed, 11 Jan 2023 10:59:39 +0100 Message-ID: <2889898.e9J7NaK4W3@fomalhaut> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart3235138.aeNJFYEL58" Content-Transfer-Encoding: 7Bit X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This is a multi-part message in MIME format. --nextPart3235138.aeNJFYEL58 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Hi, this fixes the problematic interaction between bitfields, unions, SSO and SRA. Tested on x86-64/Linux and SPARC/Solaris, OK for all active branches? 2023-01-11 Eric Botcazou Andreas Krebbel PR tree-optimization/108199 * tree-sra.cc (sra_modify_expr): Deal with reverse storage order for bit-field references. 2023-01-11 Eric Botcazou * gcc.dg/sso-17.c: New test. -- Eric Botcazou --nextPart3235138.aeNJFYEL58 Content-Disposition: attachment; filename="pr108199.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="utf-8"; name="pr108199.diff" diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc index f0182a45485..ad0c738645d 100644 --- a/gcc/tree-sra.cc +++ b/gcc/tree-sra.cc @@ -3858,7 +3858,23 @@ sra_modify_expr (tree *expr, gimple_stmt_iterator *gsi, bool write) } } else - *expr = repl; + { + /* If we are going to replace a scalar field in a structure with + reverse storage order by a stand-alone scalar, we are going to + effectively byte-swap the scalar and we also need to byte-swap + the portion of it represented by the bit-field. */ + if (bfr && REF_REVERSE_STORAGE_ORDER (bfr)) + { + REF_REVERSE_STORAGE_ORDER (bfr) = 0; + TREE_OPERAND (bfr, 2) + = size_binop (MINUS_EXPR, TYPE_SIZE (TREE_TYPE (repl)), + size_binop (PLUS_EXPR, TREE_OPERAND (bfr, 1), + TREE_OPERAND (bfr, 2))); + } + + *expr = repl; + } + sra_stats.exprs++; } else if (write && access->grp_to_be_debug_replaced) --nextPart3235138.aeNJFYEL58 Content-Disposition: attachment; filename="sso17.adb" Content-Transfer-Encoding: 7Bit Content-Type: text/x-adasrc; charset="utf-8"; name="sso17.adb" -- { dg-do run } -- { dg-options "-gnatws -O" } with System; procedure SSO17 is type My_Float is new Float range 0.0 .. 359.99; type Rec is record Az : My_Float; El : My_Float; end record; for Rec'Bit_Order use System.High_Order_First; for Rec'Scalar_Storage_Order use System.High_Order_First; R : Rec; procedure Is_True (B : Boolean); pragma No_Inline (Is_True); procedure Is_True (B : Boolean) is begin if not B then raise Program_Error; end if; end; begin R := (Az => 1.1, El => 2.2); Is_True (R.Az'Valid); R := (Az => 3.3, El => 4.4); Is_True (R.Az'Valid); end; --nextPart3235138.aeNJFYEL58--