public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Bug in traditional cpp in gcc 3.3.2 ?
@ 2003-11-25 15:31 Marc Espie
  2003-11-25 17:01 ` Andreas Schwab
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Espie @ 2003-11-25 15:31 UTC (permalink / raw)
  To: gcc

The following fragment is giving me errors I don't understand.

b.c
#ifdef HAVE_PROTOTYPES
# include <stdarg.h>
# define SH_VA_START(va, argn) va_start(va, argn)
#else
# include <varargs.h>
# define SH_VA_START(va, argn) va_start(va)
#endif /* HAVE_PROTOTYPES */

cpp -traditional-cpp -DHAVE_PROTOTYPES b.c >/dev/null
b.c:6: macro "va_start" requires 2 arguments, but only 1 given

Note that line 6 is the define SH_VA_START which is NOT taken.
What business does traditional-cpp have complaining about a usage
of va_start that doesn't even exist ?

The problem vanishes in non -traditional-cpp mode...

Is there something I'm not getting, or is this a genuine bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug in traditional cpp in gcc 3.3.2 ?
  2003-11-25 15:31 Bug in traditional cpp in gcc 3.3.2 ? Marc Espie
@ 2003-11-25 17:01 ` Andreas Schwab
  2003-11-29 18:14   ` PATCH: work-around for bug in -traditional-cpp Marc Espie
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2003-11-25 17:01 UTC (permalink / raw)
  To: espie; +Cc: gcc

Marc Espie <espie@nerim.net> writes:

> The following fragment is giving me errors I don't understand.
>
> b.c
> #ifdef HAVE_PROTOTYPES
> # include <stdarg.h>
> # define SH_VA_START(va, argn) va_start(va, argn)
> #else
> # include <varargs.h>
> # define SH_VA_START(va, argn) va_start(va)
> #endif /* HAVE_PROTOTYPES */

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.

> Is there something I'm not getting, or is this a genuine bug.

The latter.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 6+ messages in thread

* PATCH: work-around for bug in -traditional-cpp
  2003-11-25 17:01 ` Andreas Schwab
@ 2003-11-29 18:14   ` Marc Espie
  2003-11-29 23:11     ` Neil Booth
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Espie @ 2003-11-29 18:14 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: gcc, gcc-patches

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.  */

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: work-around for bug in -traditional-cpp
  2003-11-29 18:14   ` PATCH: work-around for bug in -traditional-cpp Marc Espie
@ 2003-11-29 23:11     ` Neil Booth
  2003-11-29 23:52       ` Marc Espie
  0 siblings, 1 reply; 6+ messages in thread
From: Neil Booth @ 2003-11-29 23:11 UTC (permalink / raw)
  To: Marc Espie; +Cc: Andreas Schwab, gcc, gcc-patches

Marc Espie wrote:-

> 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.

If you're skipping you shouldn't even be attempting to expand
macros.

Neil.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: work-around for bug in -traditional-cpp
  2003-11-29 23:11     ` Neil Booth
@ 2003-11-29 23:52       ` Marc Espie
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Espie @ 2003-11-29 23:52 UTC (permalink / raw)
  To: Neil Booth; +Cc: Andreas Schwab, gcc, gcc-patches

On Sat, Nov 29, 2003 at 09:50:42PM +0000, Neil Booth wrote:
> > 
> > Okay, it looks like trad-cpp is messing with skipping.
> 
> If you're skipping you shouldn't even be attempting to expand
> macros.

Yes, sure. But I don't think trad-cpp knows whether it's skipping
at this point. It does expand macros early, and then it will use
them or discard them when it finds out whether it's skipping or not.

This is not my code. I'm only concerned about not getting warnings
when I should not get any, e.g., make the code work.

If you can figure what's actually going on, and can clean it up,
that will be fine.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: work-around for bug in -traditional-cpp
       [not found] <bqb9lu$m85$2@clipper.ens.fr>
@ 2003-12-07 18:30 ` Marc Espie
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Espie @ 2003-12-07 18:30 UTC (permalink / raw)
  To: gcc

In article <bqb9lu$m85$2@clipper.ens.fr> you write:
>On Sat, Nov 29, 2003 at 09:50:42PM +0000, Neil Booth wrote:
>> > 
>> > Okay, it looks like trad-cpp is messing with skipping.
>> 
>> If you're skipping you shouldn't even be attempting to expand
>> macros.
>
>Yes, sure. But I don't think trad-cpp knows whether it's skipping
>at this point. It does expand macros early, and then it will use
>them or discard them when it finds out whether it's skipping or not.
>
>This is not my code. I'm only concerned about not getting warnings
>when I should not get any, e.g., make the code work.
>
>If you can figure what's actually going on, and can clean it up,
>that will be fine.
>

Okay, is anybody actually intending to look deeper at this code ?
The work-around I posted actually fixes things for me, and if no-one
wants to search at what's going on deeper, I believe that a preprocessor
without bogus warnings is better than a preprocessor with bogus warnings...

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-12-07 18:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-25 15:31 Bug in traditional cpp in gcc 3.3.2 ? Marc Espie
2003-11-25 17:01 ` Andreas Schwab
2003-11-29 18:14   ` PATCH: work-around for bug in -traditional-cpp Marc Espie
2003-11-29 23:11     ` Neil Booth
2003-11-29 23:52       ` Marc Espie
     [not found] <bqb9lu$m85$2@clipper.ens.fr>
2003-12-07 18:30 ` Marc Espie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).