diff mbox series

[Ada] Work around problematic interaction with public symbol generation

Message ID 20200617081610.GA55276@adacore.com
State New
Headers show
Series [Ada] Work around problematic interaction with public symbol generation | expand

Commit Message

Pierre-Marie de Rodat June 17, 2020, 8:16 a.m. UTC
The previous change made to fold 'First and 'Last for constrained array
types can go awry in the presence of layers of package instantiations
because the referenced entities need to have a stable name if they are
public and providing such a guarantee is not trivial in some cases.

Therefore this change restricts the folding to the non-public case,
which is the main use case, since the initial change was primarily
intended for local subtypes created for slices.

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-17  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* exp_attr.adb (Expand_N_Attribute_Reference) <Attribute_First>:
	Do not replace the bound for an array type if it is public.
diff mbox series

Patch

--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -3424,7 +3424,14 @@  package body Exp_Attr is
          --  reference. Note that this must be in keeping with what is done
          --  for scalar types in order for range checks to be elided in loops.
 
-         elsif Is_Array_Type (Ptyp) and then Is_Constrained (Ptyp) then
+         --  However, avoid doing it if the array type is public because, in
+         --  this case, we effectively rely on the back end to create public
+         --  symbols with consistent names across units for the array bounds.
+
+         elsif Is_Array_Type (Ptyp)
+           and then Is_Constrained (Ptyp)
+           and then not Is_Public (Ptyp)
+         then
             declare
                Bnd : Node_Id;