This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[cs] patch to fix 'empty source file' pedwarn
- From: Per Bothner <per at bothner dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 02 Dec 2003 22:33:27 -0800
- Subject: [cs] patch to fix 'empty source file' pedwarn
I checked this in the compile server.
Without it it is possible to get an erroneous
pedwarn "ISO C forbids an empty source file".
This used to happen building parts of cc1.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
2003-12-02 Per Bothner <pbothner@apple.com>
* c-common.h (nonempty_fragment_reused): New declaration.
* c-common.c (nonempty_fragment_reused): New variable.
(cb_enter_fragment): Set it.
* c-objc-common.c (init_c_objc_common_eachsrc): Clear it.
* c-parse.in (program): Use it in checking for empty source file.
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.438.2.15
diff -u -p -r1.438.2.15 c-common.c
--- c-common.c 3 Dec 2003 02:53:32 -0000 1.438.2.15
+++ c-common.c 3 Dec 2003 06:12:02 -0000
@@ -4410,6 +4410,7 @@ int track_dependencies;
int track_declarations;
int main_timestamp;
int c_timestamp;
+bool nonempty_fragment_reused;
/* Inside an incomplete enum, for example. */
int currently_nested;
@@ -4608,10 +4609,14 @@ cb_enter_fragment (cpp_reader* reader, c
}
else
{
- if (warn_fragment_invalidation && ! fragment->empty)
+ if (! fragment->empty)
{
- inform ("reusing cached fragment");
- fprintf(stderr, "reuse %d lines (start:%d, end:%d)\n", fragment->end_line - fragment->start_line, fragment->start_line, fragment->end_line);
+ nonempty_fragment_reused = true;
+ if (warn_fragment_invalidation)
+ {
+ inform ("reusing cached fragment");
+ fprintf(stderr, "reuse %d lines (start:%d, end:%d)\n", fragment->end_line - fragment->start_line, fragment->start_line, fragment->end_line);
+ }
}
restore_fragment (fragment);
}
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.194.2.10
diff -u -p -r1.194.2.10 c-common.h
--- c-common.h 3 Dec 2003 02:53:36 -0000 1.194.2.10
+++ c-common.h 3 Dec 2003 06:12:02 -0000
@@ -200,6 +200,7 @@ extern int track_dependencies;
extern int track_declarations;
extern int main_timestamp;
extern int c_timestamp;
+extern bool nonempty_fragment_reused;
extern GTY(()) struct c_include_fragment *current_c_fragment;
extern GTY(()) struct c_include_fragment *builtins_c_fragment;
extern struct cpp_fragment *builtins_fragment;
Index: c-objc-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-objc-common.c,v
retrieving revision 1.29.2.7
diff -u -p -r1.29.2.7 c-objc-common.c
--- c-objc-common.c 3 Dec 2003 02:53:36 -0000 1.29.2.7
+++ c-objc-common.c 3 Dec 2003 06:12:02 -0000
@@ -270,6 +270,7 @@ init_c_objc_common_once ()
bool
init_c_objc_common_eachsrc (void)
{
+ nonempty_fragment_reused = false;
init_c_decl_processing_eachsrc ();
cpp_do_macro_callbacks (parse_in, builtins_fragment);
Index: c-parse.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-parse.in,v
retrieving revision 1.176.2.2
diff -u -p -r1.176.2.2 c-parse.in
--- c-parse.in 29 Oct 2003 19:02:39 -0000 1.176.2.2
+++ c-parse.in 3 Dec 2003 06:12:03 -0000
@@ -349,7 +349,7 @@ c_parse_init (void)
%%
program: /* empty */
- { if (pedantic)
+ { if (pedantic && ! nonempty_fragment_reused)
pedwarn ("ISO C forbids an empty source file");
}
| extdefs