[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.
Showing
- gcc/ada/exp_ch3.adb 54 additions, 34 deletionsgcc/ada/exp_ch3.adb
- gcc/ada/exp_ch3.ads 9 additions, 4 deletionsgcc/ada/exp_ch3.ads
- gcc/ada/exp_ch4.adb 11 additions, 0 deletionsgcc/ada/exp_ch4.adb
- gcc/ada/sem_ch13.adb 10 additions, 1 deletiongcc/ada/sem_ch13.adb
- gcc/ada/sem_ch6.adb 39 additions, 29 deletionsgcc/ada/sem_ch6.adb
- gcc/ada/sem_res.adb 5 additions, 1 deletiongcc/ada/sem_res.adb
Loading
Please register or sign in to comment