diff options
author | Ed Schonberg <schonberg@adacore.com> | 2018-05-23 10:22:35 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-05-23 10:22:35 +0000 |
commit | a0fa549732f1a6ab26c7b904472a8f7d241dae39 (patch) | |
tree | 42ea2601ade6aa0de1df48cb406eef64797222d1 | |
parent | a0f3668cdee0255ce993f4309448329ca40bfe3c (diff) | |
download | gcc-a0fa549732f1a6ab26c7b904472a8f7d241dae39.zip gcc-a0fa549732f1a6ab26c7b904472a8f7d241dae39.tar.gz gcc-a0fa549732f1a6ab26c7b904472a8f7d241dae39.tar.bz2 |
[Ada] Crash on predicate involving qualified expression in instance
This patch inhibits the generation of freeze nodes when pre-analyzing the
domain of iteration of an Ada2012 loop that appears as a quantified
expression in a predicate for an array type. This prevents a back-end
abort on an invisible freeze node that would otherwise appear in an
unexpanded code sequence.
The following must compile quietly:
----
with Id_Manager;
package My_Id_Manager is new Id_Manager (Max_Id_Type => 100_000,
Max_Key_Count => 100);
----
generic
Max_Id_Type : Positive;
Max_Key_Count : Positive;
package Id_Manager is
type Unique_Id_Type is new Integer range 0 .. Max_Id_Type;
Undefined_Id : constant Unique_Id_Type := 0;
type Key_Count is new Integer range 0 .. Max_Key_Count;
subtype Key_Index is Key_Count range 1 .. Key_Count'Last;
type Key_Array is array (Key_Index range <>) of Unique_Id_Type
with Predicate => Key_Array'First = 1;
type Id_Manager_State (Capacity : Key_Count) is private;
procedure Display_Objects (TheObject : Id_Manager_State);
private
type Id_Manager_State (Capacity : Key_Count) is record
Id_Key : Key_Array (1 .. Capacity) := (others => Undefined_Id);
Key_Size : Key_Count := 0;
end record;
end Id_Manager;
----
package body Id_Manager is
procedure Display_Objects (TheObject : Id_Manager_State) is
begin
for Item of TheObject.Id_Key loop
null;
end loop;
end Display_Objects;
end Id_Manager;
2018-05-23 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* sem_ch5.adb (Preanalyze_Range): The pre-analysis of the domain of
iteration of an Ada2012 loop is performed to determine the type of the
domain, but full analysis is performed once the loop is rewritten as a
while-loop during expansion. The pre-analysis suppresses expansion; it
must also suppress the generation of freeze nodes, which may otherwise
appear in the wrong scope before rewritting.
From-SVN: r260582
-rw-r--r-- | gcc/ada/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/ada/sem_ch5.adb | 11 |
2 files changed, 20 insertions, 0 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 31dca9e..b99ca1a 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,12 @@ +2018-05-23 Ed Schonberg <schonberg@adacore.com> + + * sem_ch5.adb (Preanalyze_Range): The pre-analysis of the domain of + iteration of an Ada2012 loop is performed to determine the type of the + domain, but full analysis is performed once the loop is rewritten as a + while-loop during expansion. The pre-analysis suppresses expansion; it + must also suppress the generation of freeze nodes, which may otherwise + appear in the wrong scope before rewritting. + 2018-05-23 Hristian Kirtchev <kirtchev@adacore.com> * sem_elab.adb: Update the section on suppressing elaboration warnings. diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb index 2a3b1ff..2a1f222 100644 --- a/gcc/ada/sem_ch5.adb +++ b/gcc/ada/sem_ch5.adb @@ -4076,6 +4076,17 @@ package body Sem_Ch5 is Full_Analysis := False; Expander_Mode_Save_And_Set (False); + -- In addition to the above we must ecplicity suppress the + -- generation of freeze nodes which might otherwise be generated + -- during resolution of the range (e.g. if given by an attribute + -- that will freeze its prefix). + + Set_Must_Not_Freeze (R_Copy); + + if Nkind (R_Copy) = N_Attribute_Reference then + Set_Must_Not_Freeze (Prefix (R_Copy)); + end if; + Analyze (R_Copy); if Nkind (R_Copy) in N_Subexpr and then Is_Overloaded (R_Copy) then |