public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-4916] Fix internal error on chain of constants with -gnatc
@ 2020-11-11 13:40 Eric Botcazou
  0 siblings, 0 replies; only message in thread
From: Eric Botcazou @ 2020-11-11 13:40 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1c91516aeb8362696786e17f83d8366de9a31f81

commit r11-4916-g1c91516aeb8362696786e17f83d8366de9a31f81
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Wed Nov 11 14:39:32 2020 +0100

    Fix internal error on chain of constants with -gnatc
    
    gcc/ada/ChangeLog:
            * gcc-interface/decl.c (gnat_to_gnu_entity) <E_Constant>: In case
            the constant is not being defined, get the expression in type
            annotation mode only if its type is elementary.

Diff:
---
 gcc/ada/gcc-interface/decl.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c
index 4e6dc84beea..baae58a025f 100644
--- a/gcc/ada/gcc-interface/decl.c
+++ b/gcc/ada/gcc-interface/decl.c
@@ -667,21 +667,24 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
 
       /* If we have a constant that we are not defining, get the expression it
 	 was defined to represent.  This is necessary to avoid generating dumb
-	 elaboration code in simple cases, but we may throw it away later if it
+	 elaboration code in simple cases, and we may throw it away later if it
 	 is not a constant.  But do not do it for dispatch tables because they
 	 are only referenced indirectly and we need to have a consistent view
 	 of the exported and of the imported declarations of the tables from
 	 external units for them to be properly merged in LTO mode.  Moreover
-	 simply do not retrieve the expression it if it is an allocator since
+	 simply do not retrieve the expression if it is an allocator because
 	 the designated type might still be dummy at this point.  Note that we
 	 invoke gnat_to_gnu_external and not gnat_to_gnu because the expression
 	 may contain N_Expression_With_Actions nodes and thus declarations of
-	 objects from other units that we need to discard.  */
+	 objects from other units that we need to discard.  Note also that we
+	 need to do it even if we are only annotating types, so as to be able
+	 to validate representation clauses using constants.  */
       if (!definition
 	  && !No_Initialization (gnat_decl)
 	  && !Is_Dispatch_Table_Entity (gnat_entity)
 	  && Present (gnat_temp = Expression (gnat_decl))
-	  && Nkind (gnat_temp) != N_Allocator)
+	  && Nkind (gnat_temp) != N_Allocator
+	  && (Is_Elementary_Type (Etype (gnat_entity)) || !type_annotate_only))
 	gnu_expr = gnat_to_gnu_external (gnat_temp);
 
       /* ... fall through ... */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-11 13:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-11 13:40 [gcc r11-4916] Fix internal error on chain of constants with -gnatc Eric Botcazou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).