[InstrProf][Driver] Make InstrProfiling behave with TSan (#230582)
I have been seeing an issue whereby TSan reports a race on (non-atomic)
profiling counters. While the TSan pass does try to avoid instrumenting
these, it is possible for optimizations to end up with a PHI node
joining a counter address with a plain user address - in which case we
do want to instrument the access.
This patch follows in GCOVProfiling.cpp's footsteps and adds !nosanitize
metadata to counter accesses in functions compiled with TSan
instrumentation. It also auto-promotes counter accesses to be atomic
(note that TSan already incurs a huge runtime overhead). As this
overrides an explicit `-fprofile-update=single`, a warning is now
emitted by the driver when this happens. I believe the PHI join could
still occur between an atomic counter access and an atomic variable
access, however TSan does not treat atomic accesses as data races.
Assisted by: claude
rdar://188406188