https://gcc.gnu.org/g:b2029c82ff9174b59f2779641022760bf27ae0a0

commit r17-1971-gb2029c82ff9174b59f2779641022760bf27ae0a0
Author: Eric Botcazou <[email protected]>
Date:   Mon Jun 15 18:23:38 2026 +0200

    ada: Fix internal error on subtraction in array bound with -gnatc
    
    The problem is that the expansion of intrinsic operators is not performed
    in semantic-only (-gnatc) mode and thus one of them is handed down to gigi
    unexpanded and trips on an assertion about type consistency.  The simplest
    fix is to disable the translation for them at the beginning of gnat_to_gnu.
    
    gcc/ada/ChangeLog:
    
            * gcc-interface/trans.cc (gnat_to_gnu): Return a NULL_EXPR for the
            use of an intrinsic operator and exclude more cases explicitly.

Diff:
---
 gcc/ada/gcc-interface/trans.cc | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index 7df32d67ea9a..995da1942e7a 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -6535,12 +6535,15 @@ gnat_to_gnu (Node_Id gnat_node)
   if (type_annotate_only && statement_node_p (gnat_node))
     return alloc_stmt_list ();
 
-  /* If we are only annotating types and this node is a subexpression, return
-     a NULL_EXPR, but filter out nodes appearing in the expressions attached
-     to packed array implementation types.  */
+  /* If we are only annotating types and this node is a dynamic expression,
+     return a NULL_EXPR, but filter out nodes appearing in the expressions
+     attached to packed array implementation types.  */
   if (type_annotate_only
       && IN (kind, N_Subexpr)
-      && !(((IN (kind, N_Op) && kind != N_Op_Expon)
+      && kind != N_Expanded_Name
+      && !IN (kind, N_Direct_Name)
+      && !IN (kind, N_Numeric_Or_String_Literal)
+      && !(((IN (kind, N_Op) && !Is_Intrinsic_Subprogram (Entity (gnat_node)))
            || kind == N_Type_Conversion)
           && Is_Integer_Type (Etype (gnat_node)))
       && !(kind == N_Attribute_Reference
@@ -6548,8 +6551,6 @@ gnat_to_gnu (Node_Id gnat_node)
               || Get_Attribute_Id (Attribute_Name (gnat_node)) == Attr_Size)
           && Is_Constrained (Etype (Prefix (gnat_node)))
           && !Is_Constr_Subt_For_U_Nominal (Etype (Prefix (gnat_node))))
-      && kind != N_Expanded_Name
-      && kind != N_Identifier
       && !Compile_Time_Known_Value (gnat_node))
     return build1 (NULL_EXPR, get_unpadded_type (Etype (gnat_node)),
                   build_call_raise (CE_Range_Check_Failed, gnat_node,

Reply via email to