Index: sinfo.ads =================================================================== --- sinfo.ads (revision 197766) +++ sinfo.ads (working copy) @@ -807,7 +807,10 @@ -- This flag is set on N_Selected_Component nodes to indicate that a -- discriminant check is required using the discriminant check routine -- associated with the selector. The actual check is generated by the - -- expander when processing selected components. + -- expander when processing selected components. In the case of + -- Unchecked_Union, the flag is also set, but no discriminant check + -- routine is associated with the selector, and the expander does not + -- generate a check. -- Do_Division_Check (Flag13-Sem) -- This flag is set on a division operator (/ mod rem) to indicate Index: sem_res.adb =================================================================== --- sem_res.adb (revision 197777) +++ sem_res.adb (working copy) @@ -8798,8 +8798,6 @@ and then Ekind_In (Entity (S), E_Component, E_Discriminant) and then Present (Original_Record_Component (Entity (S))) and then Ekind (Original_Record_Component (Entity (S))) = E_Component - and then Present (Discriminant_Checking_Func - (Original_Record_Component (Entity (S)))) and then not Discriminant_Checks_Suppressed (T) and then not Init_Component then Index: exp_ch4.adb =================================================================== --- exp_ch4.adb (revision 197777) +++ exp_ch4.adb (working copy) @@ -9198,6 +9198,7 @@ Loc : constant Source_Ptr := Sloc (N); Par : constant Node_Id := Parent (N); P : constant Node_Id := Prefix (N); + S : constant Node_Id := Selector_Name (N); Ptyp : Entity_Id := Underlying_Type (Etype (P)); Disc : Entity_Id; New_N : Node_Id; @@ -9273,18 +9274,27 @@ -- Deal with discriminant check required if Do_Discriminant_Check (N) then + if Present (Discriminant_Checking_Func + (Original_Record_Component (Entity (S)))) + then + -- Present the discriminant checking function to the backend, so + -- that it can inline the call to the function. - -- Present the discriminant checking function to the backend, so that - -- it can inline the call to the function. + Add_Inlined_Body + (Discriminant_Checking_Func + (Original_Record_Component (Entity (S)))); - Add_Inlined_Body - (Discriminant_Checking_Func - (Original_Record_Component (Entity (Selector_Name (N))))); + -- Now reset the flag and generate the call - -- Now reset the flag and generate the call + Set_Do_Discriminant_Check (N, False); + Generate_Discriminant_Check (N); - Set_Do_Discriminant_Check (N, False); - Generate_Discriminant_Check (N); + -- In the case of Unchecked_Union, no discriminant checking is + -- actually performed. + + else + Set_Do_Discriminant_Check (N, False); + end if; end if; -- Ada 2005 (AI-318-02): If the prefix is a call to a build-in-place