MSVC 2013 and possibly earlier generate optimised code for bitfield assignments which confuses Memcheck. This is at -O1 and -O2. Doesn't happen at -Od. The basic problem is: to create a new word W, which consists of bits from A where a mask M has a 0 bit and bits of B where M has a 1 bit, MSVC generates A ^ ((A ^ B) & M) whereas gcc generates (A ^ ~M) | (B & M) Memcheck has no problem with gcc's code, but MSVC's code causes a lot of complaining. This is because Memcheck doesn't have a way to know that xoring an undefined value with itself produces a defined zero, since that requires tracking the actual identity of the value, which Memcheck can't do. Proposal is to transform the MSVC version into the GCC version in the IR optimiser (ir_opt.c). This seems to be pretty effective in initial trials. Reproducible: Always
Created attachment 91228 [details] WIP patch, believed to be correct Reduces false positive rate for me by about 2/3 on MSVC optimised code. * CSE cleanups * enable CSEing on loads * the core XOR-AND-XOR transformation
(In reply to Julian Seward from comment #1) > WIP patch, believed to be correct Committed, r3097, but disabled. To enable, change if (0) to if (1) at line 6651.