PR tree-optimization/83369 - Missing diagnostics during inlining
authorMartin Sebor <msebor@redhat.com>
Mon, 5 Feb 2018 22:45:04 +0000 (22:45 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Mon, 5 Feb 2018 22:45:04 +0000 (15:45 -0700)
gcc/ChangeLog:

PR tree-optimization/83369
* tree-ssa-ccp.c (pass_post_ipa_warn::execute): Use %G to print
inlining context.

gcc/testsuite/ChangeLog:

PR tree-optimization/83369
gcc.dg/Wnonnull.c: New test.

From-SVN: r257400

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wnonnull.c [new file with mode: 0644]
gcc/tree-ssa-ccp.c

index e5a8c11b30390baeb9755e94d77b7e463a0515a8..12d238ebc3e1e7387654a6efd6f5151d0497bd56 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-05  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/83369
+       * tree-ssa-ccp.c (pass_post_ipa_warn::execute): Use %G to print
+       inlining context.
+
 2018-02-05  Martin Liska  <mliska@suse.cz>
 
        * doc/invoke.texi: Cherry-pick upstream r323995.
index 62ee8f2a26a224b580f79f4412aaae7026aeb978..41dae445f1fbd6b6dd79c54efa08c149cde6327e 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-05  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/83369
+       gcc.dg/Wnonnull.c: New test.
+
 2018-02-05  Richard Sandiford  <richard.sandiford@linaro.org>
 
        * lib/lto.exp (lto_handle_diagnostics): Remove messages_by_file
diff --git a/gcc/testsuite/gcc.dg/Wnonnull.c b/gcc/testsuite/gcc.dg/Wnonnull.c
new file mode 100644 (file)
index 0000000..be89a5a
--- /dev/null
@@ -0,0 +1,41 @@
+/* PR tree-optimization/83369 - Missing diagnostics during inlining
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+#include <string.h>
+
+char buf[100];
+
+struct Test
+{
+  const char* s1;
+  const char* s2;
+};
+
+__attribute ((nonnull (1, 2)))
+inline char*
+my_strcpy (char *restrict dst, const char *restrict src, size_t size)
+{
+  size_t len = strlen (src);        /* { dg-warning "argument 1 null where non-null expected" } */
+  if (len < size)
+    memcpy (dst, src, len + 1);     /* { dg-warning "argument 2 null where non-null expected" } */
+  else
+    {
+      memcpy (dst, src, size - 1);  /* { dg-warning "argument 2 null where non-null expected" } */
+      dst[size - 1] = '\0';
+    }
+  return dst;
+}
+
+void test (struct Test* test)
+{
+  if (test->s1)
+    my_strcpy (buf, test->s1, sizeof buf);
+  else if (test->s2)
+    my_strcpy (buf, test->s2, sizeof buf);
+  else
+    my_strcpy (buf, test->s2, sizeof buf);
+}
+
+/* Verify that the inlining context is printed for -Wnonnull:
+   { dg-message "function .my_strcpy..*inlined from .test." "" { target *-*-* } 0 }  */
index 5bae9a7fee5cb76f4fcc9ca00f47847d3eabbb56..5591097d0183270879b7856c81a37a23781449f1 100644 (file)
@@ -3458,8 +3458,8 @@ pass_post_ipa_warn::execute (function *fun)
 
                      location_t loc = gimple_location (stmt);
                      if (warning_at (loc, OPT_Wnonnull,
-                                     "argument %u null where non-null "
-                                     "expected", i + 1))
+                                     "%Gargument %u null where non-null "
+                                     "expected", as_a <gcall *>(stmt), i + 1))
                        {
                          tree fndecl = gimple_call_fndecl (stmt);
                          if (fndecl && DECL_IS_BUILTIN (fndecl))