Commit be4aa83d by David Malcolm Committed by David Malcolm

Don't suppress bogus usage of macros from system headers in -Wformat (PR c/78304)

gcc/ChangeLog:
	PR c/78304
	* substring-locations.c (format_warning_va): Strengthen case 1 so
	that both endpoints of the substring must be within the format
	range for just the substring to be printed.

gcc/testsuite/ChangeLog:
	PR c/78304
	* gcc.dg/format/diagnostic-ranges.c (test_macro): Undef INT_FMT.
	(test_macro_2): New test.
	(test_macro_3): New test.
	(test_macro_4): New test.
	(test_non_contiguous_strings): Convert line number to line offset.
	* gcc.dg/format/pr78304-2.c: New test case.
	* gcc.dg/format/pr78304.c: New test case.

From-SVN: r244453
parent 7cdca3ec
2017-01-13 David Malcolm <dmalcolm@redhat.com>
PR c/78304
* substring-locations.c (format_warning_va): Strengthen case 1 so
that both endpoints of the substring must be within the format
range for just the substring to be printed.
2017-01-13 Uros Bizjak <ubizjak@gmail.com>
* config/i386/i386.opt (msgx): Use ix86_isa_flags2 variable.
......
......@@ -118,6 +118,8 @@ format_warning_va (const substring_loc &fmt_loc,
else
{
if (fmt_substring_range.m_start >= fmt_loc_range.m_start
&& fmt_substring_range.m_start <= fmt_loc_range.m_finish
&& fmt_substring_range.m_finish >= fmt_loc_range.m_start
&& fmt_substring_range.m_finish <= fmt_loc_range.m_finish)
/* Case 1. */
{
......
2017-01-13 David Malcolm <dmalcolm@redhat.com>
PR c/78304
* gcc.dg/format/diagnostic-ranges.c (test_macro): Undef INT_FMT.
(test_macro_2): New test.
(test_macro_3): New test.
(test_macro_4): New test.
(test_non_contiguous_strings): Convert line number to line offset.
* gcc.dg/format/pr78304-2.c: New test case.
* gcc.dg/format/pr78304.c: New test case.
2017-01-13 Uros Bizjak <ubizjak@gmail.com>
* gcc.target/i386/funcspec-56.inc: Add missing options and
......
......@@ -254,12 +254,63 @@ void test_macro (const char *msg)
~^
%s
{ dg-end-multiline-output "" } */
#undef INT_FMT
}
void test_macro_2 (const char *msg)
{
#define PRIu32 "u" /* { dg-message "17: format string is defined here" } */
printf("hello %" PRIu32 " world", msg); /* { dg-warning "10: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'const char \\*' " } */
/* { dg-begin-multiline-output "" }
printf("hello %" PRIu32 " world", msg);
^~~~~~~~~
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
#define PRIu32 "u"
^
{ dg-end-multiline-output "" } */
#undef PRIu32
}
void test_macro_3 (const char *msg)
{
#define FMT_STRING "hello %i world" /* { dg-warning "20: format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */
printf(FMT_STRING, msg); /* { dg-message "10: in expansion of macro 'FMT_STRING" } */
/* { dg-begin-multiline-output "" }
#define FMT_STRING "hello %i world"
^
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
printf(FMT_STRING, msg);
^~~~~~~~~~
{ dg-end-multiline-output "" } */
#undef FMT_STRING
}
void test_macro_4 (const char *msg)
{
#define FMT_STRING "hello %i world" /* { dg-warning "20: format '%i' expects argument of type 'int', but argument 2 has type 'const char \\*' " } */
printf(FMT_STRING "\n", msg); /* { dg-message "10: in expansion of macro 'FMT_STRING" } */
/* { dg-begin-multiline-output "" }
#define FMT_STRING "hello %i world"
^
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
printf(FMT_STRING "\n", msg);
^~~~~~~~~~
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
#define FMT_STRING "hello %i world"
~^
%s
{ dg-end-multiline-output "" } */
#undef FMT_STRING
}
void test_non_contiguous_strings (void)
{
__builtin_printf(" %" "d ", 0.5); /* { dg-warning "20: format .%d. expects argument of type .int., but argument 2 has type .double." } */
/* { dg-message "26: format string is defined here" "" { target *-*-* } 261 } */
/* { dg-message "26: format string is defined here" "" { target *-*-* } .-1 } */
/* { dg-begin-multiline-output "" }
__builtin_printf(" %" "d ", 0.5);
^~~~
......
/* { dg-do compile } */
/* { dg-options "-O2 -Wall -Wextra" } */
extern int printf (const char *, ...);
# define PRIu32 "u"
void test (long size)
{
printf ("size: %" PRIu32 "\n", size); /* { dg-warning "expects argument of type" } */
}
/* { dg-do compile { target inttypes_types } } */
/* { dg-options "-O2 -Wall -Wextra" } */
#include <inttypes.h>
#include <stdio.h>
void test (size_t size)
{
printf ("size: %" PRIu32 "\n", size); /* { dg-warning "expects argument of type" } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment