This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Clarifying attribute-const
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Geert Bosch <boschg at mac dot com>
- Cc: Alexander Monakov <amonakov at ispras dot ru>, Eric Botcazou <ebotcazou at adacore dot com>, GCC Development <gcc at gcc dot gnu dot org>
- Date: Fri, 2 Oct 2015 10:25:18 +0200
- Subject: Re: Clarifying attribute-const
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot LNX dot 2 dot 20 dot 1509251933001 dot 23590 at monopod dot intra dot ispras dot ru> <1449338 dot uM7p4ILj71 at polaris> <alpine dot LNX dot 2 dot 20 dot 1510011821460 dot 15118 at monopod dot intra dot ispras dot ru> <E1BB19B1-2CC6-494C-AFDC-49ED2FD227FD at mac dot com>
On Fri, Oct 2, 2015 at 1:40 AM, Geert Bosch <boschg@mac.com> wrote:
>
>> On Oct 1, 2015, at 11:34 AM, Alexander Monakov <amonakov@ispras.ru> wrote:
>>
>> Can you expand on the "etc." a bit, i.e., may the compiler ...
>>
>> - move a call to a "const" function above a conditional branch,
>> causing a conditional throw to happen unconditionally?
> No, calls may only be omitted, not moved.
>>
>> - move a call to a "const" function below a conditional branch,
>> causing an unconditional throw to happen only conditionally?
>> No, calls may only be omitted, not moved.
I think that's less clear as the transform basically duplicates the call
on both branches and removes the one that is not necessary.
>> - reorder calls to "const" functions w.r.t. code with side effects, or
>> other throwing functions?
> A call to a pure function (Ada's version of "const") may be omitted if its result is not used,
> or if results of an earlier call with the same argument values (including referenced values) can
> be used. This is allowed regardless of whether the original function had any side effects.
> Note that if a function raised an exception (threw) the call can only be replaced with throwing
> that exception.
>
> So, reordering is not allowed, but omitting is, in the context of Ada.
I think GCC does both though (if it throws only externally, for
internally throwing ones
the transforms would be too complicated).
Richard.
> -Geert
>