This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Local binding DECLs


On Tue, 2003-05-13 at 03:33, Geoff Keating wrote:
> Stephen Biggs <xyzzy@hotpop.com> writes:
> 
> > 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.
> 
> My immediate reaction is "no it doesn't!"
> 
> It certainly shouldn't, ISO C specifically prohibits it and it's not
> any GCC extension I recognize.

I'll agree 100% that this is garbage code.  That being said, why is
stuff like this all over the GCC/deja testsuite and classified as
"PASS"??  If it shouldn't compile and ISO C specifically prohibits it,
then why does GCC allow this without barfing?  -W compiles cleanly
without complaint. Only when -Wall is specified do the warnings start.

It generates perfectly good assembly code on the x86:
        .ident  "GCC: (GNU) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)"

> 
> > I see nothing that gives me the ability to know that any particular DECL
> > is declared inside a particular function.
> 
> That question really doesn't make sense.  Why do you want to know this?

Why shouldn't I be able to know this?  What do IDENTIFIER_IMPLICIT_DECL
and DECL_CONTEXT mean?  When are they set?  I am NEVER seeing
DECL_CONTEXT set.  Is this only for nested functions where the body is
enclosed in another function??

You're saying that knowing the scope of a particular function
declaration/prototype has no use?

> 
> > Perhaps someone might need to write different code or do something else
> > different per function based on the local declarations?  Does THIS make
> > sense?
> 
> No, it doesn't.  Can you give an example of what you want to do?

In the code compiled for the foo function, it would help optimization if
it was know whether the return value was used anywhere, whether or not
it was declared to return "int" in the actual function definition.

I also don't want to generate machine instructions in a function that
calls "foo" to handle return values if "foo" is declared as "void"
inside the scope.  The problem here is that the declaration changes and
the scope of the declaration isn't known, based on DECL_CONTEXT not
being set.

[-- signature snipped --]




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]