* Local binding DECLs @ 2003-05-08 11:40 Stephen Biggs 2003-05-08 22:04 ` Richard Henderson 0 siblings, 1 reply; 11+ messages in thread From: Stephen Biggs @ 2003-05-08 11:40 UTC (permalink / raw) To: GCC list Given a set of functions such as: void a(void) { static void b(void); static void c(char); static char d[20]; b(); c(d[0]); } b() {} c(char aa) {} ... when TARGET_ASM_FUNCTION_PROLOGUE is called on 'a', is there any way to access the DECLs of b, c, and d, and only those, that is, the DECLs of all the forward declarations in the scope of this function? I tried searching through the list given by getdecls but came up with the DECLs at the same level as a, that is, the GLOBAL binding level, and not locally subordinate to a. Is this even possible at this stage? Thanks for any help. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Local binding DECLs 2003-05-08 11:40 Local binding DECLs Stephen Biggs @ 2003-05-08 22:04 ` Richard Henderson 2003-05-11 7:03 ` Stephen Biggs 0 siblings, 1 reply; 11+ messages in thread From: Richard Henderson @ 2003-05-08 22:04 UTC (permalink / raw) To: Stephen Biggs; +Cc: GCC list On Thu, May 08, 2003 at 02:42:47PM +0300, Stephen Biggs wrote: > Is this even possible at this stage? No. r~ ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Local binding DECLs 2003-05-08 22:04 ` Richard Henderson @ 2003-05-11 7:03 ` Stephen Biggs 2003-05-12 1:15 ` Richard Henderson 0 siblings, 1 reply; 11+ messages in thread From: Stephen Biggs @ 2003-05-11 7:03 UTC (permalink / raw) To: GCC list On Fri, 2003-05-09 at 01:01, Richard Henderson wrote: > On Thu, May 08, 2003 at 02:42:47PM +0300, Stephen Biggs wrote: > > Is this even possible at this stage? > > No. > > > r~ > 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? ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Local binding DECLs 2003-05-11 7:03 ` Stephen Biggs @ 2003-05-12 1:15 ` Richard Henderson 2003-05-12 6:41 ` Stephen Biggs 0 siblings, 1 reply; 11+ messages in thread From: Richard Henderson @ 2003-05-12 1:15 UTC (permalink / raw) To: Stephen Biggs; +Cc: GCC list 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~ ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Local binding DECLs 2003-05-12 1:15 ` Richard Henderson @ 2003-05-12 6:41 ` Stephen Biggs 2003-05-12 7:30 ` Daniel Berlin ` (2 more replies) 0 siblings, 3 replies; 11+ messages in thread From: Stephen Biggs @ 2003-05-12 6:41 UTC (permalink / raw) To: GCC list 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. Perhaps someone might need to write different code or do something else different per function based on the local declarations? Does THIS make sense? ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Local binding DECLs 2003-05-12 6:41 ` Stephen Biggs @ 2003-05-12 7:30 ` Daniel Berlin 2003-05-12 10:32 ` Stephen Biggs 2003-05-12 12:54 ` Stephen Biggs 2003-05-12 17:15 ` Richard Henderson [not found] ` <jm1xz33cu5.fsf@desire.geoffk.org> 2 siblings, 2 replies; 11+ messages in thread From: Daniel Berlin @ 2003-05-12 7:30 UTC (permalink / raw) To: Stephen Biggs; +Cc: GCC list 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 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Local binding DECLs 2003-05-12 7:30 ` Daniel Berlin @ 2003-05-12 10:32 ` Stephen Biggs 2003-05-12 12:54 ` Stephen Biggs 1 sibling, 0 replies; 11+ messages in thread From: Stephen Biggs @ 2003-05-12 10:32 UTC (permalink / raw) To: GCC list 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 > > No, DECL_CONTEXT seems to be NULL all the time when ENCODE_SECTION is called, even on contained function DECLs. Version 3.2. This is my problem. I can't find out the scope of the DECL because of this. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Local binding DECLs 2003-05-12 7:30 ` Daniel Berlin 2003-05-12 10:32 ` Stephen Biggs @ 2003-05-12 12:54 ` Stephen Biggs 1 sibling, 0 replies; 11+ messages in thread From: Stephen Biggs @ 2003-05-12 12:54 UTC (permalink / raw) To: GCC list 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. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Local binding DECLs 2003-05-12 6:41 ` Stephen Biggs 2003-05-12 7:30 ` Daniel Berlin @ 2003-05-12 17:15 ` Richard Henderson [not found] ` <jm1xz33cu5.fsf@desire.geoffk.org> 2 siblings, 0 replies; 11+ messages in thread From: Richard Henderson @ 2003-05-12 17:15 UTC (permalink / raw) To: Stephen Biggs; +Cc: GCC list On Mon, May 12, 2003 at 09:44:43AM +0300, Stephen Biggs wrote: > This compiles. Ok, but it's certainly not a correct program, so I don't see why we should have to care how it gets compiled. > I see nothing that gives me the ability to know that any particular DECL > is declared inside a particular function. I still don't see why you would possibly need to care. > 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. r~ ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <jm1xz33cu5.fsf@desire.geoffk.org>]
* Re: Local binding DECLs [not found] ` <jm1xz33cu5.fsf@desire.geoffk.org> @ 2003-05-13 8:45 ` Stephen Biggs 2003-05-14 18:31 ` Geoff Keating 0 siblings, 1 reply; 11+ messages in thread From: Stephen Biggs @ 2003-05-13 8:45 UTC (permalink / raw) To: GCC list; +Cc: Geoff Keating 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 --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Local binding DECLs 2003-05-13 8:45 ` Stephen Biggs @ 2003-05-14 18:31 ` Geoff Keating 0 siblings, 0 replies; 11+ messages in thread From: Geoff Keating @ 2003-05-14 18:31 UTC (permalink / raw) To: xyzzy; +Cc: gcc > X-Original-To: geoffk@foam.wonderslug.com > From: Stephen Biggs <xyzzy@hotpop.com> > Cc: Geoff Keating <geoffk@geoffk.org> > Date: 13 May 2003 11:48:56 +0300 > X-HotPOP: ----------------------------------------------- > Sent By HotPOP.com FREE Email > Get your FREE POP email at www.HotPOP.com > ----------------------------------------------- > X-OriginalArrivalTime: 13 May 2003 08:45:13.0274 (UTC) FILETIME=[F81241A0:01C3192B] > > 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'd help if you could point to a particular example. As I said, this shouldn't be allowed. I actually see *two* problems: 1. You can't have a declaration like 'static void foo(int)' other than at file scope 2. Even if the declarations were 'extern void foo(int)', they have to be compatible with the function's actual definition, and they aren't. > 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?? DECL_CONTEXT is documented in tree.h, and I thought it was pretty clear: 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". [I think this comment is incomplete, though, because DECL_CONTEXT can also be a BLOCK.] However DECL_CONTEXT doesn't completely specify the scope of the declaration or how it can be accessed, for instance in C++ you can get to declarations inside classes or namespaces. > You're saying that knowing the scope of a particular function > declaration/prototype has no use? I'm wondering why you should care in a backend, or how you could even make sense of it once you knew it. > > > 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. This is tricky. Consider function pointers, for example. Ideally you'd want to do this as a general optimisation at the tree level, removing unused parameters and return values from static functions. > 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. You can do this based just on the type at the time of the call, you don't need to have to know about scoping for it. -- - Geoffrey Keating <geoffk@geoffk.org> ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2003-05-14 18:31 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2003-05-08 11:40 Local binding DECLs Stephen Biggs 2003-05-08 22:04 ` Richard Henderson 2003-05-11 7:03 ` Stephen Biggs 2003-05-12 1:15 ` Richard Henderson 2003-05-12 6:41 ` Stephen Biggs 2003-05-12 7:30 ` Daniel Berlin 2003-05-12 10:32 ` Stephen Biggs 2003-05-12 12:54 ` Stephen Biggs 2003-05-12 17:15 ` Richard Henderson [not found] ` <jm1xz33cu5.fsf@desire.geoffk.org> 2003-05-13 8:45 ` Stephen Biggs 2003-05-14 18:31 ` Geoff Keating
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).