diff mbox series

[Ada] Fix check for implicit allocation of dynamic objects

Message ID 20220111133216.GA748715@adacore.com
State New
Headers show
Series [Ada] Fix check for implicit allocation of dynamic objects | expand

Commit Message

Pierre-Marie de Rodat Jan. 11, 2022, 1:32 p.m. UTC
We check for dynamic objects by recursively examining record components.
We should thus first check if the component is a record type before
checking if it is a `Discriminated_Size` which will be false for all non
array-type components.

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

gcc/ada/

	* sem_ch3.adb (Check_Dynamic_Object): Swap check order.
diff mbox series

Patch

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -3831,6 +3831,9 @@  package body Sem_Ch3 is
                then
                   null;
 
+               elsif Is_Record_Type (Etype (Comp)) then
+                  Check_Dynamic_Object (Etype (Comp));
+
                elsif not Discriminated_Size (Comp)
                  and then Comes_From_Source (Comp)
                then
@@ -3838,8 +3841,6 @@  package body Sem_Ch3 is
                     ("component& of non-static size will violate restriction "
                      & "No_Implicit_Heap_Allocation?", N, Comp);
 
-               elsif Is_Record_Type (Etype (Comp)) then
-                  Check_Dynamic_Object (Etype (Comp));
                end if;
 
                Next_Component (Comp);