public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Preserve location in gimple_fold_builtin_memset
@ 2021-10-29  7:50 Jakub Jelinek
  2021-10-29  8:06 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2021-10-29  7:50 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

As mentioned yesterday, gimple_fold_builtin_memset doesn't preserve
locus which means e.g. the -Wstringop-overflow warnings are emitted as:
In function 'test_max':
cc1: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
The function emits up to 2 new statements, but the latter (asgn) is added
through gsi_replace and therefore the locus is copied over from the call.
But store is emitted before the call and optionally the call removed
afterwards, so locus needs to be copied over manually.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2021-10-29  Jakub Jelinek  <jakub@redhat.com>

	* gimple-fold.c (gimple_fold_builtin_memset): Copy over location from
	call to store.

	* gcc.dg/Wstringop-overflow-62.c: Adjust expected diagnostics.

--- gcc/gimple-fold.c.jj	2021-10-12 09:36:57.728450483 +0200
+++ gcc/gimple-fold.c	2021-10-28 12:42:07.638741783 +0200
@@ -1505,6 +1505,7 @@ gimple_fold_builtin_memset (gimple_stmt_
   var = fold_build2 (MEM_REF, etype, dest, build_int_cst (ptr_type_node, 0));
   gimple *store = gimple_build_assign (var, build_int_cst_type (etype, cval));
   gimple_move_vops (store, stmt);
+  gimple_set_location (store, gimple_location (stmt));
   gsi_insert_before (gsi, store, GSI_SAME_STMT);
   if (gimple_call_lhs (stmt))
     {
--- gcc/testsuite/gcc.dg/Wstringop-overflow-62.c.jj	2021-10-28 12:24:21.909780099 +0200
+++ gcc/testsuite/gcc.dg/Wstringop-overflow-62.c	2021-10-28 12:43:52.023273297 +0200
@@ -223,7 +223,7 @@ void test_max (void)
 
     char *q = MAX (pi, pj);
 
-    memset (q, 0, 1);         // { dg-warning "writing 1 byte into a region of size 0 " "" { target *-*-* } 0 }
+    memset (q, 0, 1);         // { dg-warning "writing 1 byte into a region of size 0 " }
     memset (q, 0, 2);         // { dg-warning "writing 2 bytes into a region of size 0 " }
   }
 
@@ -345,7 +345,7 @@ void test_max (void)
        not reflected in the determaxed offset).  */
     char *q = MAX (p1, p2);
 
-    memset (q, 0, 1);
+    memset (q, 0, 1);         // { dg-warning "writing 1 byte into a region of size 0 " }
   }
 
   {

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Preserve location in gimple_fold_builtin_memset
  2021-10-29  7:50 [PATCH] Preserve location in gimple_fold_builtin_memset Jakub Jelinek
@ 2021-10-29  8:06 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-10-29  8:06 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Fri, 29 Oct 2021, Jakub Jelinek wrote:

> Hi!
> 
> As mentioned yesterday, gimple_fold_builtin_memset doesn't preserve
> locus which means e.g. the -Wstringop-overflow warnings are emitted as:
> In function 'test_max':
> cc1: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
> The function emits up to 2 new statements, but the latter (asgn) is added
> through gsi_replace and therefore the locus is copied over from the call.
> But store is emitted before the call and optionally the call removed
> afterwards, so locus needs to be copied over manually.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

OK.

Thanks,
Richard.

> 2021-10-29  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* gimple-fold.c (gimple_fold_builtin_memset): Copy over location from
> 	call to store.
> 
> 	* gcc.dg/Wstringop-overflow-62.c: Adjust expected diagnostics.
> 
> --- gcc/gimple-fold.c.jj	2021-10-12 09:36:57.728450483 +0200
> +++ gcc/gimple-fold.c	2021-10-28 12:42:07.638741783 +0200
> @@ -1505,6 +1505,7 @@ gimple_fold_builtin_memset (gimple_stmt_
>    var = fold_build2 (MEM_REF, etype, dest, build_int_cst (ptr_type_node, 0));
>    gimple *store = gimple_build_assign (var, build_int_cst_type (etype, cval));
>    gimple_move_vops (store, stmt);
> +  gimple_set_location (store, gimple_location (stmt));
>    gsi_insert_before (gsi, store, GSI_SAME_STMT);
>    if (gimple_call_lhs (stmt))
>      {
> --- gcc/testsuite/gcc.dg/Wstringop-overflow-62.c.jj	2021-10-28 12:24:21.909780099 +0200
> +++ gcc/testsuite/gcc.dg/Wstringop-overflow-62.c	2021-10-28 12:43:52.023273297 +0200
> @@ -223,7 +223,7 @@ void test_max (void)
>  
>      char *q = MAX (pi, pj);
>  
> -    memset (q, 0, 1);         // { dg-warning "writing 1 byte into a region of size 0 " "" { target *-*-* } 0 }
> +    memset (q, 0, 1);         // { dg-warning "writing 1 byte into a region of size 0 " }
>      memset (q, 0, 2);         // { dg-warning "writing 2 bytes into a region of size 0 " }
>    }
>  
> @@ -345,7 +345,7 @@ void test_max (void)
>         not reflected in the determaxed offset).  */
>      char *q = MAX (p1, p2);
>  
> -    memset (q, 0, 1);
> +    memset (q, 0, 1);         // { dg-warning "writing 1 byte into a region of size 0 " }
>    }
>  
>    {
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-29  8:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-29  7:50 [PATCH] Preserve location in gimple_fold_builtin_memset Jakub Jelinek
2021-10-29  8:06 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).