aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/substring-locations.c2
-rw-r--r--gcc/testsuite/ChangeLog11
-rw-r--r--gcc/testsuite/gcc.dg/format/diagnostic-ranges.c53
-rw-r--r--gcc/testsuite/gcc.dg/format/pr78304-2.c11
-rw-r--r--gcc/testsuite/gcc.dg/format/pr78304.c10
6 files changed, 93 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b303681..3c74b19 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+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.
diff --git a/gcc/substring-locations.c b/gcc/substring-locations.c
index 8b41f2b..e2d8dd7 100644
--- a/gcc/substring-locations.c
+++ b/gcc/substring-locations.c
@@ -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. */
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f9b6188..76dfd7e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,14 @@
+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
diff --git a/gcc/testsuite/gcc.dg/format/diagnostic-ranges.c b/gcc/testsuite/gcc.dg/format/diagnostic-ranges.c
index e5e6ade..cab30f2 100644
--- a/gcc/testsuite/gcc.dg/format/diagnostic-ranges.c
+++ b/gcc/testsuite/gcc.dg/format/diagnostic-ranges.c
@@ -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);
^~~~
diff --git a/gcc/testsuite/gcc.dg/format/pr78304-2.c b/gcc/testsuite/gcc.dg/format/pr78304-2.c
new file mode 100644
index 0000000..5ee6d65
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/pr78304-2.c
@@ -0,0 +1,11 @@
+/* { 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" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/pr78304.c b/gcc/testsuite/gcc.dg/format/pr78304.c
new file mode 100644
index 0000000..d0a96f6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/pr78304.c
@@ -0,0 +1,10 @@
+/* { 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" } */
+}