[Ada] Spurious accessibility error on call in return statement

Message ID 20210503092945.GA77491@adacore.com
State New
Headers show
  • [Ada] Spurious accessibility error on call in return statement
Related show

Commit Message

Pierre-Marie de Rodat May 3, 2021, 9:29 a.m.
This patch fixes an issue in the compiler whereby a spurious
accessibility error regarding actuals for explicitly aliased formals in
a function call within a return statement gets triggered during
compilation when the return type of the function call in question has
implicit dereference specified.

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


	* sem_util.adb (In_Return_Value): Modified to detect when
	implicit dereference is specified on the return type of a
	function call within the expression being checked.


diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -14329,6 +14329,17 @@  package body Sem_Util is
             when N_Function_Call =>
                if not In_Function_Call then
                   In_Function_Call := True;
+                  --  When the function return type has implicit dereference
+                  --  specified we know it cannot directly contribute to the
+                  --  return value.
+                  if Present (Etype (Par))
+                    and then Has_Implicit_Dereference
+                               (Get_Full_View (Etype (Par)))
+                  then
+                     return False;
+                  end if;
                   return False;
                end if;