[COMMITTED] ada: Support Put_Image for types in user-defined instances of predefined generics.

Message ID 20231130101918.3094500-1-poulhies@adacore.com
State Committed
Commit 262229e1e61c5130c7d5f1b4fa4e77ff60c9bc86
Headers
Series [COMMITTED] ada: Support Put_Image for types in user-defined instances of predefined generics. |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm warning Patch is already merged
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 warning Patch is already merged

Commit Message

Marc Poulhiès Nov. 30, 2023, 10:19 a.m. UTC
  From: Steve Baird <baird@adacore.com>

Predefined units do not generally support the Put_Image attribute.
There are good reasons for this in most cases. But if a user-defined
instantiation of a predefined generic occurs in Ada 2022 code, then
Put_Image can be supported for types declared therein. Add this support.

gcc/ada/

	* exp_put_image.adb (Put_Image_Enabled): Return True in more
	cases. In particular, when testing to see if a type occurs in a
	predefined unit, test the type's code unit
	(obtained by calling Get_Code_Unit). In the case of type within a
	user-defined instance of a predefined generic, Is_Predefined_Unit
	will return True for the type and False for the type's code unit.

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

---
 gcc/ada/exp_put_image.adb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb
index 6684d4178e6..a30f609cfac 100644
--- a/gcc/ada/exp_put_image.adb
+++ b/gcc/ada/exp_put_image.adb
@@ -1023,7 +1023,7 @@  package body Exp_Put_Image is
             null;
          elsif Is_Derived_Type (Typ) then
             return Put_Image_Enabled (Etype (Base_Type (Typ)));
-         elsif In_Predefined_Unit (Typ) then
+         elsif Is_Predefined_Unit (Get_Code_Unit (Typ)) then
             return False;
          end if;
       end if;