]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: Fix up gcc.dg/analyzer/divide-by-zero-6.c test
authorJakub Jelinek <jakub@redhat.com>
Thu, 7 May 2026 15:29:23 +0000 (17:29 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 7 May 2026 15:29:23 +0000 (17:29 +0200)
On Thu, May 07, 2026 at 01:35:07PM +0800, H.J. Lu wrote:
> I got
>
> FAIL: gcc.dg/analyzer/divide-by-zero-6.c  (test for warnings, line 14)
> FAIL: gcc.dg/analyzer/divide-by-zero-6.c  at line 15 (test for
> warnings, line 14)
> FAIL: gcc.dg/analyzer/divide-by-zero-6.c (test for excess errors)
> Excess errors:
> /export/gnu/import/git/gitlab/x86-gcc/gcc/testsuite/gcc.dg/analyzer/divide-by-zero-6.c:14:18:
> warning: use of uninitialized value '*f.y' [CWE-457]
> [-Wanalyzer-use-of-uninitialized-value]

The warnings are correct, but I guess the test wasn't meant to test two
completely different thing, one on 64-bit targets and one on 32-bit ones.

struct foo { int x; int y; };

has sizeof (8) on most targets (except on non-32-bit int), but the test
was using __builtin_memset (f, 0, sizeof (f)) where f is a pointer.
Now, this happens to clear the whole structure on 64-bit targets but only
first half of it on 32-bit ones, so on 64-bit it emits the expected warning
about division by zero, while on 32-bit about using uninitialized value.

I think the testcase was meant to clear the whole structure on all arches,
the following patch does that.

2026-05-07  Jakub Jelinek  <jakub@redhat.com>

* gcc.dg/analyzer/divide-by-zero-6.c (init_foo): Use sizeof (*f)
rather than sizeof (f).

Reviewed-by: David Malcolm <dmalcolm@redhat.com>
gcc/testsuite/gcc.dg/analyzer/divide-by-zero-6.c

index 7b50a19fe38e5eb367502479ee7ff1f05d1c04f4..074acabd43017129e47147f00d0a619dcecf8647 100644 (file)
@@ -5,7 +5,7 @@ struct foo { int x; int y; };
 void
 init_foo (struct foo *f)
 {
-  __builtin_memset (f, 0, sizeof (f));
+  __builtin_memset (f, 0, sizeof (*f));
 }
 
 int