Hi,

I noticed that currently the tsan pass does not instrument bit fileld accesses 
or unaligned data.
Thus some race conditions are not found by the sanitizer.

Furthermore the function __tsan_vptr_update is not called with the correct 
parameters.

This patch uses two already existing interfaces for unaligned or bit field 
accessses,
__tsan_read_range and __tsan_write_range, and fixes the parameters of the 
__tsan_vptr_update
function.

As a little surprise, the test case g++.dg/tsan/aligned_vs_unaligned_race.C 
started to fail at -O2
with this patch, but actually that was due to a combination of invalid C code 
and inverted logic
in the test case.  So actually that test was failing all the time, because TSAN 
cannot find
the race condition because __tsan_write8 should only be called with aligned 
addresses.


Boot-strapped and reggession tested on x86_64-linux-gnu.
OK for trunk?


Thanks
Bernd.
                                          
gcc/ChangeLog:
2014-12-29  Bernd Edlinger  <bernd.edlin...@hotmail.de>

        Instrument bit field and unaligned accesses for TSAN.
        * sanitizer.def (BUILT_IN_TSAN_READ_RANGE): New built-in function.
        (BUILT_IN_TSAN_WRITE_RANGE): New built-in function.
        * tsan.c (instrument_expr): Handle COMPONENT_REF and BIT_FIELD_REF.
        Use BUILT_IN_TSAN_READ_RANGE and BUILT_IN_TSAN_WRITE_RANGE for
        unaligned memory regions.  Pass "rhs" to BUILT_IN_TSAN_VPTR_UPDATE.

testsuite/ChangeLog:
2014-12-29  Bernd Edlinger  <bernd.edlin...@hotmail.de>

        * c-c++-common/tsan/bitfield_race.c: New testcase.
        * g++.dg/tsan/aligned_vs_unaligned_race.C: Fixed.

Attachment: patch-tsan-bitfields.diff
Description: Binary data

Reply via email to