This implements the AI in all versions of the languages, since it is a
binding interpretation.  The goal of the AI is to clarify where three
checks prescribed by the 6.5 clause are done in the case of an extended
return statement (immediately after the return object is created or
immediately before it is returned) as well as to specify that predicate
checks must also be done immediately before it is returned.

The main implementation change is to arrange for the simple return
statement generated by the expansion of an extended return statement
to be analyzed with checks enabled (except for access checks), but
without doing the common accessibility check on the return object.

Another change is to remove the duplicate implementation of the check
prescribed by AI05-0073 and do it only in Expand_Simple_Function_Return
(this check is one of the three covered by AI12-0343).

This also prevents the compiler from generating duplicate predicate
checks for the expression initializing the return object, if any.

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-15  Eric Botcazou  <ebotca...@adacore.com>

gcc/ada/

        * einfo.ads (Return_Applies_To): Document special usage for E_Block.
        * einfo.adb (Write_Field8_Name): Write it for E_Block too.
        * exp_ch4.adb (Expand_N_Type_Conversion): Remove implementation of
        the check prescribed by AI05-0073.
        * exp_ch6.adb (Apply_CW_Accessibility_Check): New procedure to apply
        the check prescribed by AI95-344 extracted from...
        (Expand_N_Extended_Return_Statement): Apply the check prescribed by
        AI95-344 to the expression, if present.  Suppress only access checks
        when analyzing the rewritten result.
        (Expand_Simple_Function_Return): ...here.  Rename local variable.
        Call Apply_CW_Accessibility_Check to apply the check prescribed by
        AI95-344, but do not do it for the simple return statement generated
        by the expansion of an extended return statement.  Apply the check
        prescribed by AI05-0073 to all functions returning anonymous access
        type designating a specific tagged type, but not if the expression
        was null or tag checks are suppressed for the type, and use Not In
        operator rather than comparing the tags explicitly.
        * sem.adb (Analyze): Handle all Suppress values.
        * sem_ch6.adb (Analyze_Function_Return): Do not explicitly apply
        predicate checks in the case of an extended return statement.
        Do not apply an implicit conversion to the anonymous access result
        type in the case of the simple return statement generated by the
        expansion of an extended return statement.
        (New_Overloaded_Entity): Small comment tweak.
        * treepr.adb (Print_Node): Fix typo in flag string.

Attachment: patch.diff.gz
Description: application/gzip

Reply via email to