[PATCH] D158385: [tsan] Respect !nosanitize metadata and remove gcov special case

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 20 20:39:24 PDT 2023


MaskRay created this revision.
MaskRay added reviewers: Sanitizers, dvyukov, melver, vitalybuka, Enna1.
Herald added a subscriber: hiraditya.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Certain instrumentations set the !nosanitize metadata for inserted
instructions, which are generally not interested for sanitizers. Skip
tsan instrumentation like we do for asan (D126294 <https://reviews.llvm.org/D126294>)/msan/hwasan.

-fprofile-arcs instrumentation has data race unless
-fprofile-update=atomic is specified. Let's remove the the `__llvm_gcov`
special case from commit 0222adbcd25779a156399bcc16fde9f6d083a809 (2016)
as the racy instructions have the !nosanitize metadata.
(-fprofile-arcs instrumentation does not use `__llvm_gcda` as global variables.)

  std::atomic<int> c;
  void foo() { c++; }
  int main() {
    std::thread th(foo);
    c++;
    th.join();
  }

Tested that `clang++ --coverage -fsanitize=thread a.cc && ./a.out` does
not report spurious tsan errors.

Also remove the default CC1 option -fprofile-update=atomic for
-fsanitize=thread to make options more orthogonal.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158385

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/code-coverage-tsan.c
  clang/test/Driver/fprofile-update.c
  llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
  llvm/test/Instrumentation/ThreadSanitizer/do-not-instrument-memory-access.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158385.551888.patch
Type: text/x-patch
Size: 5634 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230821/55c0409c/attachment.bin>


More information about the llvm-commits mailing list