[gcc r13-8202] Fix internal error on anonymous access type equality

Eric Botcazou ebotcazou@gcc.gnu.org
Tue Jan 9 09:26:37 GMT 2024


https://gcc.gnu.org/g:13f8c71aebc7df388678c52cffbc11db980d8fa0

commit r13-8202-g13f8c71aebc7df388678c52cffbc11db980d8fa0
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Tue Jan 9 10:21:51 2024 +0100

    Fix internal error on anonymous access type equality
    
    This is a small regression present on the mainline and 13 branch, in the
    form of an internal error in gigi on anonymous access type equality.  We
    now need to also accept them for anonymous access types that point to
    compatible object subtypes in the language sense.
    
    gcc/ada/
            * gcc-interface/utils2.cc (build_binary_op) <EQ_EXPR>: Relax
            assertion for regular pointer types.
    
    gcc/testsuite/
            * gnat.dg/specs/anon4.ads: New test.

Diff:
---
 gcc/ada/gcc-interface/utils2.cc       | 12 ++++--------
 gcc/testsuite/gnat.dg/specs/anon4.ads | 10 ++++++++++
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/gcc/ada/gcc-interface/utils2.cc b/gcc/ada/gcc-interface/utils2.cc
index 6c17675f488..b7a6d97b984 100644
--- a/gcc/ada/gcc-interface/utils2.cc
+++ b/gcc/ada/gcc-interface/utils2.cc
@@ -1137,14 +1137,10 @@ build_binary_op (enum tree_code op_code, tree result_type,
 	      tree left_ref_type = TREE_TYPE (left_base_type);
 	      tree right_ref_type = TREE_TYPE (right_base_type);
 
-	      /* Anonymous access types in Ada 2005 can point to different
-		 members of a tagged hierarchy or different function types.  */
-	      gcc_assert (TYPE_MAIN_VARIANT (left_ref_type)
-			  == TYPE_MAIN_VARIANT (right_ref_type)
-			  || (TYPE_ALIGN_OK (left_ref_type)
-			      && TYPE_ALIGN_OK (right_ref_type))
-			  || (TREE_CODE (left_ref_type) == FUNCTION_TYPE
-			      && TREE_CODE (right_ref_type) == FUNCTION_TYPE));
+	      /* Anonymous access types in Ada 2005 may point to compatible
+		 object subtypes or function types in the language sense.  */
+	      gcc_assert (FUNCTION_POINTER_TYPE_P (left_ref_type)
+			  == FUNCTION_POINTER_TYPE_P (right_ref_type));
 	      best_type = left_base_type;
 	    }
 
diff --git a/gcc/testsuite/gnat.dg/specs/anon4.ads b/gcc/testsuite/gnat.dg/specs/anon4.ads
new file mode 100644
index 00000000000..493cf6093f2
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/anon4.ads
@@ -0,0 +1,10 @@
+-- { dg-do compile }
+
+package Anon4 is
+   subtype I is Integer;
+   A : access I;
+
+   Acc : access Integer;
+
+   function F return Boolean is (A = Acc);
+end Anon4;


More information about the Gcc-cvs mailing list