This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: work-around for bug in -traditional-cpp
- From: Marc Espie <espie at nerim dot net>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: gcc at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Sat, 29 Nov 2003 16:47:43 +0100
- Subject: PATCH: work-around for bug in -traditional-cpp
- References: <20031125125336.GA3717@tetto.gentiane.org> <jeu14sh92h.fsf@sykes.suse.de>
- Reply-to: espie at nerim dot net
On Tue, Nov 25, 2003 at 02:27:50PM +0100, Andreas Schwab wrote:
> An even simpler test case:
>
> #define a(b,c)
> #if 0
> #define b(x,y) a(x)
> #endif
>
> cpp.c:3: macro "a" requires 2 arguments, but only 1 given
>
> Interestingly, changing #if 0 to #if 1 removes the error.
Okay, it looks like trad-cpp is messing with skipping.
I have at least a work-around for the bug.
It probably means cpp -traditional will no longer emit some needed
warnings, but it will at least stop emitting bogus ones.
2003-11-29 Marc Espie <espie@openbsd.org>
* cpphash.h (_cpp_arguments_ok): Add extra argument.
* cppmacro.c (_cpp_argument_ok, collect_args): Define and use
extra argument silent to remove diagnostic messages.
* cpptrad.c (scan_out_logical_line): Use silent to remove bogus
diagnostic messages.
Index: cpphash.h
===================================================================
RCS file: /cvs/src/gnu/usr.bin/gcc/gcc/cpphash.h,v
retrieving revision 1.1.1.1
diff -c -p -r1.1.1.1 cpphash.h
*** cpphash.h 29 Nov 2003 12:21:46 -0000 1.1.1.1
--- cpphash.h 29 Nov 2003 15:45:22 -0000
*************** extern bool _cpp_save_parameter PARAMS
*** 503,509 ****
cpp_hashnode *));
extern bool _cpp_arguments_ok PARAMS ((cpp_reader *, cpp_macro *,
const cpp_hashnode *,
! unsigned int));
extern const uchar *_cpp_builtin_macro_text PARAMS ((cpp_reader *,
cpp_hashnode *));
int _cpp_warn_if_unused_macro PARAMS ((cpp_reader *, cpp_hashnode *,
--- 503,509 ----
cpp_hashnode *));
extern bool _cpp_arguments_ok PARAMS ((cpp_reader *, cpp_macro *,
const cpp_hashnode *,
! unsigned int, int));
extern const uchar *_cpp_builtin_macro_text PARAMS ((cpp_reader *,
cpp_hashnode *));
int _cpp_warn_if_unused_macro PARAMS ((cpp_reader *, cpp_hashnode *,
Index: cppmacro.c
===================================================================
RCS file: /cvs/src/gnu/usr.bin/gcc/gcc/cppmacro.c,v
retrieving revision 1.1.1.1
diff -c -p -r1.1.1.1 cppmacro.c
*** cppmacro.c 29 Nov 2003 12:21:50 -0000 1.1.1.1
--- cppmacro.c 29 Nov 2003 15:45:23 -0000
*************** paste_all_tokens (pfile, lhs)
*** 520,530 ****
Note that MACRO cannot necessarily be deduced from NODE, in case
NODE was redefined whilst collecting arguments. */
bool
! _cpp_arguments_ok (pfile, macro, node, argc)
cpp_reader *pfile;
cpp_macro *macro;
const cpp_hashnode *node;
unsigned int argc;
{
if (argc == macro->paramc)
return true;
--- 520,531 ----
Note that MACRO cannot necessarily be deduced from NODE, in case
NODE was redefined whilst collecting arguments. */
bool
! _cpp_arguments_ok (pfile, macro, node, argc, silent)
cpp_reader *pfile;
cpp_macro *macro;
const cpp_hashnode *node;
unsigned int argc;
+ int silent;
{
if (argc == macro->paramc)
return true;
*************** _cpp_arguments_ok (pfile, macro, node, a
*** 541,560 ****
if (argc + 1 == macro->paramc && macro->variadic)
{
! if (CPP_PEDANTIC (pfile) && ! macro->syshdr)
cpp_error (pfile, DL_PEDWARN,
"ISO C99 requires rest arguments to be used");
return true;
}
! cpp_error (pfile, DL_ERROR,
! "macro \"%s\" requires %u arguments, but only %u given",
! NODE_NAME (node), macro->paramc, argc);
}
else
! cpp_error (pfile, DL_ERROR,
! "macro \"%s\" passed %u arguments, but takes just %u",
! NODE_NAME (node), argc, macro->paramc);
return false;
}
--- 542,563 ----
if (argc + 1 == macro->paramc && macro->variadic)
{
! if (CPP_PEDANTIC (pfile) && ! macro->syshdr && !silent)
cpp_error (pfile, DL_PEDWARN,
"ISO C99 requires rest arguments to be used");
return true;
}
! if (!silent)
! cpp_error (pfile, DL_ERROR,
! "macro \"%s\" requires %u arguments, but only %u given",
! NODE_NAME (node), macro->paramc, argc);
}
else
! if (!silent)
! cpp_error (pfile, DL_ERROR,
! "macro \"%s\" passed %u arguments, but takes just %u",
! NODE_NAME (node), argc, macro->paramc);
return false;
}
*************** collect_args (pfile, node)
*** 674,680 ****
/* A single empty argument is counted as no argument. */
if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
argc = 0;
! if (_cpp_arguments_ok (pfile, macro, node, argc))
{
/* GCC has special semantics for , ## b where b is a varargs
parameter: we remove the comma if b was omitted entirely.
--- 677,683 ----
/* A single empty argument is counted as no argument. */
if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
argc = 0;
! if (_cpp_arguments_ok (pfile, macro, node, argc, false))
{
/* GCC has special semantics for , ## b where b is a varargs
parameter: we remove the comma if b was omitted entirely.
Index: cpptrad.c
===================================================================
RCS file: /cvs/src/gnu/usr.bin/gcc/gcc/cpptrad.c,v
retrieving revision 1.1.1.1
diff -c -p -r1.1.1.1 cpptrad.c
*** cpptrad.c 29 Nov 2003 12:21:52 -0000 1.1.1.1
--- cpptrad.c 29 Nov 2003 15:45:23 -0000
*************** scan_out_logical_line (pfile, macro)
*** 665,671 ****
&& out == pfile->out.base + fmacro.offset + 1)
fmacro.argc = 0;
! if (_cpp_arguments_ok (pfile, m, fmacro.node, fmacro.argc))
{
/* Remove the macro's invocation from the
output, and push its replacement text. */
--- 665,671 ----
&& out == pfile->out.base + fmacro.offset + 1)
fmacro.argc = 0;
! if (_cpp_arguments_ok (pfile, m, fmacro.node, fmacro.argc, true))
{
/* Remove the macro's invocation from the
output, and push its replacement text. */