https://bugs.kde.org/show_bug.cgi?id=492210

            Bug ID: 492210
           Summary: False positive on x86 with ZF taken directly from
                    addition
    Classification: Developer tools
           Product: valgrind
           Version: 3.24 GIT
          Platform: Other
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: memcheck
          Assignee: jsew...@acm.org
          Reporter: amona...@gmail.com
  Target Milestone: ---

This is minimized from Memcheck false positive on GCC bootstrap,
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116458

Take the following testcase:

static int f(short *s)
{
        return s[0] + (s[1] << 16);
}

int main()
{
        void *p = __builtin_malloc(64);
        *(char *)p = 1;
        asm("" ::: "memory");
        int r = f(p);
        asm("" : "+d"(r));
        if (!r)
                __builtin_abort();
}

Compile with 'gcc -O2 -g1' and run under valgrind. Then remove or comment out

        asm("" : "+d"(r));

and compile/run again. valgrind will complain:

==16441== Conditional jump or move depends on uninitialised value(s)
==16441==    at 0x10908D: main (in /tmp/vg/a.out)

even though the difference in generated code is

--- 1.s 2024-08-24 09:46:24.719252103 +0300
+++ 2.s 2024-08-24 09:46:35.202670418 +0300
@@ -19,7 +19,6 @@
        movswl  (%rax), %eax
        sall    $16, %edx
        addl    %eax, %edx
-       testl   %edx, %edx
        je      .L3
        xorl    %eax, %eax
        addq    $8, %rsp

i.e. ZF is now taken directly from addition rather than recomputed with the
TEST instruction. In other words, propagation of known bits in ADD is powerful
enough and proves that low 8 bits of %edx are known, but something goes awry in
deducing ZF.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to