https://gcc.gnu.org/g:75244f0e73b51d8268052b8d18935ca774f00060

commit r17-381-g75244f0e73b51d8268052b8d18935ca774f00060
Author: Jakub Jelinek <[email protected]>
Date:   Thu May 7 17:29:23 2026 +0200

    testsuite: Fix up gcc.dg/analyzer/divide-by-zero-6.c test
    
    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  <[email protected]>
    
            * gcc.dg/analyzer/divide-by-zero-6.c (init_foo): Use sizeof (*f)
            rather than sizeof (f).
    
    Reviewed-by: David Malcolm <[email protected]>

Diff:
---
 gcc/testsuite/gcc.dg/analyzer/divide-by-zero-6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/analyzer/divide-by-zero-6.c 
b/gcc/testsuite/gcc.dg/analyzer/divide-by-zero-6.c
index 7b50a19fe38e..074acabd4301 100644
--- a/gcc/testsuite/gcc.dg/analyzer/divide-by-zero-6.c
+++ b/gcc/testsuite/gcc.dg/analyzer/divide-by-zero-6.c
@@ -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

Reply via email to