[COMMITTED] ada: Fix Unchecked_Conversion in edge case

Message ID 20230515094145.1407307-1-poulhies@adacore.com
State Accepted
Headers
Series [COMMITTED] ada: Fix Unchecked_Conversion in edge case |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Marc Poulhiès May 15, 2023, 9:41 a.m. UTC
  From: Ronan Desplanques <desplanques@adacore.com>

Before this patch, Set_Can_Use_Internal_Rep was called on access
to subprogram subtypes when instantiating Unchecked_Conversion
from System.Address to an access to subprogram subtype (or the
reverse). This was incorrect and caused an assertion failure.

This patch fixes that by modifying the Can_Use_Internal_Rep
attribute of the base type of the subtype instead.

gcc/ada/

	* sem_ch13.adb (Validate_Unchecked_Conversion): Fix behavior on
	System.Address to access to subprogram subtype conversion.

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

---
 gcc/ada/sem_ch13.adb | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 0d311ca80b4..82345eca09e 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -17742,12 +17742,12 @@  package body Sem_Ch13 is
         and then Is_Descendant_Of_Address (Source)
         and then In_Same_Source_Unit (Target, N)
       then
-         Set_Can_Use_Internal_Rep (Target, False);
+         Set_Can_Use_Internal_Rep (Base_Type (Target), False);
       elsif Is_Access_Subprogram_Type (Source)
         and then Is_Descendant_Of_Address (Target)
         and then In_Same_Source_Unit (Source, N)
       then
-         Set_Can_Use_Internal_Rep (Source, False);
+         Set_Can_Use_Internal_Rep (Base_Type (Source), False);
       end if;
 
       --  Generate N_Validate_Unchecked_Conversion node for back end in case