PR middle-end/91599 - GCC does not say where warning is happening
authorMartin Sebor <msebor@redhat.com>
Fri, 30 Aug 2019 17:49:17 +0000 (17:49 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Fri, 30 Aug 2019 17:49:17 +0000 (11:49 -0600)
gcc/ChangeLog:

PR middle-end/91599
* tree-ssa-strlen.c (handle_store): Use a fallback location if
the statement doesn't have one.
* gimple-pretty-print.c (percent_G_format): Same.

gcc/testsuite/ChangeLog:

PR middle-end/91599
* gcc.dg/Wstringop-overflow-16.c: New test.

From-SVN: r275211

gcc/ChangeLog
gcc/gimple-pretty-print.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wstringop-overflow-16.c [new file with mode: 0644]
gcc/tree-ssa-strlen.c

index 45dd3a28012b27b86311ce0459ff6dde59e4eacf..1a8026c63f2dd5228d3d13460ed250135e4f8dca 100644 (file)
@@ -1,5 +1,10 @@
 2019-08-30  Martin Sebor  <msebor@redhat.com>
 
+       PR middle-end/91599
+       * tree-ssa-strlen.c (handle_store): Use a fallback location if
+       the statement doesn't have one.
+       * gimple-pretty-print.c (percent_G_format): Same.
+
        PR middle-end/91584
        * tree-vrp.c (vrp_prop::check_mem_ref): Normalize type domain bounds
        before using them to validate MEM_REF offset.
index ce339eeddac40806b3d2c7d5d6c4b5e3bf35b104..2d5ece0680538389118b909951863be50d570326 100644 (file)
@@ -3034,8 +3034,12 @@ percent_G_format (text_info *text)
 {
   gimple *stmt = va_arg (*text->args_ptr, gimple*);
 
+  /* Fall back on the rich location if the statement doesn't have one.  */
+  location_t loc = gimple_location (stmt);
+  if (loc == UNKNOWN_LOCATION)
+    loc = text->m_richloc->get_loc ();
   tree block = gimple_block (stmt);
-  percent_K_format (text, gimple_location (stmt), block);
+  percent_K_format (text, loc, block);
 }
 
 #if __GNUC__ >= 10
index 420ddd49b1f1153229e5fc34a0b6a92bbba70146..83d17a38f6c6fb3f50453951d1b085d33976e6b1 100644 (file)
@@ -1,5 +1,8 @@
 2019-08-30  Martin Sebor  <msebor@redhat.com>
 
+       PR middle-end/91599
+       * gcc.dg/Wstringop-overflow-16.c: New test.
+
        PR middle-end/91584
        * gfortran.dg/char_array_constructor_4.f90: New test.
 
diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-16.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-16.c
new file mode 100644 (file)
index 0000000..74548a4
--- /dev/null
@@ -0,0 +1,21 @@
+/* PR middle-end/91599 - GCC does not say where warning is happening
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+struct charseq {
+  unsigned char bytes[0];         // { dg-message "object declared here" }
+};
+
+struct locale_ctype_t {
+  struct charseq *mboutdigits[10];
+};
+
+void ctype_finish (struct locale_ctype_t *ctype)
+{
+  long unsigned int cnt;
+  for (cnt = 0; cnt < 20; ++cnt) {
+    static struct charseq replace[2];
+    replace[0].bytes[1] = '\0';   // { dg-warning "\\\[-Wstringop-overflow" }
+    ctype->mboutdigits[cnt] = &replace[0];
+  }
+}
index 7bb5f52c1e5dded6a3e81a4086e4e3e79cef469d..b9793207a719ea66cbd426ef7166fc33957fc82b 100644 (file)
@@ -4036,7 +4036,12 @@ handle_store (gimple_stmt_iterator *gsi)
          if (tree dstsize = compute_objsize (lhs, 1, &decl))
            if (compare_tree_int (dstsize, lenrange[2]) < 0)
              {
+               /* Fall back on the LHS location if the statement
+                  doesn't have one.  */
                location_t loc = gimple_nonartificial_location (stmt);
+               if (loc == UNKNOWN_LOCATION)
+                 loc = tree_nonartificial_location (lhs);
+               loc = expansion_point_location_if_in_system_header (loc);
                if (warning_n (loc, OPT_Wstringop_overflow_,
                               lenrange[2],
                               "%Gwriting %u byte into a region of size %E",