In some cases where a function result type has an access discriminant part, Ada requires that the execution of a return statement include a check that the access discriminant does not designate an object whose accessibility level is too deep (Ada RM 6.5(21)). This check was being incorrectly omitted in some cases where the discriminant value designates a not-explicitly-aliased parameter of the function (or some part thereof). Correct this omission. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch6.adb (Check_Return_Construct_Accessibility): Modify generation of accessibility checks to be more consolidated and get triggered properly in required cases. * sem_util.adb (Accessibility_Level): Add extra check within condition to handle aliased formals properly in more cases.