[Ada] Fix some "current instance" bugs

Pierre-Marie de Rodat derodat@adacore.com
Mon Jul 5 13:14:13 GMT 2021


This started out as an Ada2022 ticket, but work on Ada 2022 constructs
uncovered bugs that could affect pre-Ada2022 code. Fix those bugs.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* exp_ch3.adb (Build_Record_Init_Proc.Build_Assignment): When
	building the assignment statement corresponding to the default
	expression for a component, we make a copy of the expression.
	When making that copy (and if we have seen a component that
	requires late initialization), pass a Map parameter into the
	call to New_Copy_Tree to redirect references to the type to
	instead refer to the _Init formal parameter of the init proc.
	This includes hoisting the declaration of Has_Late_Init_Comp out
	one level so that it becomes available to Build_Assignment.
	(Find_Current_Instance): Return True for other kinds of current
	instance references, instead of just access-valued attribute
	references such as T'Access.
	* sem_util.adb (Is_Aliased_View): Return True for the _Init
	formal parameter of an init procedure. The changes in
	exp_ch3.adb can have the effect of replacing a "T'Access"
	attribute reference in an init procedure with an "_Init'Access"
	attribute reference. We want such an attribute reference to be
	legal. However, we do not simply mark the formal parameter as
	being aliased because that might impact callers.
	(Is_Object_Image): Return True if Is_Current_Instance returns
	True for the prefix of an Image (or related attribute) attribute
	reference.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-diff
Size: 5439 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210705/b809600d/attachment-0001.bin>


More information about the Gcc-patches mailing list