Bug 344382 - Memcheck has high false error rates on MSVC2013 compiled, optimised, code
Summary: Memcheck has high false error rates on MSVC2013 compiled, optimised, code
Status: REPORTED
Alias: None
Product: valgrind
Classification: Unclassified
Component: memcheck (show other bugs)
Version: 3.10 SVN
Platform: Other Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-20 12:38 UTC by Julian Seward
Modified: 2016-04-09 12:38 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
WIP patch, believed to be correct (24.15 KB, patch)
2015-02-23 00:02 UTC, Julian Seward
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Julian Seward 2015-02-20 12:38:42 UTC
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
Comment 1 Julian Seward 2015-02-23 00:02:29 UTC
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
Comment 2 Julian Seward 2015-02-27 13:34:49 UTC
(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.