This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/32040] New: Including a header file inside a function block results compilation error
- From: "suma dot sharma at kpitcummins dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 22 May 2007 12:17:36 -0000
- Subject: [Bug c/32040] New: Including a header file inside a function block results compilation error
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Hi,
I have successfully built SH4-Linux toolchain based on
(binutils-2.17, gcc-4.2-20061205, glibc-2.5) for Renesas SH target.
I am facing problems while executing the following testcase-
------------------------------------------------------------------
TESTCASE
function()
{
#include<stdio.h>
printf("\nHELLO WORLD");
}
main()
{
function();
}
-------------------------------------------------------------------------
PROBLEM
The above testcase gets compiled with '-O0' optimization successfully,
but on compilation with '-O2' optimization option it gives the following
error:-
In file included from
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/stdio.h:833,
from testcase.c:6:
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h: In
function 'function':
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:35:
error: nested function 'vprintf' declared 'extern'
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:35:
error: static declaration of 'vprintf' follows non-static declaration
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:42:
error: nested function 'getchar' declared 'extern'
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:42:
error: static declaration of 'getchar' follows non-static declaration
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/stdio.h:446:
error: previous declaration of 'getchar' was here
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:51:
error: nested function 'getc_unlocked' declared 'extern'
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:51:
error: static declaration of 'getc_unlocked' follows non-static declaration
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/stdio.h:458:
error: previous declaration of 'getc_unlocked' was here
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:58:
error: nested function 'getchar_unlocked' declared 'extern'
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:58:
error: static declaration of 'getchar_unlocked' follows non-static declaration
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/stdio.h:459:
error: previous declaration of 'getchar_unlocked' was here
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:67:
error: nested function 'putchar' declared 'extern'
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:67:
error: static declaration of 'putchar' follows non-static declaration
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:76:
error: nested function 'fputc_unlocked' declared 'extern'
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:76:
error: static declaration of 'fputc_unlocked' follows non-static declaration
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:86:
error: nested function 'putc_unlocked' declared 'extern'
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:86:
error: static declaration of 'putc_unlocked' follows non-static declaration
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:93:
error: nested function 'putchar_unlocked' declared 'extern'
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:93:
error: static declaration of 'putchar_unlocked' follows non-static declaration
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:113:
error: nested function 'feof_unlocked' declared 'extern'
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:113:
error: static declaration of 'feof_unlocked' follows non-static declaration
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/stdio.h:735:
error: previous declaration of 'feof_unlocked' was here
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:120:
error: nested function 'ferror_unlocked' declared 'extern'
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/bits/stdio.h:120:
error: static declaration of 'ferror_unlocked' follows non-static declaration
/usr/share/gnush4_linux_v0701-1/sh4-linux/sys-root/usr/include/stdio.h:736:
error: previous declaration of 'ferror_unlocked' was here
OBSERVATIONS
1. When "stdio.h" is included outside the function, it compiles with '-O0' as
well as '-O2' optimization options
2. When compiled with '-O0' but enabling all '-O2' flags, it compiles
successfully
(Command Line)
gcc -O0 testcase.c -fthread-jumps -fcrossjumping -foptimize-sibling-calls
-fcse-follow-jumps -fcse-skip-blocks -fgcse -fgcse-lm
-fexpensive-optimizations -fstrength-reduce -frerun-cse-after-loop
-frerun-loop-opt -fcaller-saves -fpeephole2 -fschedule-insns
-fschedule-insns2 -fsched-interblock -fsched-spec -fregmove
-fstrict-aliasing
-fdelete-null-pointer-checks -freorder-blocks -freorder-functions
-funit-at-a-time -falign-functions -falign-jumps -falign-loops
-falign-labels -ftree-vrp -ftree-pre -o all-flags.o -lm
3. When compiled with '-O2' but disabling all '-O2' flags, it does not compile
(Command Line)
sh4-linux-gcc -O2 testcase.c -fno-thread-jumps -fno-crossjumping
-fno-optimize-sibling-calls -fno-cse-follow-jumps -fno-cse-skip-blocks
-fno-gcse -fno-gcse-lm -fno-expensive-optimizations -fno-strength-reduce
-fno-rerun-cse-after-loop -fno-rerun-loop-opt -fno-caller-saves
-fno-peephole2 -fno-schedule-insns -fno-schedule-insns2
-fno-sched-interblock
-fno-sched-spec -fno-regmove -fno-strict-aliasing
-fno-delete-null-pointer-checks -fno-reorder-blocks -fno-reorder-functions
-fno-unit-at-a-time -fno-align-functions -fno-align-jumps -fno-align-loops
-fno-align-labels -fno-tree-vrp -fno-tree-pre -o all-flags.o -lm
4. This problem has been observed with
sh-linux toolchain (gcc-4.2)
i686-pc-linux toolchain (gcc-4.1.1, Fedora Core 6)
i686-pc-linux toolchain (gcc-4.2.0)
Any help on this will be appreciated.
Regards,
Suma Sharma
KPIT Cummins Infosystems Ltd,
Pune (INDIA)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based SH-Linux toolchains for Renesas' SH Series.
The following site also offers free technical support to its users.
Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU SH-Linux tools were released on April 5, 2007.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
Summary: Including a header file inside a function block results
compilation error
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: suma dot sharma at kpitcummins dot com
GCC build triplet: i686-pc-linux
GCC host triplet: sh4-unknown-linux
GCC target triplet: sh4-unknown-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32040