Skip to content

Commit 18c6ed2

Browse files
committed
tsan: add AccessVptr
Add AccessVptr access type. For now it's converted to the same thr->is_vptr_access, but later it will be passed directly to ReportRace and will enable efficient tail calling in MemoryAccess function (currently __tsan_vptr_update/__tsan_vptr_read can't use tail calls in MemoryAccess because of the trailing assignment to thr->is_vptr_access). Depends on D107276. Reviewed By: vitalybuka, melver Differential Revision: https://reviews.llvm.org/D107282
1 parent 831910c commit 18c6ed2

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

compiler-rt/lib/tsan/rtl/tsan_interface_inl.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,15 @@ void __tsan_write8_pc(void *addr, void *pc) {
8383
}
8484

8585
void __tsan_vptr_update(void **vptr_p, void *new_val) {
86-
CHECK_EQ(sizeof(vptr_p), 8);
87-
if (*vptr_p != new_val) {
88-
ThreadState *thr = cur_thread();
89-
thr->is_vptr_access = true;
90-
MemoryAccess(thr, CALLERPC, (uptr)vptr_p, 8, kAccessWrite);
91-
thr->is_vptr_access = false;
92-
}
86+
if (*vptr_p == new_val)
87+
return;
88+
MemoryAccess(cur_thread(), CALLERPC, (uptr)vptr_p, sizeof(*vptr_p),
89+
kAccessWrite | kAccessVptr);
9390
}
9491

9592
void __tsan_vptr_read(void **vptr_p) {
96-
CHECK_EQ(sizeof(vptr_p), 8);
97-
ThreadState *thr = cur_thread();
98-
thr->is_vptr_access = true;
99-
MemoryAccess(thr, CALLERPC, (uptr)vptr_p, 8, kAccessRead);
100-
thr->is_vptr_access = false;
93+
MemoryAccess(cur_thread(), CALLERPC, (uptr)vptr_p, sizeof(*vptr_p),
94+
kAccessRead | kAccessVptr);
10195
}
10296

10397
void __tsan_func_entry(void *pc) { FuncEntry(cur_thread(), STRIP_PAC_PC(pc)); }

compiler-rt/lib/tsan/rtl/tsan_rtl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ enum : AccessType {
698698
kAccessWrite = 0,
699699
kAccessRead = 1 << 0,
700700
kAccessAtomic = 1 << 1,
701+
kAccessVptr = 1 << 2,
701702
};
702703

703704
void MemoryAccess(ThreadState *thr, uptr pc, uptr addr,
@@ -738,7 +739,11 @@ void MemoryAccess(ThreadState *thr, uptr pc, uptr addr, uptr size,
738739
}
739740
bool is_write = !(typ & kAccessRead);
740741
bool is_atomic = typ & kAccessAtomic;
742+
if (typ & kAccessVptr)
743+
thr->is_vptr_access = true;
741744
MemoryAccess(thr, pc, addr, size_log, is_write, is_atomic);
745+
if (typ & kAccessVptr)
746+
thr->is_vptr_access = false;
742747
}
743748

744749
void MemoryResetRange(ThreadState *thr, uptr pc, uptr addr, uptr size);

0 commit comments

Comments
 (0)