From: Eric Botcazou <ebotcazou@adacore.com>
To: gcc-patches@gcc.gnu.org
Subject: [Patch] Fix ICE at -O3 during IPCP
Date: Mon, 19 Oct 2009 17:38:00 -0000 [thread overview]
Message-ID: <200910191934.56704.ebotcazou@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2982 bytes --]
Hi,
the attached testcase causes an ICE at -O3 on x86 during IPCP:
#0 internal_error (gmsgid=0x98733cb "in %s, at %s:%d")
at /home/eric/gnat/gnat-head/src/gcc/diagnostic.c:672
#1 0x0865d5c4 in fancy_abort (
file=0x98e03a0 "/home/eric/gnat/gnat-head/src/gcc/tree.c", line=6199,
function=0x98e1aa3 "tree_low_cst")
at /home/eric/gnat/gnat-head/src/gcc/diagnostic.c:728
#2 0x08d2674b in tree_low_cst (t=0x0, pos=1)
at /home/eric/gnat/gnat-head/src/gcc/tree.c:6199
#3 0x08bd77f9 in build_ref_for_offset_1 (res=0xffffcc68, type=0xf7d96ec4,
offset=32, exp_type=0xf7d9672c)
at /home/eric/gnat/gnat-head/src/gcc/tree-sra.c:1246
#4 0x08bd7c9b in build_ref_for_offset (expr=0xffffcc68, type=0xf7d96ec4,
offset=32, exp_type=0xf7d9672c, allow_ptr=0 '\0')
at /home/eric/gnat/gnat-head/src/gcc/tree-sra.c:1324
#5 0x08deedbb in ipcp_lattice_from_jfunc (info=0x9f50f54, lat=0xffffccec,
jfunc=0x9f28cf8) at /home/eric/gnat/gnat-head/src/gcc/ipa-cp.c:333
(gdb) frame 5
#5 0x08deedbb in ipcp_lattice_from_jfunc (info=0x9f50f54, lat=0xffffccec,
jfunc=0x9f28cf8) at /home/eric/gnat/gnat-head/src/gcc/ipa-cp.c:333
333 ok = build_ref_for_offset (&t, TREE_TYPE (t),
(gdb) p debug_generic_expr(t)
p__data.F
p__data.F has variable size because it contains the field A which originally
had variable size... but has no size anymore since it has been cleared in
free_lang_data_in_decl:
if (TREE_CODE (decl) == PARM_DECL
|| TREE_CODE (decl) == FIELD_DECL
|| TREE_CODE (decl) == RESULT_DECL)
{
tree unit_size = DECL_SIZE_UNIT (decl);
tree size = DECL_SIZE (decl);
if ((unit_size && TREE_CODE (unit_size) != INTEGER_CST)
|| (size && TREE_CODE (size) != INTEGER_CST))
{
DECL_SIZE_UNIT (decl) = NULL_TREE;
DECL_SIZE (decl) = NULL_TREE;
}
so tree_low_cst is called on the NULL pointer
#3 0x08bd77f9 in build_ref_for_offset_1 (res=0xffffcc68, type=0xf7d96ec4,
offset=32, exp_type=0xf7d9672c)
at /home/eric/gnat/gnat-head/src/gcc/tree-sra.c:1246
1246 size = tree_low_cst (DECL_SIZE (fld), 1);
(gdb) frame 2
#2 0x08d2674b in tree_low_cst (t=0x0, pos=1)
at /home/eric/gnat/gnat-head/src/gcc/tree.c:6199
6199 gcc_assert (host_integerp (t, pos));
and aborts.
Should build_ref_for_offset_1 be prepared to deal with sizeless fields?
It is already prepared to deal with sizeless arrays immediately below:
case ARRAY_TYPE:
tr_size = TYPE_SIZE (TREE_TYPE (type));
if (!tr_size || !host_integerp (tr_size, 1))
return false;
el_size = tree_low_cst (tr_size, 1);
Patch attached, tested on i586-suse-linux, OK for mainline?
2009-10-19 Eric Botcazou <ebotcazou@adacore.com>
* tree-sra.c (build_ref_for_offset_1) <RECORD_TYPE>: Skip fields
without size or size that can be represented as a host integer.
2009-10-19 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/discr21.ad[sb]: New test.
* gnat.dg/discr21_pkg.ads: New helper.
--
Eric Botcazou
[-- Attachment #2: p.diff --]
[-- Type: text/x-diff, Size: 579 bytes --]
Index: tree-sra.c
===================================================================
--- tree-sra.c (revision 152970)
+++ tree-sra.c (working copy)
@@ -1243,7 +1243,10 @@ build_ref_for_offset_1 (tree *res, tree
pos = int_bit_position (fld);
gcc_assert (TREE_CODE (type) == RECORD_TYPE || pos == 0);
- size = tree_low_cst (DECL_SIZE (fld), 1);
+ tr_size = DECL_SIZE (fld);
+ if (!tr_size || !host_integerp (tr_size, 1))
+ continue;
+ size = tree_low_cst (tr_size, 1);
if (pos > offset || (pos + size) <= offset)
continue;
[-- Attachment #3: discr21.adb --]
[-- Type: text/x-adasrc, Size: 584 bytes --]
-- { dg-do compile }
-- { dg-options "-gnatws -O3" }
with Discr21_Pkg; use Discr21_Pkg;
package body Discr21 is
type Index is new Natural range 0 .. 100;
type Arr is array (Index range <> ) of Position;
type Rec(Size : Index := 1) is record
A : Arr(1 .. Size);
end record;
Data : Rec;
function To_V(pos : Position) return VPosition is
begin
return To_Position(pos.x, pos.y, pos.z);
end;
procedure Read(Data : Rec) is
pos : VPosition := To_V (Data.A(1));
begin
null;
end;
procedure Test is
begin
Read (Data);
end;
end Discr21;
[-- Attachment #4: discr21.ads --]
[-- Type: text/x-adasrc, Size: 52 bytes --]
package Discr21 is
procedure Test;
end Discr21;
[-- Attachment #5: discr21_pkg.ads --]
[-- Type: text/x-adasrc, Size: 351 bytes --]
package Discr21_Pkg is
type Position is record
x,y,z : Float;
end record;
type Dim is (Two, Three);
type VPosition (D: Dim := Three) is record
x, y : Float;
case D is
when Two => null;
when Three => z : Float;
end case;
end record;
function To_Position (x, y, z : Float) return VPosition;
end Discr21_Pkg;
next reply other threads:[~2009-10-19 17:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-19 17:38 Eric Botcazou [this message]
2009-10-19 17:43 ` Steven Bosscher
2009-10-19 17:47 ` Eric Botcazou
2009-10-20 9:13 ` Richard Guenther
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=200910191934.56704.ebotcazou@adacore.com \
--to=ebotcazou@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).