From 8c029ee8cf5d14e8c0dc0a74d9a5278c3aee49e9 Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Mon, 22 Jul 2019 13:57:51 +0000 Subject: [PATCH] [Ada] Misleading warning on variable not assigned This patch removes a warning on a referenced entity with no explicit prior assignment, if the type of the entity has Preelaborable_Initialixation, such as Exception_Occurrence. 2019-07-22 Ed Schonberg gcc/ada/ * sem_warn.adb (Check_References): Do not emit s warning on a referenced entity with no explicit assignment if the type of the entity has Preelaborable_Initialixation, such as Exception_Occurrence. gcc/testsuite/ * gnat.dg/warn25.adb: New testcase. From-SVN: r273686 --- gcc/ada/ChangeLog | 7 +++++++ gcc/ada/sem_warn.adb | 8 ++++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/warn25.adb | 23 +++++++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/warn25.adb diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index ac990bee17c..12ea5adb30e 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,10 @@ +2019-07-22 Ed Schonberg + + * sem_warn.adb (Check_References): Do not emit s warning on a + referenced entity with no explicit assignment if the type of the + entity has Preelaborable_Initialixation, such as + Exception_Occurrence. + 2019-07-22 Javier Miranda * exp_ch4.adb (Size_In_Storage_Elements): Improve the expansion diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb index 0e1e292bd79..ab85162c786 100644 --- a/gcc/ada/sem_warn.adb +++ b/gcc/ada/sem_warn.adb @@ -1413,9 +1413,13 @@ package body Sem_Warn is goto Continue; end if; - -- Check for unset reference + -- Check for unset reference. If type of object has + -- preelaborable initialization, warning is misleading. - if Warn_On_No_Value_Assigned and then Present (UR) then + if Warn_On_No_Value_Assigned + and then Present (UR) + and then not Known_To_Have_Preelab_Init (Etype (E1)) + then -- For other than access type, go back to original node to -- deal with case where original unset reference has been diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 079f6e9d6f3..c9679c756c8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-22 Ed Schonberg + + * gnat.dg/warn25.adb: New testcase. + 2019-07-22 Yannick Moy * gnat.dg/warn24.adb: New testcase. diff --git a/gcc/testsuite/gnat.dg/warn25.adb b/gcc/testsuite/gnat.dg/warn25.adb new file mode 100644 index 00000000000..e7848701818 --- /dev/null +++ b/gcc/testsuite/gnat.dg/warn25.adb @@ -0,0 +1,23 @@ +-- { dg-do compile } +-- { dg-options "-gnatwa" } + +with Ada.Exceptions; +procedure Warn25 is + CASA_Unavailable : Ada.Exceptions.Exception_Occurrence; + use Ada.Exceptions; +begin + while True loop + declare + begin + if Exception_Identity (CASA_Unavailable) = Null_Id then + exit; + end if; + exception + when E : others => + Save_Occurrence (Source => E, Target => CASA_Unavailable); + end; + end loop; + if Exception_Identity (CASA_Unavailable) /= Null_Id then + Reraise_Occurrence (CASA_Unavailable); + end if; +end; -- 2.30.2