gcc version 3.5.0 20040827 (experimental) A 2.6 kernel compilation encountered a link failure. The following sequence shows how things fail if a function protoype appears inside another function: #define BROKE #ifndef BROKE static void foo(void); #endif int main() { #ifdef BROKE static void foo(void); #endif foo(); } static void foo(void) { printf("bar\n"); } define BROKE and foo disappears completely, undefine it and it works as expected. To be honest Im not even sure this is valid C.
This is not valid C. We should be warning or erroring out.
Subject: Re: Strange behaviour when function prototypes appear inside other functions On Fri, 27 Aug 2004, pinskia at gcc dot gnu dot org wrote: > This is not valid C. > We should be warning or erroring out. To be precise, it's compile-time undefined for block-scope function declarations to have any storage-class specifier other than extern. I don't object to removing this undocumented extension, but this bug report shows it does have users. The problem appears with a compiler from before my patch for bug 13801 went in, so it is not a problem caused by that patch. However, an appropriate fix if we keep the extension would probably be along the lines I suggested for a possible future refinement to that patch: add an internal scope between the external scope and the file scope, which stores hidden declarations of objects and functions with internal linkage used for type checking the same way as the external scope, then merge the handling of static function declarations at block scope with the handling of external and file scope declarations. (So everything with external linkage goes in the external scope, in addition to its proper scope, and everything with internal linkage in a given translation unit goes in the internal scope, in addition to its proper scope, static function declarations at block scope are defined as having internal linkage, and the internal scope, just like the external scope, accumulates composite type information from all declarations, while the file scope and scopes below that have the type information from visible declarations only.) I might look at doing this, but not immediately given the problem isn't caused by my patch.
This is probably related to 12738.
Subject: Bug 17205 CVSROOT: /cvs/gcc Module name: gcc Changes by: geoffk@gcc.gnu.org 2004-08-30 22:19:24 Modified files: gcc : ChangeLog c-decl.c gcc/testsuite : ChangeLog gcc/testsuite/gcc.c-torture/compile: 920625-2.c gcc/testsuite/gcc.c-torture/execute: 20010605-1.c nest-stdar-1.c gcc/testsuite/gcc.dg: 20011130-1.c 20021014-1.c 20030331-2.c Added files: gcc/testsuite/gcc.dg: funcdef-storage-1.c Log message: 2004-08-30 Geoffrey Keating <geoffk@apple.com> PR 12738 PR 17205 Radar 3460526 Radar 3775729 * c-decl.c (grokdeclarator): Produce error for 'static' on local function declaration. Index: testsuite/ChangeLog 2004-08-30 Geoffrey Keating <geoffk@apple.com> * gcc.dg/funcdef-storage-1.c: New. * gcc.c-torture/compile/920625-2.c: Don't use 'static' to declare an extern function in local scope. * gcc.c-torture/execute/20010605-1.c: Don't use 'static inline' to declare an 'auto inline' function in local scope. * gcc.dg/20011130-1.c: Likewise. * gcc.c-torture/execute/nest-stdar-1.c: Don't use 'static' to declare an 'auto' function in local scope. * gcc.dg/20021014-1.c: Likewise. * gcc.dg/20030331-2.c: Likewise. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.5161&r2=2.5162 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.565&r2=1.566 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4211&r2=1.4212 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/920625-2.c.diff?cvsroot=gcc&r1=1.2&r2=1.3 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20010605-1.c.diff?cvsroot=gcc&r1=1.2&r2=1.3 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/nest-stdar-1.c.diff?cvsroot=gcc&r1=1.2&r2=1.3 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/funcdef-storage-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20011130-1.c.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20021014-1.c.diff?cvsroot=gcc&r1=1.10&r2=1.11 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20030331-2.c.diff?cvsroot=gcc&r1=1.3&r2=1.4
Fixed, by declaring this code invalid and producing an error message on it. The kernel will need to be changed to Not Do That, by moving the prototype for the 'static' function to file scope.
Subject: Bug 17205 CVSROOT: /cvs/gcc Module name: gcc Branch: apple-ppc-branch Changes by: geoffk@gcc.gnu.org 2004-09-01 22:12:16 Modified files: gcc : c-decl.c gcc/testsuite/gcc.c-torture/compile: 920625-2.c gcc/testsuite/gcc.c-torture/execute: 20010605-1.c nest-stdar-1.c gcc/testsuite/gcc.dg: 20011130-1.c 20021014-1.c 20030331-2.c Added files: gcc/testsuite/gcc.dg: funcdef-storage-1.c Log message: PR 12738 PR 17205 Radar 3460526 Radar 3775729 * c-decl.c (grokdeclarator): Produce error for 'static' on local function declaration. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&only_with_tag=apple-ppc-branch&r1=1.334.2.87.2.19&r2=1.334.2.87.2.20 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/920625-2.c.diff?cvsroot=gcc&only_with_tag=apple-ppc-branch&r1=1.2&r2=1.2.116.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20010605-1.c.diff?cvsroot=gcc&only_with_tag=apple-ppc-branch&r1=1.2&r2=1.2.92.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/nest-stdar-1.c.diff?cvsroot=gcc&only_with_tag=apple-ppc-branch&r1=1.2&r2=1.2.116.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/funcdef-storage-1.c.diff?cvsroot=gcc&only_with_tag=apple-ppc-branch&r1=NONE&r2=1.2.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20011130-1.c.diff?cvsroot=gcc&only_with_tag=apple-ppc-branch&r1=1.1&r2=1.1.88.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20021014-1.c.diff?cvsroot=gcc&only_with_tag=apple-ppc-branch&r1=1.1.8.9&r2=1.1.8.9.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20030331-2.c.diff?cvsroot=gcc&only_with_tag=apple-ppc-branch&r1=1.2.4.1.8.1&r2=1.2.4.1.8.2