]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree.c (build_array_type_1): Add SET_CANONICAL parameter and compute TYPE_CANONICAL...
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 9 Dec 2019 16:43:52 +0000 (16:43 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Mon, 9 Dec 2019 16:43:52 +0000 (16:43 +0000)
* tree.c (build_array_type_1): Add SET_CANONICAL parameter and compute
TYPE_CANONICAL from the element type only if it is true.  Remove a few
obsolete lines and adjust recursive call.
(fld_process_array_type): Adjust call to build_array_type_1.
(build_array_type): Likewise.
(build_nonshared_array_type): Likewise.

From-SVN: r279134

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/lto23.adb [new file with mode: 0644]
gcc/tree.c

index ff257ff2449ac0a3f5a7ecd8e8851da4ac055d9f..ceef43bb318682288a72b291922944b1e701e952 100644 (file)
@@ -1,3 +1,12 @@
+2019-12-09  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * tree.c (build_array_type_1): Add SET_CANONICAL parameter and compute
+       TYPE_CANONICAL from the element type only if it is true.  Remove a few
+       obsolete lines and adjust recursive call.
+       (fld_process_array_type): Adjust call to build_array_type_1.
+       (build_array_type): Likewise.
+       (build_nonshared_array_type): Likewise.
+
 2019-12-02  Sandra Loosemore  <sandra@codesourcery.com>
 
        Fix bugs relating to flexibly-sized objects in nios2 backend.
index 6a93f064568c90f25d613c1d1ab4acf1bd80546d..3dbbfc787b6e7b6145f5a8ddd6aa2468e46c6df5 100644 (file)
@@ -1,9 +1,12 @@
+2019-12-09  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/lto23.adb: New test.
+
 2019-12-02  Sandra Loosemore  <sandra@codesourcery.com>
 
        Fix bugs relating to flexibly-sized objects in nios2 backend.
        
        PR target/92499
-
        * gcc.target/nios2/pr92499-1.c: New.
        * gcc.target/nios2/pr92499-2.c: New.
        * gcc.target/nios2/pr92499-3.c: New.
diff --git a/gcc/testsuite/gnat.dg/lto23.adb b/gcc/testsuite/gnat.dg/lto23.adb
new file mode 100644 (file)
index 0000000..88615c9
--- /dev/null
@@ -0,0 +1,20 @@
+-- { dg-do compile }\r
+-- { dg-options "-flto" { target lto } }\r
+\r
+procedure Lto23 (N : Natural) is\r
+\r
+  type Root is tagged null record;\r
+\r
+  type Vec is array (Positive range <>) of Root;\r
+\r
+  type Rec is record\r
+    V : Vec (1 .. N);\r
+  end record;\r
+\r
+  type Arr is array (Positive range <>) of Rec;\r
+\r
+  A : Arr (1 .. 4);\r
+\r
+begin\r
+  null;\r
+end;\r
index 028a2ed3bcad32d856c25cd417c10011849f6f0c..4a20f5a0074920617707b3fe32315cce0cf26beb 100644 (file)
@@ -265,7 +265,7 @@ static void print_type_hash_statistics (void);
 static void print_debug_expr_statistics (void);
 static void print_value_expr_statistics (void);
 
-static tree build_array_type_1 (tree, tree, bool, bool);
+static tree build_array_type_1 (tree, tree, bool, bool, bool);
 
 tree global_trees[TI_MAX];
 tree integer_types[itk_none];
@@ -5251,8 +5251,9 @@ fld_process_array_type (tree t, tree t2, hash_map<tree, tree> *map,
      = map->get_or_insert (t, &existed);
   if (!existed)
     {
-      array = build_array_type_1 (t2, TYPE_DOMAIN (t),
-                                 TYPE_TYPELESS_STORAGE (t), false);
+      array
+       = build_array_type_1 (t2, TYPE_DOMAIN (t), TYPE_TYPELESS_STORAGE (t),
+                             false, false);
       TYPE_CANONICAL (array) = TYPE_CANONICAL (t);
       if (!fld->pset.add (array))
        add_tree_to_fld_list (array, fld);
@@ -8367,11 +8368,12 @@ subrange_type_for_debug_p (const_tree type, tree *lowval, tree *highval)
 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
    and number of elements specified by the range of values of INDEX_TYPE.
    If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type.
-   If SHARED is true, reuse such a type that has already been constructed.  */
+   If SHARED is true, reuse such a type that has already been constructed.
+   If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type.  */
 
 static tree
 build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
-                   bool shared)
+                   bool shared, bool set_canonical)
 {
   tree t;
 
@@ -8388,19 +8390,13 @@ build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
   TYPE_TYPELESS_STORAGE (t) = typeless_storage;
   layout_type (t);
 
-  /* If the element type is incomplete at this point we get marked for
-     structural equality.  Do not record these types in the canonical
-     type hashtable.  */
-  if (TYPE_STRUCTURAL_EQUALITY_P (t))
-    return t;
-
   if (shared)
     {
       hashval_t hash = type_hash_canon_hash (t);
       t = type_hash_canon (hash, t);
     }
 
-  if (TYPE_CANONICAL (t) == t)
+  if (TYPE_CANONICAL (t) == t && set_canonical)
     {
       if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
          || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
@@ -8412,7 +8408,7 @@ build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
          = build_array_type_1 (TYPE_CANONICAL (elt_type),
                                index_type
                                ? TYPE_CANONICAL (index_type) : NULL_TREE,
-                               typeless_storage, shared);
+                               typeless_storage, shared, set_canonical);
     }
 
   return t;
@@ -8423,7 +8419,8 @@ build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
 tree
 build_array_type (tree elt_type, tree index_type, bool typeless_storage)
 {
-  return build_array_type_1 (elt_type, index_type, typeless_storage, true);
+  return
+    build_array_type_1 (elt_type, index_type, typeless_storage, true, true);
 }
 
 /* Wrapper around build_array_type_1 with SHARED set to false.  */
@@ -8431,7 +8428,7 @@ build_array_type (tree elt_type, tree index_type, bool typeless_storage)
 tree
 build_nonshared_array_type (tree elt_type, tree index_type)
 {
-  return build_array_type_1 (elt_type, index_type, false, false);
+  return build_array_type_1 (elt_type, index_type, false, false, true);
 }
 
 /* Return a representation of ELT_TYPE[NELTS], using indices of type