From f9e5da46f7708d7eaf5a080e51dd6d5553bdf37a Mon Sep 17 00:00:00 2001 From: Hristian Kirtchev Date: Thu, 11 Jul 2019 08:02:07 +0000 Subject: [PATCH] [Ada] Infinite loop on illegal declaration This patch updates predicate Null_Status to prevent an infinite recursion when the argument is an illegal object declaration of an access type. 2019-07-11 Hristian Kirtchev gcc/ada/ * sem_util.adb (Null_Status): Assume that an erroneous construct has an undefined null status. gcc/testsuite/ * gnat.dg/self_ref1.adb: New testcase. From-SVN: r273389 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/sem_util.adb | 8 +++++++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/self_ref1.adb | 11 +++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gnat.dg/self_ref1.adb diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index a17ab7e25fd..0a1bd245545 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2019-07-11 Hristian Kirtchev + + * sem_util.adb (Null_Status): Assume that an erroneous construct + has an undefined null status. + 2019-07-11 Hristian Kirtchev * checks.adb, exp_ch6.adb, gnat1drv.adb, sem_aux.adb, diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 147c281c797..04d981a6a86 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -22367,9 +22367,15 @@ package body Sem_Util is -- Start of processing for Null_Status begin + -- Prevent cascaded errors or infinite loops when trying to determine + -- the null status of an erroneous construct. + + if Error_Posted (N) then + return Unknown; + -- An allocator always creates a non-null value - if Nkind (N) = N_Allocator then + elsif Nkind (N) = N_Allocator then return Is_Non_Null; -- Taking the 'Access of something yields a non-null value diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bbfada284f9..f0d066db984 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-11 Hristian Kirtchev + + * gnat.dg/self_ref1.adb: New testcase. + 2019-07-11 Ed Schonberg * gnat.dg/predicate11.adb: New testcase. diff --git a/gcc/testsuite/gnat.dg/self_ref1.adb b/gcc/testsuite/gnat.dg/self_ref1.adb new file mode 100644 index 00000000000..a65dbd912e8 --- /dev/null +++ b/gcc/testsuite/gnat.dg/self_ref1.adb @@ -0,0 +1,11 @@ +-- { dg-do compile } + +procedure Self_Ref1 is + type Integer_Ptr is access all Integer; + Ptr : constant Integer_Ptr := Integer_Ptr (Ptr); -- { dg-error "object \"Ptr\" cannot be used before end of its declaration" } + +begin + if Ptr /= null then + null; + end if; +end Self_Ref1; -- 2.30.2