[Ada] Postcondition checks performed before finalization

Pierre-Marie de Rodat derodat@adacore.com
Tue Dec 15 11:42:41 GMT 2020


This patch fixes an issue in the compiler whereby postconditions were
incorrectly checked prior to the execution of finalization.

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

gcc/ada/

	* contracts.adb, contracts.ads (Build_Postconditions_Procedure):
	Add declarations for Postcond_Enabled,
	Result_Object_For_Postcondition, and
	Return_Success_For_Postcond, and place all postconditions within
	an if statement to control their execution for interactions when
	cleanup actions get generated.
	(Get_Postcond_Enabled): Created to fetch object declared to
	handle new expansion of postconditions.
	(Get_Result_Object_For_Postcond): Created to fetch object
	declared to handle new expansion of postconditions.
	(Get_Return_Success_For_Postcond): Created to fetch object
	declared to handle new expansion of postconditions.
	* einfo.adb, einfo.ads: Modify flag Stores_Attribute_Old_Prefix
	to apply to constants, variables, and types.
	* exp_ch6.adb (Add_Return): Add assignment to
	Return_Success_For_Postcond.
	(Expand_Non_Function_Return): Add assignment to
	Return_Success_For_Postcond
	(Expand_Simple_Function_Return): Add assignment to
	Result_Object_For_Postcond and Return_Success_For_Postcond.
	* exp_ch7.adb (Build_Finalization_Master): Mark finalization
	masters which finalize types created store 'Old objects as
	storing 'Old objects.
	(Build_Finalizer): Created to generated a unified and special
	expansion for finalization when postconditions are present.
	(Build_Finalizer_Helper): Renamed Build_Finalizer and added
	parameter to facilitate the creation of separate finalization
	routines for 'Old objects and general objects.
	(Create_Finalizer): Add condition for the insertion of the
	finalizer spec to avoid malformed trees.
	(Expand_Cleanup_Actions): Move _postconditions and related
	declarations to the new declarative section.  Fix the loop to
	properly stop at the subprogram declaration for the
	postconditions procedure and exclude its body from being moved
	to the new list of declarations to avoid freezing issues.
	* exp_prag.adb (Expand_Attributes): Mark temporary created to
	store 'Old objects as storing a 'Old attribute.
	* sem_ch6.adb (Find_What_Applies_To): Remove strange exception
	to postconditions when traversing the scope stack.
	* sem_prag.adb (Find_Related_Declaration_Or_Body): Use the newly
	created Enclosing_HSS function to find the HSS for a potentially
	nested statement.
	* sem_util.adb, sem_util.ads (Declare_Indirect_Temp): Mark types
	created to store 'Old objects as storing 'Old attributes.
	(Enclosing_HSS): Created to find the enclosing handled sequence
	of statements for a given statement.
	* snames.ads-tmpl: Add multiple names to aid in the expansion of
	finalization and to control the evaluation of postconditions.
	Including _finalization_controller, a new routine to centralize
	finalization actions and postcondition evaluation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff.gz
Type: application/gzip
Size: 10314 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20201215/71837008/attachment-0001.gz>


More information about the Gcc-patches mailing list