Local binding DECLs
Stephen Biggs
xyzzy@hotpop.com
Mon May 12 12:54:00 GMT 2003
On Mon, 2003-05-12 at 10:30, Daniel Berlin wrote:
>
> On Monday, May 12, 2003, at 02:44 AM, Stephen Biggs wrote:
>
> > On Mon, 2003-05-12 at 04:13, Richard Henderson wrote:
> >> On Sun, May 11, 2003 at 10:04:20AM +0300, Stephen Biggs wrote:
> >>> Ok... is there ANY way to find out if the FUNCTION_DECL I am handed
> >>> at
> >>> any time (preferably in ENCODE_SECTION) is declared in a function
> >>> block
> >>> as opposed to globally?
> >>
> >> *Declared*? I.e. to distinguish
> >>
> >> extern void foo();
> >> void bar() { foo(); }
> >>
> >> from
> >>
> >> void bar() {
> >> extern void foo();
> >> foo();
> >> }
> >>
> >> Absolutely not. That question doesn't even make sense.
> >>
> >>
> >> r~
> >>
> > Sure it does, if you have, for example:
> >
> > void bar() {
> > static void foo();
> > foo();
> > }
> >
> > void bar1() {
> > static int foo();
> > foo();
> > }
> >
> > void bar2() {
> > static int foo(int);
> > int a = foo(3);
> > }
> > foo() {}
> >
> > This compiles.
> >
> > I see nothing that gives me the ability to know that any particular
> > DECL
> > is declared inside a particular function.
> >
>
>
> Errr, won't DECL_CONTEXT do what you want?
> From tree.h:
> /* For FIELD_DECLs, this is the
> RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node that the field is
> a member of. For VAR_DECL, PARM_DECL, FUNCTION_DECL, LABEL_DECL,
> and CONST_DECL nodes, this points to either the FUNCTION_DECL for
> the
> containing function, the RECORD_TYPE or UNION_TYPE for the
> containing
> type, or NULL_TREE if the given decl has "file scope". */
> #define DECL_CONTEXT(NODE) (DECL_CHECK (NODE)->decl.context)
>
>
> DECL_CONTEXT on a contained function_decl should give you the
> containing function_decl (or NULL_TREE if it's not contained/is file
> scope), as the comment says.
> Does it not work?
> I haven't really been following till now.
> --Dan
>
>
As a matter of fact, a few things seem to be broken in 3.2, unless I am
off the deep end here.
E.g., in the test case gcc/testsuite/gcc.dg/c90-impl-decl-1.c, shouldn't
the DECL for "foo" also be defined in
IDENTIFIER_IMPLICIT_DECL(DECL_NAME(decl)) since this is an implicit
prototype? The args are defined as TYPE_BINFO, but that is not enough,
is it? This means that the function is defined as old-style but says
nothing about whether there is a function prototype defined or not,
which is what I thought the IDENTIFIER_IMPLICIT_DECL was for.
Rechecking shows me that in the test case
gcc/testsuite/gcc.c-torture/compile/920625-1.c, DECL_CONTEXT is, in
fact, nil for the function_decl for function freeReturnStruct when it is
passed to ENCODE_SECTION.
Shouldn't these be defined as expected?? Am I missing something really
dumb, here?
I've been banging my head against the wall trying to figure out ways to
decipher these states when the compiler front-end should be telling me
up-front.
More information about the Gcc
mailing list