* Static nested functions
@ 2004-12-01 7:12 James A. Morrison
2004-12-01 7:36 ` Zack Weinberg
0 siblings, 1 reply; 6+ messages in thread
From: James A. Morrison @ 2004-12-01 7:12 UTC (permalink / raw)
To: gcc
Hi,
I'm looking at 18596 again because my fix didn't do what I expected (it does
nothing). Anyway, we have in gcc.dg/funcdec-storage-1.c the following
void
flarm(void)
{
static void foo(); /* { dg-error "invalid storage class" } */
foo();
}
Should foo () be considered a static function at the file level or a nested
function at the function level. If we consider foo() to be at the file level
then we can be done with this function. If we consider foo() to be a nested
function we then discover that foo() is undefined at the end of the function
and run into PR17807. The nice part about considering foo() to be a nested
function is that in c-decl.c:grokdeclarator() we can turn the storage class of
foo() from static to auto which fixes the ICE in 18596. However we look at
this we are in an error case, but we should do something sane.
--
Thanks,
Jim
http://www.student.cs.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Static nested functions
2004-12-01 7:12 Static nested functions James A. Morrison
@ 2004-12-01 7:36 ` Zack Weinberg
2004-12-01 11:05 ` Joseph S. Myers
0 siblings, 1 reply; 6+ messages in thread
From: Zack Weinberg @ 2004-12-01 7:36 UTC (permalink / raw)
To: James A. Morrison; +Cc: gcc
Suggest trying csc_extern instead of csc_auto; that might get more
sensible error-recovery behavior.
zw
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Static nested functions
2004-12-01 7:36 ` Zack Weinberg
@ 2004-12-01 11:05 ` Joseph S. Myers
2004-12-01 17:38 ` Zack Weinberg
0 siblings, 1 reply; 6+ messages in thread
From: Joseph S. Myers @ 2004-12-01 11:05 UTC (permalink / raw)
To: Zack Weinberg; +Cc: James A. Morrison, gcc
On Tue, 30 Nov 2004, Zack Weinberg wrote:
> Suggest trying csc_extern instead of csc_auto; that might get more
> sensible error-recovery behavior.
I'd concur, and also add that this should make the code in pushdecl
/* Similarly, a declaration of a function with static linkage at
block scope must be checked against any existing declaration
of that function at file scope. */
else if (TREE_CODE (x) == FUNCTION_DECL && scope != file_scope
&& !TREE_PUBLIC (x) && !DECL_INITIAL (x))
{
...
unreachable, so it should be replaced by an assert (with appropriate tests
for static declarations at block scope with extern and static ones at file
scope, and for auto declarations at block scope which should shadow outer
static or extern declarations with the same name, and that auto
declarations or nested function definitions with implied auto conflict
with extern declarations at the same scope but not with other auto
declarations at the same scope). (Only at this stage if there's a
regression involved, of course.)
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
joseph@codesourcery.com (CodeSourcery mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Static nested functions
2004-12-01 11:05 ` Joseph S. Myers
@ 2004-12-01 17:38 ` Zack Weinberg
2004-12-01 17:43 ` Joseph S. Myers
0 siblings, 1 reply; 6+ messages in thread
From: Zack Weinberg @ 2004-12-01 17:38 UTC (permalink / raw)
To: Joseph S. Myers; +Cc: James A. Morrison, gcc
"Joseph S. Myers" <joseph@codesourcery.com> writes:
> On Tue, 30 Nov 2004, Zack Weinberg wrote:
>
>> Suggest trying csc_extern instead of csc_auto; that might get more
>> sensible error-recovery behavior.
>
> I'd concur, and also add that this should make the code in pushdecl
>
> /* Similarly, a declaration of a function with static linkage at
> block scope must be checked against any existing declaration
> of that function at file scope. */
> else if (TREE_CODE (x) == FUNCTION_DECL && scope != file_scope
> && !TREE_PUBLIC (x) && !DECL_INITIAL (x))
> {
> ...
>
> unreachable, so it should be replaced by an assert
good point ...
> (with appropriate tests for static declarations at block scope with
> extern and static ones at file scope, and for auto declarations at
> block scope which should shadow outer static or extern declarations
> with the same name, and that auto declarations or nested function
> definitions with implied auto conflict with extern declarations at
> the same scope but not with other auto declarations at the same
> scope).
I can't parse this sentence; is it just a list of appropriate tests?
If so, would you be willing to implement such a test and file a 4.1-
target PR?
zw
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Static nested functions
2004-12-01 17:38 ` Zack Weinberg
@ 2004-12-01 17:43 ` Joseph S. Myers
2004-12-02 1:22 ` James A. Morrison
0 siblings, 1 reply; 6+ messages in thread
From: Joseph S. Myers @ 2004-12-01 17:43 UTC (permalink / raw)
To: Zack Weinberg; +Cc: James A. Morrison, gcc
On Wed, 1 Dec 2004, Zack Weinberg wrote:
> > (with appropriate tests for static declarations at block scope with
> > extern and static ones at file scope, and for auto declarations at
> > block scope which should shadow outer static or extern declarations
> > with the same name, and that auto declarations or nested function
> > definitions with implied auto conflict with extern declarations at
> > the same scope but not with other auto declarations at the same
> > scope).
>
> I can't parse this sentence; is it just a list of appropriate tests?
> If so, would you be willing to implement such a test and file a 4.1-
> target PR?
Yes, it's a list of appropriate tests. I can write the tests (minus the
diagnostics which may depend on the exact patch; the point of the tests
being that certain errors are detected and do not cause a crash, the exact
errors following the first one not being so important).
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
joseph@codesourcery.com (CodeSourcery mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Static nested functions
2004-12-01 17:43 ` Joseph S. Myers
@ 2004-12-02 1:22 ` James A. Morrison
0 siblings, 0 replies; 6+ messages in thread
From: James A. Morrison @ 2004-12-02 1:22 UTC (permalink / raw)
To: Joseph S. Myers; +Cc: Zack Weinberg, gcc
[-- Attachment #1: Type: text/plain, Size: 603 bytes --]
"Joseph S. Myers" <joseph@codesourcery.com> writes:
> Yes, it's a list of appropriate tests. I can write the tests (minus the
> diagnostics which may depend on the exact patch; the point of the tests
> being that certain errors are detected and do not cause a crash, the exact
> errors following the first one not being so important).
>
What I've got now is the following attached testcases. When I get something
that doesn't ICE on all the testcases I'll be happy.
--
Thanks,
Jim
http://www.student.cs.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Modified funcdec-storage-1.c --]
[-- Type: text/x-csrc, Size: 267 bytes --]
/* { dg-do compile } */
/* { dg-options "" } */
void
flarm(void)
{
static void foo(); /* { dg-error "invalid storage class" } */
static void bar(); /* { dg-error "invalid storage class" } */
foo();
}
static void
bar (int i)
{
}
static void
foo(void)
{
}
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: pr18596-1.c --]
[-- Type: text/x-csrc, Size: 544 bytes --]
/* { dg-do compile } */
/* { dg-options "" } */
register int h ()
{ /* { dg-error "invalid storage class" } */
return 1;
}
int f(int i)
{
static int g(); /* { dg-error "invalid storage class" } */
static int g() { /* { dg-error "invalid storage class" } */
return i;
}
return g();
}
int k(int i)
{
static int g(); /* { dg-error "invalid storage class" } */
int g() {
return i;
}
return g();
}
int l(int i)
{
auto int g();
static int g() { /* { dg-error "invalid storage class" } */
return i;
}
return g();
}
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: pr18596-2.c --]
[-- Type: text/x-csrc, Size: 326 bytes --]
/* { dg-do compile } */
/* { dg-options "" } */
static int barf ();
int foo ()
{
static int bar (); /* { dg-error "invalid storage class" } */
extern int baz ();
auto int bar();
auto int barf ();
int j = 4;
int bar() {
return j;
}
int barf() {
return j;
}
return bar ();
}
static int barf () {
return 3;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-12-02 1:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-01 7:12 Static nested functions James A. Morrison
2004-12-01 7:36 ` Zack Weinberg
2004-12-01 11:05 ` Joseph S. Myers
2004-12-01 17:38 ` Zack Weinberg
2004-12-01 17:43 ` Joseph S. Myers
2004-12-02 1:22 ` James A. Morrison
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).