public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR tree-optimization/108199
@ 2023-01-11  9:59 Eric Botcazou
  2023-01-11 12:03 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2023-01-11  9:59 UTC (permalink / raw)
  To: gcc-patches

[-- 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;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix PR tree-optimization/108199
  2023-01-11  9:59 [PATCH] Fix PR tree-optimization/108199 Eric Botcazou
@ 2023-01-11 12:03 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-01-11 12:03 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches

On Wed, Jan 11, 2023 at 11:00 AM Eric Botcazou via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> 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?

OK.

Thanks,
Richard.

>
> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-11 12:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-11  9:59 [PATCH] Fix PR tree-optimization/108199 Eric Botcazou
2023-01-11 12:03 ` Richard Biener

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).