From f3d2fbfdb83bcc60d72824daf7a470c0e5398854 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Mon, 22 Jul 2019 13:56:50 +0000 Subject: [PATCH] [Ada] Fix spurious loop warning for function with Out parameter The compiler gives a spurious warning about a possible infinite while loop whose condition contains a call to a function that takes an Out or In/Out parameter and whose actual is a variable that is not modified in the loop, because it still thinks that functions can only have In parameters. 2019-07-22 Eric Botcazou gcc/ada/ * sem_warn.adb (Find_Var): Bail out for a function call with an Out or In/Out parameter. gcc/testsuite/ * gnat.dg/warn23.adb: New testcase. From-SVN: r273673 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/sem_warn.adb | 5 +++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/warn23.adb | 17 +++++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/gnat.dg/warn23.adb diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index ec1b81aeb59..6fc9d1c59cc 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2019-07-22 Eric Botcazou + + * sem_warn.adb (Find_Var): Bail out for a function call with an + Out or In/Out parameter. + 2019-07-22 Nicolas Roche * terminals.c (__gnat_tty_waitpid): Support both blocking and diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb index 16a772af88b..0e1e292bd79 100644 --- a/gcc/ada/sem_warn.adb +++ b/gcc/ada/sem_warn.adb @@ -333,6 +333,11 @@ package body Sem_Warn is elsif Has_Warnings_Off (Entity (Name (N))) then return; + + -- Forget it if the parameter is not In + + elsif Has_Out_Or_In_Out_Parameter (Entity (Name (N))) then + return; end if; -- OK, see if we have one argument diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2fa30eb58dd..c542c626f1d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-22 Eric Botcazou + + * gnat.dg/warn23.adb: New testcase. + 2019-07-22 Javier Miranda * gnat.dg/cpp_constructor2.adb: New testcase. diff --git a/gcc/testsuite/gnat.dg/warn23.adb b/gcc/testsuite/gnat.dg/warn23.adb new file mode 100644 index 00000000000..63d0557c720 --- /dev/null +++ b/gcc/testsuite/gnat.dg/warn23.adb @@ -0,0 +1,17 @@ +-- { dg-do compile } + +procedure Warn23 is + + type Enum_Type is (A, B, C); + + function Poll (E : out Enum_Type) return Boolean + with Convention => Ada, + Import => True; + + E : Enum_Type; + +begin + while Poll (E) loop + null; + end loop; +end; -- 2.11.4.GIT