From 92e047e7751db6da3f343f14e25ce257812f6310 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Tue, 12 Jun 2018 10:09:20 +0000 Subject: [PATCH] Backpor from mainline 2018-06-02 Eric Botcazou * gcc-interface/decl.c (gnat_to_gnu_entity) : If this is not a definition, retrieve the expression only if it's a compile-time known value if we are just annotating types. * gcc-interface/utils.c (convert): Do not try to upcast properly for a conversion between tagged types in type_annotate_only mode. From-SVN: r261482 --- gcc/ada/ChangeLog | 12 ++++++++++++ gcc/ada/gcc-interface/decl.c | 16 ++++++++-------- gcc/ada/gcc-interface/utils.c | 7 +++++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 9c5d7dc2a30d..aed04eabb957 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,15 @@ +2018-06-12 Eric Botcazou + + Backpor from mainline + 2018-06-02 Eric Botcazou + + * gcc-interface/decl.c (gnat_to_gnu_entity) : If this is + not a definition, retrieve the expression only if it's a compile-time + known value if we are just annotating types. + + * gcc-interface/utils.c (convert): Do not try to upcast properly for a + conversion between tagged types in type_annotate_only mode. + 2018-06-12 Eric Botcazou Backport from mainline diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index 4ed49281b560..df27f209fb1b 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -593,16 +593,16 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) 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 is not a constant. But do not retrieve it if it is an allocator since - the designated type might still be dummy at this point. */ + 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. */ if (!definition && !No_Initialization (Declaration_Node (gnat_entity)) - && Present (Expression (Declaration_Node (gnat_entity))) - && Nkind (Expression (Declaration_Node (gnat_entity))) - != N_Allocator) - /* The expression may contain N_Expression_With_Actions nodes and - thus object declarations from other units. Discard them. */ - gnu_expr - = gnat_to_gnu_external (Expression (Declaration_Node (gnat_entity))); + && Present (gnat_temp = Expression (Declaration_Node (gnat_entity))) + && Nkind (gnat_temp) != N_Allocator + && (!type_annotate_only || Compile_Time_Known_Value (gnat_temp))) + gnu_expr = gnat_to_gnu_external (gnat_temp); /* ... fall through ... */ diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index f362946e63a6..2e10950f254b 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -4543,9 +4543,12 @@ convert (tree type, tree expr) etype))) return build1 (VIEW_CONVERT_EXPR, type, expr); - /* If we are converting between tagged types, try to upcast properly. */ + /* If we are converting between tagged types, try to upcast properly. + But don't do it if we are just annotating types since tagged types + aren't fully laid out in this mode. */ else if (ecode == RECORD_TYPE && code == RECORD_TYPE - && TYPE_ALIGN_OK (etype) && TYPE_ALIGN_OK (type)) + && TYPE_ALIGN_OK (etype) && TYPE_ALIGN_OK (type) + && !type_annotate_only) { tree child_etype = etype; do { -- 2.47.2