[compiler-rt] r301008 - [tsan] Refactor __tsan_external_read/__tsan_external_write to avoid code duplication
Kuba Mracek via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 21 10:41:02 PDT 2017
Author: kuba.brecka
Date: Fri Apr 21 12:41:01 2017
New Revision: 301008
URL: http://llvm.org/viewvc/llvm-project?rev=301008&view=rev
Log:
[tsan] Refactor __tsan_external_read/__tsan_external_write to avoid code duplication
Let's introduce a ExternalAccess function that has the shared code only once.
Differential Revision: https://reviews.llvm.org/D32360
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_external.cc
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_external.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_external.cc?rev=301008&r1=301007&r2=301008&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_external.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_external.cc Fri Apr 21 12:41:01 2017
@@ -30,6 +30,20 @@ const char *GetObjectTypeFromTag(uptr ta
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 @@ void __tsan_external_assign_tag(void *ad
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"
More information about the llvm-commits
mailing list