[Ada] Incorrect Dynamic_Predicate results for static arguments

Pierre-Marie de Rodat derodat@adacore.com
Mon Oct 11 13:39:47 GMT 2021


In determining at run time whether a statically-known discrete value
satisifies the predicate of a subtype where both

   - a Dynamic_Predicate aspect specification applies (directly or
     indirectly) to a subtype; and

   - at least one other predicate aspect specification (that is, either
     a Static_Predicate aspect specification, a GNAT-defined Predicate
     aspect specification, or a second Dynamic_Predicate aspect
     specification) applies (directly or indirectly) to that same
     subtype,

sometimes only the "last" Dynamic_Predicate aspect's condition was
checked; the other predicate aspects were incorrectly ignored. This
could result in a subtype membership test incorrectly yielding a result
of True. This error is corrected.

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

gcc/ada/

	* exp_ch6.adb (Can_Fold_Predicate_Call): Do not attempt folding
	if there is more than one predicate involved. Recall that
	predicate aspect specification are additive, not overriding, and
	that there are three different predicate
	aspects (Dynamic_Predicate, Static_Predicate, and the
	GNAT-defined Predicate aspect). These various ways of
	introducing multiple predicates are all checked for.  A new
	nested function, Augments_Other_Dynamic_Predicate, is
	introduced.
	* sem_ch4.adb
	(Analyze_Indexed_Component_Form.Process_Function_Call): When
	determining whether a name like "X (Some_Discrete_Type)" might
	be interpreted as a slice, the answer should be "no" if the
	type/subtype name denotes the current instance of type/subtype.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-diff
Size: 3469 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20211011/74cba155/attachment.bin>


More information about the Gcc-patches mailing list