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

--- Comment #3 from Martin Jambor <jamborm at gcc dot gnu.org> ---
I need to leave today, but with the following patch, SRA builds the
memory accesses (hopefully) correctly... and we then fail the verifier
after forwprop with verification error "invalid offset operand in
'mem_ref'."  (So I guess the mem_ref constructed by SRA should still be
checked too.)

diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc
index f951a38442a..d02d59328c7 100644
--- a/gcc/tree-sra.cc
+++ b/gcc/tree-sra.cc
@@ -2028,8 +2028,13 @@ build_ref_for_model (location_t loc, tree base,
HOST_WIDE_INT offset,
                                gsi, insert_after, force_ref_all);
       /* The flag will be set on the record type.  */
       REF_REVERSE_STORAGE_ORDER (t) = 0;
-      return fold_build3_loc (loc, COMPONENT_REF, TREE_TYPE (fld), t, fld,
-                             NULL_TREE);
+      tree res_type = TREE_TYPE (fld);
+      addr_space_t exp_as = TYPE_ADDR_SPACE (TREE_TYPE (t));
+      if (TYPE_ADDR_SPACE (TREE_TYPE (fld)) != exp_as)
+       res_type = build_qualified_type (res_type,
+                                        TYPE_QUALS (res_type)
+                                        | ENCODE_QUAL_ADDR_SPACE (exp_as));
+      return fold_build3_loc (loc, COMPONENT_REF, res_type, t, fld,
NULL_TREE);
     }
   else
     {

Reply via email to