If -gnatE is specified, then in some cases a call to a subprogram
includes a check that the body of the subprogram has been elaborated. No
such check is needed in the case of an expression function that is not a
completion; the function has no prior declaration. However, in some
cases the compiler was incorrectly treating an expression function
declared in the visible part of a package as though it had a function
body declared within the package body. Not only could this result in an
unnecessary check, but that check could fail and raise Program_Error.
The ABE check is now correctly omitted.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_elab.adb (Is_Safe_Call): Return True in the case of a
(possibly rewritten) call to an expression function.
diff --git a/gcc/ada/sem_elab.adb b/gcc/ada/sem_elab.adb
--- a/gcc/ada/sem_elab.adb
+++ b/gcc/ada/sem_elab.adb
@@ -13621,6 +13621,13 @@ package body Sem_Elab is
then
return True;
+ -- A call to an expression function that is not a completion cannot
+ -- cause an ABE because it has no prior declaration; this remains
+ -- true even if the FE transforms the callee into something else.
+
+ elsif Nkind (Original_Node (Spec_Decl)) = N_Expression_Function then
+ return True;
+
-- Subprogram bodies which wrap attribute references used as actuals
-- in instantiations are always ABE-safe. These bodies are artifacts
-- of expansion.