Thank you, John and Phillippe, for your replies.

First, to John:

Valgrind actually does know that a conditional move is a functional
operation and not a conditional branch. So if you can convince your
compiler to emit conditional moves, Valgrind will simply "taint" the output
instead of emitting a diagnostic. (Actually, my original example is so
simple that a modern compiler will see that it invokes undefined behavior,
and then the compiler might optimize away the entire program. Of course my
real-life case is not so simple; in reality, the undefined value is coming
from outside the function.)

Also, even with optimization disabled, or with a compiler that does not
emit CMOV instructions, I can get the behavior I want by rewriting like so:

    int a; /* undefined */
    int b = a & (-(a > 0));

It is always possible to rewrite pure functions to avoid branches; anyone
who writes vectorized code is probably familiar with this sort of trick.
However, the computational overhead can become prohibitive. My second
example is the sort of case that would be (very) painful to "fix" in this
way.

To both of you:

I do not necessarily want Valgrind to figure all of this out
automatically... I am willing to annotate my code with VG_ macros to
achieve the effect I want. As I mentioned in the original Email, I believe
I can mostly do this with the GET_VBITS() and SET_VBITS() macros. But I
fear I will lose the origin tracking, which in my case is extremely useful.

And yes, this is creating a huge number of false positives for me. (My use
case is a bit of a long story; I am hoping you will trust me when I say I
cannot easily fix this in some other way.) I could add suppression rules,
of course, but then I might miss real bugs... I really do want simply to
propagate the invalidity bits and only see the warning if the value is
later used.

Thank you again for your replies.

 - Pat
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to