There is a fallback code in gigi in case the front-end constructs trees referencing non existing record fields. At this stage, it's safer and cleaner to ensure that the front-end never generates such references, and eventually replace the code in gigi by a gcc_unreachable().
We are not quite there yet so for now keep the fallback in gigi, hopefully more changes will follow to completely remove it. The rest of the change is needed to deal with the presence of N_Raise_xxx_Error nodes in more places which the front-end and back-end are not prepared to deal with. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch4.adb (Analyze_Selected_Component): Request a compile time error replacement in Apply_Compile_Time_Constraint_Error in case of an invalid field. * sem_ch3.adb (Create_Constrained_Components): Take advantage of Gather_Components also in the case of a record extension and also constrain records in the case of compile time known discriminant values, as already done in gigi. * sem_util.ads, sem_util.adb (Gather_Components): New parameter Allow_Compile_Time to allow compile time known (but non static) discriminant values, needed by Create_Constrained_Components, and new parameter Include_Interface_Tag. (Is_Dependent_Component_Of_Mutable_Object): Use Original_Node to perform check on the original tree. (Is_Object_Reference): Likewise. Only call Original_Node when relevant via a new function Safe_Prefix. (Is_Static_Discriminant_Component, In_Check_Node): New. (Is_Actual_Out_Or_In_Out_Parameter): New. * exp_ch4.adb (Expand_N_Selected_Component): Remove no longer needed code preventing evaluating statically discriminants in more cases. * exp_ch5.adb (Expand_N_Loop_Statement): Simplify expansion of loops with an N_Raise_xxx_Error node to avoid confusing the code generator. (Make_Component_List_Assign): Try to find a constrained type to extract discriminant values from, so that the case statement built gets an opportunity to be folded by Expand_N_Case_Statement. (Expand_Assign_Record): Update comments, code cleanups. * sem_attr.adb (Analyze_Attribute): Perform most of the analysis on the original prefix node to deal properly with a prefix rewritten as a N_Raise_xxx_Error. * sem_ch5.adb (Analyze_Loop_Parameter_Specification): Handle properly a discrete subtype definition being rewritten as N_Raise_xxx_Error. * sem_ch8.adb (Analyze_Object_Renaming): Handle N_Raise_xxx_Error nodes as part of the expression being renamed. * sem_eval.ads, sem_eval.adb (Fold, Eval_Selected_Component): New. (Compile_Time_Known_Value, Expr_Value, Expr_Rep_Value): Evaluate static discriminant component values. * sem_res.adb (Resolve_Selected_Component): Call Eval_Selected_Component.
patch.diff.gz
Description: application/gzip