https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85244

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot 
gnu.org

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #2)
> That said, it is get_ref_base_and_extent that for the variable index returns
> offset 96 bits and size == maxsize == 32, identical to the [0] case.
> 
> Perhaps we shouldn't trust:
> 638         /* If maxsize is unknown adjust it according to the size of the
> 639            base decl.  */
> 640         else if (!known_size_p (maxsize)
> 641                  && DECL_SIZE (exp)
> 642                  && poly_int_tree_p (DECL_SIZE (exp)))
> 643           maxsize = wi::to_poly_offset (DECL_SIZE (exp)) - bit_offset;
> if exp is DECL_EXTERNAL and the struct/union ends with flexible array member
> (or flexible array member-like array)?  Perhaps we'd need to remember from
> the case where we set seen_variable_array_ref to true if it was
> array_at_end_of_struct_p and if yes and DECL_EXTERNAL, ignore this?
> 
> Richard?

Hmm, what about

extern int a[];

or

extern int a[1];

?

so should we just treat structs with trailing flexible arrays in this way
(flexible as in [] or [0]?).

I think if we fix another case in get_ref_base_and_extent like with

Index: gcc/tree-dfa.c
===================================================================
--- gcc/tree-dfa.c      (revision 259082)
+++ gcc/tree-dfa.c      (working copy)
@@ -464,6 +464,11 @@ get_ref_base_and_extent (tree exp, poly_
                            maxsize += tem;
                          }
                      }
+                   /* An component ref with an adjacent field up in the
+                      structure hierarchy constrains the size of any variable
+                      array ref lower in the access hierarchy.  */
+                   if (next)
+                     seen_variable_array_ref = false;
                  }
              }
            else

then we can just do

@@ -622,7 +627,9 @@ get_ref_base_and_extent (tree exp, poly_

   if (DECL_P (exp))
     {
-      if (flag_unconstrained_commons && VAR_P (exp) && DECL_COMMON (exp))
+      if (VAR_P (exp)
+         && ((flag_unconstrained_commons && DECL_COMMON (exp))
+             || (DECL_EXTERNAL (exp) && seen_variable_array_ref)))
        {
          tree sz_tree = TYPE_SIZE (TREE_TYPE (exp));
          /* If size is unknown, or we have read to the end, assume there

and that way also handle plain arrays (very) conservatively.

Reply via email to