This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Exit code for errors detected by cpplib
- To: gcc-patches at gcc dot gnu dot org
- Subject: Exit code for errors detected by cpplib
- From: Nick Clifton <nickc at cygnus dot com>
- Date: Mon, 29 Nov 1999 19:09:25 GMT
- Reply-to: nickc at cygnus dot co dot uk
Hi Guys,
This is a patch to fix a minor problem with cpplib. Currently if
cpplib detects any errors, this will not be reflected in the status
code returned by gcc/g++. The patch fixes this problem by
maintaining a count of the number of errors encountered by cpplib,
and then having the C and C++ front ends check this value and if it
is non-zero, signaling this to main() by increasing the global error
count.
May I apply this patch ?
Cheers
Nick
1999-11-29 Nick Clifton <nickc@cygnus.com>
* cpplib.c (cpp_errors): New static variable: a count of the
number of errors encounterd by cpplib.
(cpp_error_from_errno): Increment cpp_errors.
(cpp_perror_with_name): Increment cpp_errors.
(cpp_get_num_errors): New Function: return the number of
errors encountered by cpplib so far.
(cpp_set_num_errors): New Function: set the number of errors
encountered by cpplib so far.
* cppinit.c (initialize_builtins): Initialise error count to
zero.
* cpplib.h: Declare prototypes for cpp_get_num_errors() and
cpp_set_num_errors().
* c-decl.c (finish_function): Is using cpplib, check to see if
any errors were detected.
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplib.c,v
retrieving revision 1.96
diff -p -r1.96 cpplib.c
*** cpplib.c 1999/10/29 04:31:13 1.96
--- cpplib.c 1999/11/29 19:05:07
*************** do_sccs (pfile, keyword)
*** 1677,1682 ****
--- 1677,1683 ----
}
#endif
+ static unsigned int cpp_errors;
/* We've found an `#if' directive. If the only thing before it in
this file is white space, and if it is of the form
*************** cpp_error_from_errno (pfile, name)
*** 3512,3517 ****
--- 3513,3519 ----
const char *name;
{
cpp_message_from_errno (pfile, 1, name);
+ ++ cpp_errors;
}
void
*************** cpp_perror_with_name (pfile, name)
*** 3537,3542 ****
--- 3539,3558 ----
const char *name;
{
cpp_message (pfile, 1, "%s: %s: %s", progname, name, my_strerror (errno));
+ ++ cpp_errors;
+ }
+
+ unsigned int
+ cpp_get_num_errors ()
+ {
+ return cpp_errors;
+ }
+
+ void
+ cpp_get_num_errors (num)
+ unsigned int num;
+ {
+ cpp_errors = num;
}
/* TODO:
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cppinit.c,v
retrieving revision 1.25
diff -p -r1.25 cppinit.c
*** cppinit.c 1999/11/18 11:01:34 1.25
--- cppinit.c 1999/11/29 19:05:08
*************** initialize_builtins (pfile)
*** 573,578 ****
--- 573,579 ----
dump_special_to_buffer (pfile, b->name);
}
+ cpp_set_num_errors (0);
}
#undef DUMP
#undef STDC
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplib.h,v
retrieving revision 1.44
diff -p -r1.44 cpplib.h
*** cpplib.h 1999/10/29 04:31:14 1.44
--- cpplib.h 1999/11/29 19:05:08
*************** extern void cpp_message_from_errno PROTO
*** 732,737 ****
--- 732,739 ----
extern void cpp_error_from_errno PROTO ((cpp_reader *, const char *));
extern void cpp_perror_with_name PROTO ((cpp_reader *, const char *));
extern void v_cpp_message PROTO ((cpp_reader *, int, const char *, va_list));
+ extern unsigned int cpp_get_num_errors PROTO ((void));
+ extern void cpp_set_num_errors PROTO ((unsigned int));
extern void cpp_grow_buffer PARAMS ((cpp_reader *, long));
extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-decl.c,v
retrieving revision 1.90
diff -p -r1.90 c-decl.c
*** c-decl.c 1999/11/25 16:58:31 1.90
--- c-decl.c 1999/11/29 19:05:10
*************** finish_function (nested)
*** 6813,6818 ****
--- 6813,6825 ----
pop_c_function_context and then reset via pop_function_context. */
current_function_decl = NULL;
}
+
+ #ifdef USE_CPPLIB
+ /* Make sure that any errors detected by cpplib get reflected in the
+ exit status of gcc. */
+ if (cpp_get_num_errors ())
+ ++ errorcount;
+ #endif
}
/* Save and restore the variables in this file and elsewhere
1999-11-29 Nick Clifton <nickc@cygnus.com>
* decl.c (finish_function): Is using cpplib, check to see if
any errors were detected.
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl.c,v
retrieving revision 1.510
diff -p -r1.510 decl.c
*** decl.c 1999/11/25 20:32:03 1.510
--- decl.c 1999/11/29 19:05:15
*************** finish_function (lineno, flags)
*** 13794,13799 ****
--- 13794,13806 ----
current_function_decl = NULL_TREE;
}
+ #ifdef USE_CPPLIB
+ /* Make sure that any errors detected by cpplib get reflected in the
+ exit status of g++. */
+ if (cpp_get_num_errors ())
+ ++ errorcount;
+ #endif
+
return fndecl;
}