* [PATCH] gimple-fold: fix further missing stmt locations [PR104308]
@ 2022-04-14 13:24 David Malcolm
2022-04-19 11:03 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: David Malcolm @ 2022-04-14 13:24 UTC (permalink / raw)
To: gcc-patches
PR analyzer/104308 initially reported about a
-Wanalyzer-use-of-uninitialized-value diagnostic using UNKNOWN_LOCATION
when complaining about certain memmove operations where the source
is uninitialized.
In r12-7856-g875342766d4298 I fixed the missing location for
a stmt generated by gimple_fold_builtin_memory_op, but the reporter
then found another way to generate such a stmt with UNKNOWN_LOCATION.
I've now gone through gimple_fold_builtin_memory_op looking at all
statement creation, and found three places in which a new statement
doesn't have a location set on it (either directly via
gimple_set_location, or indirectly via gsi_replace), one of which is
the new reproducer.
This patch adds a gimple_set_location to these three cases, and adds
test coverage for one of them (the third hunk within the patch), fixing
the new reproducer for PR analyzer/104308.
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
OK for trunk in stage 4? Or in stage 1?
Thanks
Dave
gcc/ChangeLog:
PR analyzer/104308
* gimple-fold.cc (gimple_fold_builtin_memory_op): Explicitly set
the location of new_stmt in all places that don't already set it,
whether explicitly, or via a call to gsi_replace.
gcc/testsuite/ChangeLog:
PR analyzer/104308
* gcc.dg/analyzer/pr104308.c: Add test coverage.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
gcc/gimple-fold.cc | 3 +++
gcc/testsuite/gcc.dg/analyzer/pr104308.c | 13 ++++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index ac22adfd9b1..863ee3d3912 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -1048,6 +1048,7 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
gsi_replace (gsi, new_stmt, false);
return true;
}
+ gimple_set_location (new_stmt, loc);
gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
goto done;
}
@@ -1302,6 +1303,7 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
new_stmt);
gimple_assign_set_lhs (new_stmt, srcvar);
gimple_set_vuse (new_stmt, gimple_vuse (stmt));
+ gimple_set_location (new_stmt, loc);
gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
}
new_stmt = gimple_build_assign (destvar, srcvar);
@@ -1338,6 +1340,7 @@ set_vop_and_replace:
gsi_replace (gsi, new_stmt, false);
return true;
}
+ gimple_set_location (new_stmt, loc);
gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
}
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr104308.c b/gcc/testsuite/gcc.dg/analyzer/pr104308.c
index 9cd5ee6feee..a3a0cbb7317 100644
--- a/gcc/testsuite/gcc.dg/analyzer/pr104308.c
+++ b/gcc/testsuite/gcc.dg/analyzer/pr104308.c
@@ -1,8 +1,19 @@
+/* Verify that we have source locations for
+ -Wanalyzer-use-of-uninitialized-value warnings involving folded
+ memory ops. */
+
#include <string.h>
-int main()
+int test_memmove_within_uninit (void)
{
char s[5]; /* { dg-message "region created on stack here" } */
memmove(s, s + 1, 2); /* { dg-warning "use of uninitialized value" } */
return 0;
}
+
+int test_memcpy_from_uninit (void)
+{
+ char a1[5];
+ char a2[5]; /* { dg-message "region created on stack here" } */
+ return (memcpy(a1, a2, 5) == a1); /* { dg-warning "use of uninitialized value" } */
+}
--
2.26.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] gimple-fold: fix further missing stmt locations [PR104308]
2022-04-14 13:24 [PATCH] gimple-fold: fix further missing stmt locations [PR104308] David Malcolm
@ 2022-04-19 11:03 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-04-19 11:03 UTC (permalink / raw)
To: David Malcolm; +Cc: GCC Patches
On Thu, Apr 14, 2022 at 3:25 PM David Malcolm via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> PR analyzer/104308 initially reported about a
> -Wanalyzer-use-of-uninitialized-value diagnostic using UNKNOWN_LOCATION
> when complaining about certain memmove operations where the source
> is uninitialized.
>
> In r12-7856-g875342766d4298 I fixed the missing location for
> a stmt generated by gimple_fold_builtin_memory_op, but the reporter
> then found another way to generate such a stmt with UNKNOWN_LOCATION.
>
> I've now gone through gimple_fold_builtin_memory_op looking at all
> statement creation, and found three places in which a new statement
> doesn't have a location set on it (either directly via
> gimple_set_location, or indirectly via gsi_replace), one of which is
> the new reproducer.
>
> This patch adds a gimple_set_location to these three cases, and adds
> test coverage for one of them (the third hunk within the patch), fixing
> the new reproducer for PR analyzer/104308.
>
> Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
>
> OK for trunk in stage 4? Or in stage 1?
OK for stage4.
> Thanks
> Dave
>
> gcc/ChangeLog:
> PR analyzer/104308
> * gimple-fold.cc (gimple_fold_builtin_memory_op): Explicitly set
> the location of new_stmt in all places that don't already set it,
> whether explicitly, or via a call to gsi_replace.
>
> gcc/testsuite/ChangeLog:
> PR analyzer/104308
> * gcc.dg/analyzer/pr104308.c: Add test coverage.
>
> Signed-off-by: David Malcolm <dmalcolm@redhat.com>
> ---
> gcc/gimple-fold.cc | 3 +++
> gcc/testsuite/gcc.dg/analyzer/pr104308.c | 13 ++++++++++++-
> 2 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
> index ac22adfd9b1..863ee3d3912 100644
> --- a/gcc/gimple-fold.cc
> +++ b/gcc/gimple-fold.cc
> @@ -1048,6 +1048,7 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
> gsi_replace (gsi, new_stmt, false);
> return true;
> }
> + gimple_set_location (new_stmt, loc);
> gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
> goto done;
> }
> @@ -1302,6 +1303,7 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
> new_stmt);
> gimple_assign_set_lhs (new_stmt, srcvar);
> gimple_set_vuse (new_stmt, gimple_vuse (stmt));
> + gimple_set_location (new_stmt, loc);
> gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
> }
> new_stmt = gimple_build_assign (destvar, srcvar);
> @@ -1338,6 +1340,7 @@ set_vop_and_replace:
> gsi_replace (gsi, new_stmt, false);
> return true;
> }
> + gimple_set_location (new_stmt, loc);
> gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT);
> }
>
> diff --git a/gcc/testsuite/gcc.dg/analyzer/pr104308.c b/gcc/testsuite/gcc.dg/analyzer/pr104308.c
> index 9cd5ee6feee..a3a0cbb7317 100644
> --- a/gcc/testsuite/gcc.dg/analyzer/pr104308.c
> +++ b/gcc/testsuite/gcc.dg/analyzer/pr104308.c
> @@ -1,8 +1,19 @@
> +/* Verify that we have source locations for
> + -Wanalyzer-use-of-uninitialized-value warnings involving folded
> + memory ops. */
> +
> #include <string.h>
>
> -int main()
> +int test_memmove_within_uninit (void)
> {
> char s[5]; /* { dg-message "region created on stack here" } */
> memmove(s, s + 1, 2); /* { dg-warning "use of uninitialized value" } */
> return 0;
> }
> +
> +int test_memcpy_from_uninit (void)
> +{
> + char a1[5];
> + char a2[5]; /* { dg-message "region created on stack here" } */
> + return (memcpy(a1, a2, 5) == a1); /* { dg-warning "use of uninitialized value" } */
> +}
> --
> 2.26.3
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-19 11:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-14 13:24 [PATCH] gimple-fold: fix further missing stmt locations [PR104308] David Malcolm
2022-04-19 11:03 ` 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).