Skip to content
Snippets Groups Projects
Commit eb1091dd authored by Steve Baird's avatar Steve Baird Committed by Pierre-Marie de Rodat
Browse files

[Ada] Missing discriminant checks when accessing variant field

In some cases, the compiler would incorrectly fail to generate
discriminant checks when accessing fields declared in a variant part.
Correct some such cases; detect the remaining cases and flag them as
unsupported. The formerly-problematic cases that are now handled
correctly involve component references occurring in a predicate
expression (e.g., the expression of a Dynamic_Predicate aspect
specification) for a type declaration (not for a subtype declaration).
The cases which are now flagged as unsupported involve expression
functions declared before the discriminated type in question has been
frozen.

gcc/ada/

	* exp_ch3.ads: Replace visible Build_Discr_Checking_Funcs (which
	did not need to be visible - it was not referenced outside this
	package) with Build_Or_Copy_Discr_Checking_Funcs.
	* exp_ch3.adb: Refactor existing code into 3 procedures -
	Build_Discr_Checking_Funcs, Copy_Discr_Checking_Funcs, and
	Build_Or_Copy_Discr_Checking_Funcs. This refactoring is intended
	to be semantics-preserving.
	* exp_ch4.adb (Expand_N_Selected_Component): Detect case where a
	call should be generated to the Discriminant_Checking_Func for
	the component in question, but that subprogram does not yet
	exist.
	* sem_ch13.adb (Freeze_Entity_Checks): Immediately before
	calling Build_Predicate_Function, add a call to
	Exp_Ch3.Build_Or_Copy_Discr_Checking_Funcs in order to ensure
	that Discriminant_Checking_Func attributes are already set when
	Build_Predicate_Function is called.
	* sem_ch6.adb (Analyze_Expression_Function): If the expression
	of a static expression function has been transformed into an
	N_Raise_xxx_Error node, then we need to copy the original
	expression in order to check the requirement that the expression
	must be a potentially static expression. We also want to set
	aside a copy the untransformed expression for later use in
	checking calls to the expression function via
	Inline_Static_Function_Call.  So introduce a new function,
	Make_Expr_Copy, for use in these situations.
	* sem_res.adb (Preanalyze_And_Resolve): When analyzing certain
	expressions (e.g., a default parameter expression in a
	subprogram declaration) we want to suppress checks. However, we
	do not want to suppress checks for the expression of an
	expression function.
parent 3c2674cc
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment