Bug 81794 - "would be stringified in traditional C" warning should be controlled by -Wtraditional
Summary: "would be stringified in traditional C" warning should be controlled by -Wtra...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL: https://gcc.gnu.org/ml/gcc-patches/20...
Keywords: diagnostic, easyhack, patch
Depends on:
Blocks:
 
Reported: 2017-08-10 11:39 UTC by Eric Gallager
Modified: 2017-11-21 11:52 UTC (History)
1 user (show)

See Also:
Host: i386-apple-darwin9.8.0
Target: i386-apple-darwin9.8.0
Build: i386-apple-darwin9.8.0
Known to work:
Known to fail:
Last reconfirmed: 2017-08-18 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Gallager 2017-08-10 11:39:34 UTC
Opening a bug to track the underlying issue that caused me to submit this patch:
https://gcc.gnu.org/ml/gcc-patches/2017-05/msg00481.html
https://gcc.gnu.org/ml/gcc-patches/2017-03/msg01325.html

When compiling my fork of binutils-gdb, I get a lot of warnings like this one on one file:

unwind-ia64.c:183:30: warning: macro argument "code" would be stringified in traditional C
 #define UNW_DEC_BAD_CODE(code)   \
                              ^

To reduce it to a testcase, we can modify gcc.dg/pragma-diag-7.c to look like this:

$ cat pragma-diag-7.c
/* { dg-do compile } */

unsigned long ok = 0UL;
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wtraditional"
unsigned long bad = 1UL; /* { dg-warning "suffix" } */
/* Note the extra space before the pragma on this next line: */
 #pragma GCC diagnostic pop
unsigned long ok_again = 2UL; /* { dg-bogus "suffix" } */

/* Redundant with the previous pop, but just shows that it fails to stop the
 * following warning with an unpatched GCC: */
#pragma GCC diagnostic ignored "-Wtraditional"

/* { dg-bogus "would be stringified" .+1 } */
#define UNW_DEC_PROLOGUE(fmt, body, rlen, arg) \
  do {									\
      unw_rlen = rlen;							\
      *(int *)arg = body;						\
      printf("    %s:%s(rlen=%lu)\n",					\
             fmt, (body ? "body" : "prologue"), (unsigned long)rlen);	\
  } while (0)
$ /usr/local/bin/gcc -c pragma-diag-7.c
pragma-diag-7.c:6:21: warning: traditional C rejects the "UL" suffix [-Wtraditional]
 unsigned long bad = 1UL; /* { dg-warning "suffix" } */
                     ^~~
pragma-diag-7.c:16:46: warning: macro argument "rlen" would be stringified in traditional C
 #define UNW_DEC_PROLOGUE(fmt, body, rlen, arg) \
                                              ^
pragma-diag-7.c:16:46: warning: macro argument "body" would be stringified in traditional C
$ 

To get rid of the unwanted warnings, all that is necessary is a 1-line patch to libcpp/macro.c to change a call to cpp_error with CPP_DL_WARNING into a call to cpp_warning with CPP_W_TRADITIONAL instead. The patch is already linked above.
Comment 1 Martin Sebor 2017-08-18 17:17:47 UTC
Confirmed.  Please keep pinging the patch weekly until it's reviewed.
Comment 2 David Malcolm 2017-08-18 17:50:15 UTC
Please can you turn it into a patch that contains both the fix *and* the new testcase?  (e.g. gcc.dg/pragma-diag-8.c)
Comment 3 Eric Gallager 2017-08-19 17:46:04 UTC
(In reply to David Malcolm from comment #2)
> Please can you turn it into a patch that contains both the fix *and* the new
> testcase?  (e.g. gcc.dg/pragma-diag-8.c)

I will once I get some issues with my email sorted out...
Comment 4 Eric Gallager 2017-09-18 00:02:09 UTC
(In reply to Eric Gallager from comment #3)
> (In reply to David Malcolm from comment #2)
> > Please can you turn it into a patch that contains both the fix *and* the new
> > testcase?  (e.g. gcc.dg/pragma-diag-8.c)
> 
> I will once I get some issues with my email sorted out...

OK here you go: https://gcc.gnu.org/ml/gcc-patches/2017-09/msg01107.html
Comment 5 David Malcolm 2017-11-21 00:58:01 UTC
Author: dmalcolm
Date: Tue Nov 21 00:57:29 2017
New Revision: 254981

URL: https://gcc.gnu.org/viewcvs?rev=254981&root=gcc&view=rev
Log:
Use -Wtraditional for "would be stringified in traditional C" (PR preprocessor/81794)

libcpp/ChangeLog:

2017-03-24  Eric Gallager  <egall@gwmail.gwu.edu>

	PR preprocessor/81794
	* macro.c (check_trad_stringification): Have warning be controlled
	by -Wtraditional.

gcc/testsuite/ChangeLog:

2017-09-17  Eric Gallager  <egall@gwmail.gwu.edu>

	PR preprocessor/81794
	* gcc.dg/pragma-diag-7.c: Update to include check for
	stringification.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/pragma-diag-7.c
    trunk/libcpp/ChangeLog
    trunk/libcpp/macro.c
Comment 6 David Malcolm 2017-11-21 00:58:32 UTC
Should be fixed by r254981; marking as resolved.
Comment 7 Eric Gallager 2017-11-21 11:52:02 UTC
(In reply to David Malcolm from comment #6)
> Should be fixed by r254981; marking as resolved.

Thank you!