This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch to detect invalid and missing ATTRIBUTE const/pure [take 2]
- From: Zack Weinberg <zack at codesourcery dot com>
- To: Richard Henderson <rth at redhat dot com>,"Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>, dann at ics dot uci dot edu,gcc-patches at gcc dot gnu dot org, jh at suse dot cz, john at feith dot com,mark at codesourcery dot com
- Date: Mon, 25 Mar 2002 13:02:51 -0800
- Subject: Re: Patch to detect invalid and missing ATTRIBUTE const/pure [take 2]
- References: <200203250554.AAA05644@caip.rutgers.edu> <20020325004601.A14556@redhat.com>
On Mon, Mar 25, 2002 at 12:46:01AM -0800, Richard Henderson wrote:
> On Mon, Mar 25, 2002 at 12:54:59AM -0500, Kaveh R. Ghazi wrote:
> > > No. const functions may be moved outside a loop, and if left
> > > inside the loop, may never be reached.
> [...]
> > However given that the programmer may "know" that the noreturn call
> > never occurs in practice, does it make sense to bypass the warning
> > about the marking being "invalid" should the programmer decide to mark
> > it explicitly?
>
> No. Like I just said, const functions may be called in
> cases that they weren't in the source code.
I agree with the person elsethread who observed that calling a
const/pure function more than the unoptimized program would have is
likely to be a mis-optimization; const and pure don't say anything
about the computational expense of the routine. However, for safety's
sake, it is starting to sound like we need another attribute which
indicates a const/pure function that does not necessarily return, so
it cannot be called more times than the unoptimized program would have
(but less is safe).
__attribute__ ((const, maynotreturn)) ?
zw