From: Eric Botcazou <botcazou@adacore.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix PR tree-optimization/108199
Date: Wed, 11 Jan 2023 10:59:39 +0100 [thread overview]
Message-ID: <2889898.e9J7NaK4W3@fomalhaut> (raw)
[-- Attachment #1: Type: text/plain, Size: 486 bytes --]
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 <ebotcazou@adacore.com>
Andreas Krebbel <krebbel@linux.ibm.com>
PR tree-optimization/108199
* tree-sra.cc (sra_modify_expr): Deal with reverse storage order
for bit-field references.
2023-01-11 Eric Botcazou <ebotcazou@adacore.com>
* gcc.dg/sso-17.c: New test.
--
Eric Botcazou
[-- Attachment #2: pr108199.diff --]
[-- Type: text/x-patch, Size: 937 bytes --]
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)
[-- Attachment #3: sso17.adb --]
[-- Type: text/x-adasrc, Size: 628 bytes --]
-- { 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;
next reply other threads:[~2023-01-11 9:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 9:59 Eric Botcazou [this message]
2023-01-11 12:03 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2889898.e9J7NaK4W3@fomalhaut \
--to=botcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).