From ee460e75424c78db2684a8f4dec1c993b0c05758 Mon Sep 17 00:00:00 2001 From: Martin Jambor Date: Thu, 16 Jun 2011 22:21:21 +0200 Subject: [PATCH] re PR tree-optimization/49343 (ICE on field with variable offset) 2011-06-16 Martin Jambor PR tree-optimization/49343 * tree-sra.c (build_ref_for_model): Use component_ref_field_offset to calculate offset, provide 2nd operand for the new COMPONENT_REF. * testsuite/gnat.dg/discr31.adb: New test. * testsuite/gnat.dg/discr31.ads: Likewise. From-SVN: r175111 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gnat.dg/discr31.adb | 12 ++++++++++++ gcc/testsuite/gnat.dg/discr31.ads | 14 ++++++++++++++ gcc/tree-sra.c | 12 ++++++++---- 5 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/discr31.adb create mode 100644 gcc/testsuite/gnat.dg/discr31.ads diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3e5026a6d41..0d04bc82e09 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2011-06-16 Martin Jambor + + PR tree-optimization/49343 + * tree-sra.c (build_ref_for_model): Use component_ref_field_offset to + calculate offset, provide 2nd operand for the new COMPONENT_REF. + 2011-06-16 Iain Sandoe * config/darwin-protos.h (machopic_select_rtx_section): Move to diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 01be215537c..afe706ca30a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2011-06-16 Martin Jambor + + PR tree-optimization/49343 + * gnat.dg/discr31.adb: New test. + * gnat.dg/discr31.ads: Likewise. + 2011-06-16 Rainer Orth * gcc.dg/debug/pr49032.c: Prune mips-tfile warning. diff --git a/gcc/testsuite/gnat.dg/discr31.adb b/gcc/testsuite/gnat.dg/discr31.adb new file mode 100644 index 00000000000..0fe02cc2131 --- /dev/null +++ b/gcc/testsuite/gnat.dg/discr31.adb @@ -0,0 +1,12 @@ +-- { dg-do compile } +-- { dg-options "-O" } + +package body Discr31 is + + function Log_Item(Packet : in Packet_Data_Type) return Log_Item_Type is + None : Log_Item_Type(0); + begin + return None; + end; + +end Discr31; diff --git a/gcc/testsuite/gnat.dg/discr31.ads b/gcc/testsuite/gnat.dg/discr31.ads new file mode 100644 index 00000000000..ffc76b45943 --- /dev/null +++ b/gcc/testsuite/gnat.dg/discr31.ads @@ -0,0 +1,14 @@ +package Discr31 is + + type Byte_List_Type is array(Positive range <>) of Integer; + + type Log_Item_Type(Last : Natural) is record + Data : Byte_List_Type(1 .. Last) := (others => 0); + Link : Natural := 0; + end record; + + type Packet_Data_Type is access Log_Item_Type; + + function Log_Item(Packet : in Packet_Data_Type) return Log_Item_Type; + +end Discr31; diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index c7f4174255d..28eba433dad 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -1421,12 +1421,16 @@ build_ref_for_model (location_t loc, tree base, HOST_WIDE_INT offset, { if (TREE_CODE (model->expr) == COMPONENT_REF) { - tree t, exp_type; - offset -= int_bit_position (TREE_OPERAND (model->expr, 1)); + tree t, exp_type, fld = TREE_OPERAND (model->expr, 1); + tree cr_offset = component_ref_field_offset (model->expr); + + gcc_assert (cr_offset && host_integerp (cr_offset, 1)); + offset -= TREE_INT_CST_LOW (cr_offset) * BITS_PER_UNIT; + offset -= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (fld)); exp_type = TREE_TYPE (TREE_OPERAND (model->expr, 0)); t = build_ref_for_offset (loc, base, offset, exp_type, gsi, insert_after); - return fold_build3_loc (loc, COMPONENT_REF, model->type, t, - TREE_OPERAND (model->expr, 1), NULL_TREE); + return fold_build3_loc (loc, COMPONENT_REF, model->type, t, fld, + TREE_OPERAND (model->expr, 2)); } else return build_ref_for_offset (loc, base, offset, model->type, -- 2.30.2