]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Crash freezing declaration that will raise constraint error
authorJavier Miranda <miranda@adacore.com>
Sun, 20 Mar 2022 11:36:25 +0000 (11:36 +0000)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 17 May 2022 08:25:42 +0000 (08:25 +0000)
When the compiler is built with assertions enabled and processes the
following declarations:

   type Vector_Boolean_Array is array (1 .. 10) of Boolean;
   O2 : constant Vector_Boolean_Array := [for J in 2 => True];

The expression is rewritten by the frontend with an N_Raise_CE node,
which leads to an assertion error at the freezing point of the object
declaration.

gcc/ada/

* freeze.adb (Freeze_Entity): Protect the call to
Declaration_Node against entities of expressions replaced by the
frontend with an N_Raise_CE node.

gcc/ada/freeze.adb

index ca0ffe39c25284a829f6f36c7a7b5f87d28d9128..381468aa687a7080d52191e91e2d84ebbe313849 100644 (file)
@@ -6582,9 +6582,13 @@ package body Freeze is
                end if;
             end if;
 
-            --  Special processing for objects created by object declaration
+            --  Special processing for objects created by object declaration;
+            --  we protect the call to Declaration_Node against entities of
+            --  expressions replaced by the frontend with an N_Raise_CE node.
 
-            if Nkind (Declaration_Node (E)) = N_Object_Declaration then
+            if Ekind (E) in E_Constant | E_Variable
+              and then Nkind (Declaration_Node (E)) = N_Object_Declaration
+            then
                Freeze_Object_Declaration (E);
             end if;