[COMMITTED] ada: Fix wrong result for membership test of null in null-excluding access type

Message ID 20230529082929.2410336-1-poulhies@adacore.com
State Committed
Commit 9098ae6cde6f6ec9818c180f28a7a7f7ebc6699d
Headers
Series [COMMITTED] ada: Fix wrong result for membership test of null in null-excluding access type |

Commit Message

Marc Poulhiès May 29, 2023, 8:29 a.m. UTC
  From: Eric Botcazou <ebotcazou@adacore.com>

The result must be False as per the RM 4.5.2 (30.2/4) clause.

gcc/ada/

	* exp_ch4.adb (Expand_N_In): Deal specifically with a null operand.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch4.adb | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Patch

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 3f864f2675c..537d7a6311c 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -6972,11 +6972,13 @@  package body Exp_Ch4 is
 
                --  If the null exclusion checks are not compatible, need to
                --  perform further checks. In other words, we cannot have
-               --  Ltyp including null and Typ excluding null. All other cases
-               --  are OK.
+               --  Ltyp including null or Lop being null, and Typ excluding
+               --  null. All other cases are OK.
 
                Check_Null_Exclusion :=
-                 Can_Never_Be_Null (Typ) and then not Can_Never_Be_Null (Ltyp);
+                 Can_Never_Be_Null (Typ)
+                   and then (not Can_Never_Be_Null (Ltyp)
+                              or else Nkind (Lop) = N_Null);
                Typ := Designated_Type (Typ);
             end if;