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: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- To: jakub at redhat dot com
- Cc: 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, rth at redhat dot com
- Date: Mon, 25 Mar 2002 15:11:41 -0500 (EST)
- Subject: Re: Patch to detect invalid and missing ATTRIBUTE const/pure [take 2]
> From: "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu>
>
> Next task will be to start adding ATTRIBUTES where suggested by gcc
> and test test test.
Hmm, so of course its not that simple. Things appear to be strange
under the hood. Consider my last patch:
http://gcc.gnu.org/ml/gcc-patches/2002-03/msg01477.html
and the following testcase:
When compiling with -Wmissing-pure -Wmissing-const, I'm getting this
one warning:
> foo.c:14: warning: function `p2' may be candidate for attribute `pure'
Here's what I consider wrong:
1. Function p2 *is* declare "pure" by the prototype, but
mark_constant_function doesn't realize that when parson p2's
definition. For some reason, "const" is carried through
prototypes to the function definition, but "pure" isn't. If I
mark p2's function definition itself pure, then it appears to
work, but that seems like a bug in attribute merging.
2. I would have thought that foo_p1/foo_c1/foo_p2/foo_c2 would all be
suggested candidates for either pure or const. None of them are.
Is it not the case that a "pure" or "const" function may call
another respectively "pure" or "const" function?
--Kaveh
----------------------------
#define APURE __attribute__ ((__pure__))
#define ACONST __attribute__ ((__const__))
extern int i;
extern int p1 (int) APURE;
extern int c1 (int) ACONST;
extern int p2 (int) APURE;
extern int c2 (int) ACONST;
int p2 (int a)
{
return i + a;
}
int c2 (int a)
{
return a * 3;
}
int foo_p1 (int a, int b)
{
return p1(a) + b;
}
int foo_c1 (int a, int b)
{
return a + c1(b);
}
int foo_p2 (int a, int b)
{
return p2(a) + b;
}
int foo_c2 (int a, int b)
{
return a + c2(b);
}