A call to an exprewion function generated for a precondition that
applies to a null procedure leaves the freeze node for the expression
function in the wrong context. As a result the body of the function is
not properly compiled and the corresponding symbol is markea as
undefined, leading to a subsequent link error.

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

2020-06-15  Ed Schonberg  <schonb...@adacore.com>

gcc/ada/

        * freeze.adb (Freeze_Expression): When traversing the tree
        looking for the proper insertion point for the freeze node of an
        entity that is declared in an outer scope, set the candidate
        subprogram body node properly.  Previous code has an off-by-one
        error.
--- gcc/ada/freeze.adb
+++ gcc/ada/freeze.adb
@@ -7379,10 +7379,16 @@ package body Freeze is
                return;
             end if;
 
-            exit when
-              Nkind (Parent_P) = N_Subprogram_Body
+            --  If the parent is a subprogram body, the candidate insertion
+            --  point is just ahead of it.
+
+            if  Nkind (Parent_P) = N_Subprogram_Body
                 and then Unique_Defining_Entity (Parent_P) =
-                           Freeze_Outside_Subp;
+                           Freeze_Outside_Subp
+            then
+               P := Parent_P;
+               exit;
+            end if;
 
             P := Parent_P;
          end loop;

Reply via email to