This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] use fallback location for warning (PR 91599)


warning_at() calls with the %G directive rely on the gimple statement
for both their location and the inlining context.  When the statement
is not associated with a location, the warning doesn't point at any
line even if the location argument passed to the call was valid.
The attached patch changes the percent_G_percent handler to fall back
on the provided location in that case, and the recently added warning
for char assignments to pass to the function a fallback location if
the statement doesn't have one.

Tested on x86_64-linux.

Martin
PR middle-end/91599 - GCC does not say where warning is happening

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.

Index: gcc/tree-ssa-strlen.c
===================================================================
--- gcc/tree-ssa-strlen.c	(revision 275047)
+++ gcc/tree-ssa-strlen.c	(working copy)
@@ -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",
Index: gcc/gimple-pretty-print.c
===================================================================
--- gcc/gimple-pretty-print.c	(revision 275047)
+++ gcc/gimple-pretty-print.c	(working copy)
@@ -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: gcc/testsuite/gcc.dg/Wstringop-overflow-16.c
===================================================================
--- gcc/testsuite/gcc.dg/Wstringop-overflow-16.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/Wstringop-overflow-16.c	(working copy)
@@ -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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]