This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] for PR 19333
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 10 Jan 2005 09:50:15 +0100
- Subject: [patch] for PR 19333
Hello,
with
extern short ac[][];
ivopts asks to gimplify the following expression:
&(*(short int[4] *) &ac)[0];
the outcome is (ssa form removed for clarity)
short int[<unknown>] * ac.33;
ac.33 = ∾
D.1199 = &(*ac.33)[0];
Later the definition of ac.33 is copy propagated (inside dom) to the
expression and fold_stmt_r tries to simplify *&ac using
maybe_fold_stmt_indirect (type of &ac is short int[<unknown>] *, type of
*&ac is short int[4]). That calls maybe_fold_offset_to_array_ref with
base = ac (type short int[<unknown>][<unknown>]). This however
segfaults, since maybe_fold_offset_to_array_ref works with size of
element of the array, which is NULL in this case.
This patch fixes the problem in maybe_fold_offset_to_array_ref by
failing if the size of the element is NULL. I am not sure whether this
is a correct place, however; the code before dom seems OK to me, but
maybe the real problem is a lack of cast somewhere.
Bootstrapped & regtested on i686 and ppc64.
Zdenek
PR tree-optimization/19333
* tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Fail if the size
of the array element is not known.
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-ccp.c,v
retrieving revision 2.53
diff -c -3 -p -r2.53 tree-ssa-ccp.c
*** tree-ssa-ccp.c 29 Nov 2004 01:15:39 -0000 2.53
--- tree-ssa-ccp.c 10 Jan 2005 00:11:35 -0000
*************** maybe_fold_offset_to_array_ref (tree bas
*** 1340,1351 ****
elt_type = TREE_TYPE (array_type);
if (!lang_hooks.types_compatible_p (orig_type, elt_type))
return NULL_TREE;
!
/* If OFFSET and ELT_OFFSET are zero, we don't care about the size of the
element type (so we can use the alignment if it's not constant).
Otherwise, compute the offset as an index by using a division. If the
division isn't exact, then don't do anything. */
- elt_size = TYPE_SIZE_UNIT (elt_type);
if (integer_zerop (offset))
{
if (TREE_CODE (elt_size) != INTEGER_CST)
--- 1340,1356 ----
elt_type = TREE_TYPE (array_type);
if (!lang_hooks.types_compatible_p (orig_type, elt_type))
return NULL_TREE;
!
! elt_size = TYPE_SIZE_UNIT (elt_type);
! /* If the size of the element is not known, we cannot address the array
! directly. */
! if (!elt_size)
! return NULL_TREE;
!
/* If OFFSET and ELT_OFFSET are zero, we don't care about the size of the
element type (so we can use the alignment if it's not constant).
Otherwise, compute the offset as an index by using a division. If the
division isn't exact, then don't do anything. */
if (integer_zerop (offset))
{
if (TREE_CODE (elt_size) != INTEGER_CST)