]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix wrong finalization for double subtype of bounded vector
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 10 May 2023 16:00:36 +0000 (18:00 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 15 Jun 2023 07:59:38 +0000 (09:59 +0200)
The special handling of temporaries created for return values and subject
to a renaming needs to be restricted to the top level, where it is needed
to prevent dangling references to the frame of the elaboration routine from
being created, because, at a lower level, the front-end may create implicit
renamings of objects as these temporaries, so a copy is not allowed.

gcc/ada/

* gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Restrict
the special handling of temporaries created for return values and
subject to a renaming to the top level.

gcc/ada/gcc-interface/decl.cc

index e5e04ddad933e01c986812c499fd0fa6c67e2543..b2b77787bc04cd52fc1054de4d072d1ce03d8118 100644 (file)
@@ -1076,9 +1076,13 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
                || EXPRESSION_CLASS_P (inner)
                /* We need to detect the case where a temporary is created to
                   hold the return value, since we cannot safely rename it at
-                  top level as it lives only in the elaboration routine.  */
+                  top level because it lives only in the elaboration routine.
+                  But, at a lower level, an object initialized by a function
+                  call may be (implicitly) renamed as this temporary by the
+                  front-end and, in this case, we cannot make a copy.  */
                || (VAR_P (inner)
-                   && DECL_RETURN_VALUE_P (inner))
+                   && DECL_RETURN_VALUE_P (inner)
+                   && global_bindings_p ())
                /* We also need to detect the case where the front-end creates
                   a dangling 'reference to a function call at top level and
                   substitutes it in the renaming, for example:
@@ -1092,12 +1096,14 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
                     q__b : boolean renames q__R1s.all.e (1);
 
                   We cannot safely rename the rewritten expression since the
-                  underlying object lives only in the elaboration routine.  */
+                  underlying object lives only in the elaboration routine but,
+                  as above, this cannot be done at a lower level.  */
                || (INDIRECT_REF_P (inner)
                    && (inner
                        = remove_conversions (TREE_OPERAND (inner, 0), true))
                    && VAR_P (inner)
-                   && DECL_RETURN_VALUE_P (inner)))
+                   && DECL_RETURN_VALUE_P (inner)
+                   && global_bindings_p ()))
              ;
 
            /* Otherwise, this is an lvalue being renamed, so it needs to be