[PATCH] D32360: [tsan] Refactor __tsan_external_read/__tsan_external_write to avoid code duplication

Kuba (Brecka) Mracek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 21 10:37:27 PDT 2017


kubamracek created this revision.
kubamracek added a project: Sanitizers.

Let's introduce a ExternalAccess function that has the shared code only once.


Repository:
  rL LLVM

https://reviews.llvm.org/D32360

Files:
  lib/tsan/rtl/tsan_external.cc


Index: lib/tsan/rtl/tsan_external.cc
===================================================================
--- lib/tsan/rtl/tsan_external.cc
+++ lib/tsan/rtl/tsan_external.cc
@@ -30,6 +30,20 @@
   return registered_tags[tag];
 }
 
+typedef void(*AccessFunc)(ThreadState *, uptr, uptr, int);
+void ExternalAccess(void *addr, void *caller_pc, void *tag, AccessFunc access) {
+  CHECK_LT(tag, atomic_load(&used_tags, memory_order_relaxed));
+  ThreadState *thr = cur_thread();
+  thr->external_tag = (uptr)tag;
+  if (caller_pc) FuncEntry(thr, (uptr)caller_pc);
+  bool in_ignored_lib;
+  if (!caller_pc || !libignore()->IsIgnored((uptr)caller_pc, &in_ignored_lib)) {
+    access(thr, CALLERPC, (uptr)addr, kSizeLog1);
+  }
+  if (caller_pc) FuncExit(thr);
+  thr->external_tag = 0;
+}
+
 extern "C" {
 SANITIZER_INTERFACE_ATTRIBUTE
 void *__tsan_external_register_tag(const char *object_type) {
@@ -55,30 +69,12 @@
 
 SANITIZER_INTERFACE_ATTRIBUTE
 void __tsan_external_read(void *addr, void *caller_pc, void *tag) {
-  CHECK_LT(tag, atomic_load(&used_tags, memory_order_relaxed));
-  ThreadState *thr = cur_thread();
-  thr->external_tag = (uptr)tag;
-  if (caller_pc) FuncEntry(thr, (uptr)caller_pc);
-  bool in_ignored_lib;
-  if (!caller_pc || !libignore()->IsIgnored((uptr)caller_pc, &in_ignored_lib)) {
-    MemoryRead(thr, CALLERPC, (uptr)addr, kSizeLog1);
-  }
-  if (caller_pc) FuncExit(thr);
-  thr->external_tag = 0;
+  ExternalAccess(addr, caller_pc, tag, MemoryRead);
 }
 
 SANITIZER_INTERFACE_ATTRIBUTE
 void __tsan_external_write(void *addr, void *caller_pc, void *tag) {
-  CHECK_LT(tag, atomic_load(&used_tags, memory_order_relaxed));
-  ThreadState *thr = cur_thread();
-  thr->external_tag = (uptr)tag;
-  if (caller_pc) FuncEntry(thr, (uptr)caller_pc);
-  bool in_ignored_lib;
-  if (!caller_pc || !libignore()->IsIgnored((uptr)caller_pc, &in_ignored_lib)) {
-    MemoryWrite(thr, CALLERPC, (uptr)addr, kSizeLog1);
-  }
-  if (caller_pc) FuncExit(thr);
-  thr->external_tag = 0;
+  ExternalAccess(addr, caller_pc, tag, MemoryWrite);
 }
 }  // extern "C"
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32360.96176.patch
Type: text/x-patch
Size: 2072 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170421/e0024e4e/attachment.bin>


More information about the llvm-commits mailing list