Patchwork Fix gnat.dg/aliasing2.adb regression

login
register
mail settings
Submitter Eric Botcazou
Date Dec. 2, 2010, 11:25 a.m.
Message ID <201012021225.35279.ebotcazou@adacore.com>
Download mbox | patch
Permalink /patch/73954/
State New
Headers show

Comments

Eric Botcazou - Dec. 2, 2010, 11:25 a.m.
> So your original patch is ok.

I missed that this original patch also breaks C++, because TYPE_MIN/MAX_VALUE 
for C++ types can contain C++-specific tree nodes that CONTAINS_PLACEHOLDER_P 
isn't prepared to handle.  So we would need to teach the latter about them 
and this would slow down both the C++ and the Ada compilers.

I'm proposing the following trick instead: do not fiddle with TYPE_CANONICAL 
if a non-shared type is requested.  The Ada compiler doesn't want these types 
to be merged, so having different TYPE_CANONICALs is just fine I think.

Only LTO-bootstrapped (for C/Ada) on x86_64-suse-linux for now, I'll do a full 
regular bootstrap if accepted.  OK for mainline?


2010-12-02  Eric Botcazou  <ebotcazou@adacore.com>

	* tree.c (build_range_type_1): Do not SET_TYPE_STRUCTURAL_EQUALITY
	for a non-shared type.
Richard Guenther - Dec. 2, 2010, 1:36 p.m.
On Thu, Dec 2, 2010 at 12:25 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
>> So your original patch is ok.
>
> I missed that this original patch also breaks C++, because TYPE_MIN/MAX_VALUE
> for C++ types can contain C++-specific tree nodes that CONTAINS_PLACEHOLDER_P
> isn't prepared to handle.  So we would need to teach the latter about them
> and this would slow down both the C++ and the Ada compilers.
>
> I'm proposing the following trick instead: do not fiddle with TYPE_CANONICAL
> if a non-shared type is requested.  The Ada compiler doesn't want these types
> to be merged, so having different TYPE_CANONICALs is just fine I think.
>
> Only LTO-bootstrapped (for C/Ada) on x86_64-suse-linux for now, I'll do a full
> regular bootstrap if accepted.  OK for mainline?

Yes.

Thanks,
Richard.

>
> 2010-12-02  Eric Botcazou  <ebotcazou@adacore.com>
>
>        * tree.c (build_range_type_1): Do not SET_TYPE_STRUCTURAL_EQUALITY
>        for a non-shared type.
>
>
> --
> Eric Botcazou
>

Patch

Index: tree.c
===================================================================
--- tree.c	(revision 167352)
+++ tree.c	(working copy)
@@ -7096,6 +7096,7 @@  static tree
 build_range_type_1 (tree type, tree lowval, tree highval, bool shared)
 {
   tree itype = make_node (INTEGER_TYPE);
+  hashval_t hashcode = 0;
 
   TREE_TYPE (itype) = type;
 
@@ -7109,6 +7110,9 @@  build_range_type_1 (tree type, tree lowv
   TYPE_ALIGN (itype) = TYPE_ALIGN (type);
   TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
 
+  if (!shared)
+    return itype;
+
   if ((TYPE_MIN_VALUE (itype)
        && TREE_CODE (TYPE_MIN_VALUE (itype)) != INTEGER_CST)
       || (TYPE_MAX_VALUE (itype)
@@ -7120,13 +7124,10 @@  build_range_type_1 (tree type, tree lowv
       return itype;
     }
 
-  if (shared)
-    {
-      hashval_t hash = iterative_hash_expr (TYPE_MIN_VALUE (itype), 0);
-      hash = iterative_hash_expr (TYPE_MAX_VALUE (itype), hash);
-      hash = iterative_hash_hashval_t (TYPE_HASH (type), hash);
-      itype = type_hash_canon (hash, itype);
-    }
+  hashcode = iterative_hash_expr (TYPE_MIN_VALUE (itype), hashcode);
+  hashcode = iterative_hash_expr (TYPE_MAX_VALUE (itype), hashcode);
+  hashcode = iterative_hash_hashval_t (TYPE_HASH (type), hashcode);
+  itype = type_hash_canon (hashcode, itype);
 
   return itype;
 }