[Ada] Spurious access error in function returning type with access discriminant
authorJustin Squirek <squirek@adacore.com>
Wed, 15 Dec 2021 14:27:23 +0000 (14:27 +0000)
committerPierre-Marie de Rodat <derodat@adacore.com>
Fri, 13 May 2022 08:04:27 +0000 (08:04 +0000)
commitfa45988cc0129f95d1c8b1d386342b6351233ef5
tree20fd5f9324b5f2372e9bd5baba9a57daa41d0214
parent74ce1d5a6cbcf81e21b4c0eeee372df46c275df0
[Ada] Spurious access error in function returning type with access discriminant

This patch fixes an issue in the compiler whereby incorrect
accessibility checks were generated in functions returning types with
unconstrained access discriminants when the value supplied for the
discriminant is a formal parameter.

More specifically, accessibility checks for return statements featuring
a result type having access discriminants were incorrectly being
performed against the level of the function declaration instead of the
level of the master of the call.

gcc/ada/

* sem_ch6.adb (Check_Return_Construct_Accessibility): Modify
generation of run-time accessibility checks to account for cases
where Extra_Accessibility_Of_Result should be used versus the
level of the enclosing subprogram. Use original node to avoid
checking against expanded code. Disable check generation for
tagged type case.
(Is_Formal_Of_Current_Function): Added to encompass a predicate
used within Check_Return_Construct_Accessibility to test if an
associated expression is related to a relevant formal.
* sem_util.adb, sem_util.ads (Enclosing_Subprogram): Modified to
accept Node_Or_Entity_Id.
(Innermost_Master_Scope_Depth): Calculate level based on the
subprogram of a return statement instead of the one returned by
Current_Subprogram.
(Needs_Result_Accessibility_Level): Remove
Disable_Coextension_Cases constant, and disable the tagged type
case for performance reasons.
gcc/ada/sem_ch6.adb
gcc/ada/sem_util.adb
gcc/ada/sem_util.ads