From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1285) id B00BE385703A; Fri, 21 May 2021 08:45:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B00BE385703A 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 r12-966] Always translate Is_Pure flag into pure in C sense X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/master X-Git-Oldrev: 1e66a9170071aded59dda09ac437757de4223346 X-Git-Newrev: 932198a8e1b6ab26201a265ced3a8c4802304146 Message-Id: <20210521084557.B00BE385703A@sourceware.org> Date: Fri, 21 May 2021 08:45:57 +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:45:57 -0000 https://gcc.gnu.org/g:932198a8e1b6ab26201a265ced3a8c4802304146 commit r12-966-g932198a8e1b6ab26201a265ced3a8c4802304146 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 | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index a7595cbf514..19e851ff712 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -5737,16 +5737,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; @@ -5899,14 +5899,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. */ @@ -6034,19 +6034,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, 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 ((const_flag || pure_flag) + 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 @@ -6246,9 +6243,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);