aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-10-29 10:20:29 +0200
committerJakub Jelinek <jakub@redhat.com>2021-10-29 10:20:29 +0200
commitf1ba6a819de6f4aacf9d69725f64496d20edd5a1 (patch)
tree27bc21a1517537e9c1e2e62e2b30e6aad573e226 /gcc
parent4cd2a27a1c910421b31fd72dea726d838c1a39e9 (diff)
downloadgcc-f1ba6a819de6f4aacf9d69725f64496d20edd5a1.zip
gcc-f1ba6a819de6f4aacf9d69725f64496d20edd5a1.tar.gz
gcc-f1ba6a819de6f4aacf9d69725f64496d20edd5a1.tar.bz2
gimple-fold: Preserve location in gimple_fold_builtin_memset
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. 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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gimple-fold.c1
-rw-r--r--gcc/testsuite/gcc.dg/Wstringop-overflow-62.c4
2 files changed, 3 insertions, 2 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 7fcfef4..6e25a7c 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -1505,6 +1505,7 @@ gimple_fold_builtin_memset (gimple_stmt_iterator *gsi, tree c, tree len)
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))
{
diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-62.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-62.c
index e39ab2f..ea19aa8 100644
--- a/gcc/testsuite/gcc.dg/Wstringop-overflow-62.c
+++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-62.c
@@ -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 " }
}
{