From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1285) id F2C0D3865483; Fri, 21 May 2021 08:49:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F2C0D3865483 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Eric Botcazou To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8453] Always translate Is_Pure flag into pure in C sense X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: a9591c33e91b7cb1e544b4efb5987a93143a2a07 X-Git-Newrev: 36a70e6b64be306cf6384becbd21c65ac8bd22fa Message-Id: <20210521084945.F2C0D3865483@sourceware.org> Date: Fri, 21 May 2021 08:49:45 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 May 2021 08:49:46 -0000 https://gcc.gnu.org/g:36a70e6b64be306cf6384becbd21c65ac8bd22fa commit r11-8453-g36a70e6b64be306cf6384becbd21c65ac8bd22fa Author: Eric Botcazou Date: Fri May 21 10:45:21 2021 +0200 Always translate Is_Pure flag into pure in C sense Gigi has historically translated the Is_Pure flag of the front-end into the "const" attribute of GNU C. That's correct for subprograms of pure Ada units, but not fully exact according to the semantics of the flag. gcc/ada/ * gcc-interface/decl.c (gnat_to_gnu_subprog_type): Always translate the Is_Pure flag into the "pure" attribute of GNU C. Diff: --- gcc/ada/gcc-interface/decl.c | 47 ++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index 27ef51a9eed..232a67ce77b 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -5761,16 +5761,16 @@ gnat_to_gnu_subprog_type (Entity_Id gnat_subprog, bool definition, tree gnu_cico_return_type = NULL_TREE; tree gnu_cico_field_list = NULL_TREE; bool gnu_cico_only_integral_type = true; - /* The semantics of "pure" in Ada essentially matches that of "const" - or "pure" in GCC. In particular, both properties are orthogonal - to the "nothrow" property if the EH circuitry is explicit in the - internal representation of the middle-end. If we are to completely - hide the EH circuitry from it, we need to declare that calls to pure - Ada subprograms that can throw have side effects since they can - trigger an "abnormal" transfer of control flow; therefore, they can - be neither "const" nor "pure" in the GCC sense. */ - bool const_flag = (Back_End_Exceptions () && Is_Pure (gnat_subprog)); - bool pure_flag = false; + /* Although the semantics of "pure" units in Ada essentially match those of + "const" in GNU C, the semantics of the Is_Pure flag in GNAT do not say + anything about access to global memory, that's why it needs to be mapped + to "pure" instead of "const" in GNU C. The property is orthogonal to the + "nothrow" property only if the EH circuitry is explicit in the internal + representation of the middle-end: if we are to completely hide the EH + circuitry from it, we need to declare that calls to pure Ada subprograms + that can throw have side effects, since they can trigger an "abnormal" + transfer of control; therefore they cannot be "pure" in the GCC sense. */ + bool pure_flag = Is_Pure (gnat_subprog) && Back_End_Exceptions (); bool return_by_direct_ref_p = false; bool return_by_invisi_ref_p = false; bool return_unconstrained_p = false; @@ -5923,14 +5923,14 @@ gnat_to_gnu_subprog_type (Entity_Id gnat_subprog, bool definition, } /* A procedure (something that doesn't return anything) shouldn't be - considered const since there would be no reason for calling such a + considered pure since there would be no reason for calling such a subprogram. Note that procedures with Out (or In Out) parameters have already been converted into a function with a return type. Similarly, if the function returns an unconstrained type, then the function will allocate the return value on the secondary stack and thus calls to it cannot be CSE'ed, lest the stack be reclaimed. */ if (VOID_TYPE_P (gnu_return_type) || return_unconstrained_p) - const_flag = false; + pure_flag = false; /* Loop over the parameters and get their associated GCC tree. While doing this, build a copy-in copy-out structure if we need one. */ @@ -6058,18 +6058,16 @@ gnat_to_gnu_subprog_type (Entity_Id gnat_subprog, bool definition, save_gnu_tree (gnat_param, gnu_param, false); /* A pure function in the Ada sense which takes an access parameter - may modify memory through it and thus need be considered neither - const nor pure in the GCC sense. Likewise it if takes a by-ref - In Out or Out parameter. But if it takes a by-ref In parameter, - then it may only read memory through it and can be considered - pure in the GCC sense. */ - if ((const_flag || pure_flag) - && (POINTER_TYPE_P (gnu_param_type) + may modify memory through it and thus cannot be considered pure + in the GCC sense, unless it's access-to-function. Likewise it if + takes a by-ref In Out or Out parameter. But if it takes a by-ref + In parameter, then it may only read memory through it and can be + considered pure in the GCC sense. */ + if (pure_flag + && ((POINTER_TYPE_P (gnu_param_type) + && TREE_CODE (TREE_TYPE (gnu_param_type)) != FUNCTION_TYPE) || TYPE_IS_FAT_POINTER_P (gnu_param_type))) - { - const_flag = false; - pure_flag = DECL_POINTS_TO_READONLY_P (gnu_param); - } + pure_flag = DECL_POINTS_TO_READONLY_P (gnu_param); } /* If the parameter uses the copy-in copy-out mechanism, allocate a field @@ -6269,9 +6267,6 @@ gnat_to_gnu_subprog_type (Entity_Id gnat_subprog, bool definition, } } - if (const_flag) - gnu_type = change_qualified_type (gnu_type, TYPE_QUAL_CONST); - if (pure_flag) gnu_type = change_qualified_type (gnu_type, TYPE_QUAL_RESTRICT);