* [PATCH] analyzer/pr104308.c: Avoid optimizing away the copies
@ 2022-05-04 0:29 Palmer Dabbelt
2024-02-14 14:01 ` David Malcolm
0 siblings, 1 reply; 2+ messages in thread
From: Palmer Dabbelt @ 2022-05-04 0:29 UTC (permalink / raw)
To: gcc-patches
The test cases in analyzer/pr104308.c use uninitialized values in a way
that doesn't plumb through to the return value of the function. This
allows the accesses to be deleted, which can result in the diagnostic
not firing.
gcc/testsuite/ChangeLog
* gcc.dg/analyzer/pr104308.c (test_memmove_within_uninit):
Return the result of the copy.
(test_memcpy_From_uninit): Likewise.
---
I was worried this had something to do with this test failing on RISC-V.
I don't think that's actually the case (IIUC we're just not inlining the
memmove, which elides the diagnostic), but I'd already written it so I
figured I'd send it along.
---
gcc/testsuite/gcc.dg/analyzer/pr104308.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr104308.c b/gcc/testsuite/gcc.dg/analyzer/pr104308.c
index a3a0cbb7317..ae40e59c41c 100644
--- a/gcc/testsuite/gcc.dg/analyzer/pr104308.c
+++ b/gcc/testsuite/gcc.dg/analyzer/pr104308.c
@@ -8,12 +8,13 @@ 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;
+ return s[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" } */
+ memcpy(a1, a2, 5); /* { dg-warning "use of uninitialized value" } */
+ return a1[0];
}
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] analyzer/pr104308.c: Avoid optimizing away the copies
2022-05-04 0:29 [PATCH] analyzer/pr104308.c: Avoid optimizing away the copies Palmer Dabbelt
@ 2024-02-14 14:01 ` David Malcolm
0 siblings, 0 replies; 2+ messages in thread
From: David Malcolm @ 2024-02-14 14:01 UTC (permalink / raw)
To: Palmer Dabbelt, gcc-patches
On Tue, 2022-05-03 at 17:29 -0700, Palmer Dabbelt wrote:
> The test cases in analyzer/pr104308.c use uninitialized values in a
> way
> that doesn't plumb through to the return value of the function. This
> allows the accesses to be deleted, which can result in the diagnostic
> not firing.
Thanks; LGTM for trunk.
Dave
>
> gcc/testsuite/ChangeLog
>
> * gcc.dg/analyzer/pr104308.c (test_memmove_within_uninit):
> Return the result of the copy.
> (test_memcpy_From_uninit): Likewise.
> ---
> I was worried this had something to do with this test failing on
> RISC-V.
> I don't think that's actually the case (IIUC we're just not inlining
> the
> memmove, which elides the diagnostic), but I'd already written it so
> I
> figured I'd send it along.
> ---
> gcc/testsuite/gcc.dg/analyzer/pr104308.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/testsuite/gcc.dg/analyzer/pr104308.c
> b/gcc/testsuite/gcc.dg/analyzer/pr104308.c
> index a3a0cbb7317..ae40e59c41c 100644
> --- a/gcc/testsuite/gcc.dg/analyzer/pr104308.c
> +++ b/gcc/testsuite/gcc.dg/analyzer/pr104308.c
> @@ -8,12 +8,13 @@ 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;
> + return s[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" } */
> + memcpy(a1, a2, 5); /* { dg-warning "use of uninitialized value" }
> */
> + return a1[0];
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-14 14:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-04 0:29 [PATCH] analyzer/pr104308.c: Avoid optimizing away the copies Palmer Dabbelt
2024-02-14 14:01 ` David Malcolm
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).