llvm-project/compiler-rt/lib/tsan/rtl/tsan_rtl_proc.cc
Dmitry Vyukov 5dc443619e tsan: always define SANITIZER_GO
Currently we either define SANITIZER_GO for Go or don't define it at all for C++.
This works fine with preprocessor (ifdef/ifndef/defined), but does not work
for C++ if statements (e.g. if (SANITIZER_GO) {...}). Also this is different
from majority of SANITIZER_FOO macros which are always defined to either 0 or 1.

Always define SANITIZER_GO to either 0 or 1.
This allows to use SANITIZER_GO in expressions and in flag default values.

Also remove kGoMode and kCppMode, which were meant to be used in expressions,
but they are not defined in sanitizer_common code, so SANITIZER_GO become prevalent.

Also convert some preprocessor checks to C++ if's or ternary expressions.

Majority of this change is done mechanically with:
sed "s#ifdef SANITIZER_GO#if SANITIZER_GO#g"
sed "s#ifndef SANITIZER_GO#if \!SANITIZER_GO#g"
sed "s#defined(SANITIZER_GO)#SANITIZER_GO#g"

llvm-svn: 285443
2016-10-28 20:14:18 +00:00

62 lines
1.6 KiB
C++

//===-- tsan_rtl_proc.cc ------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is a part of ThreadSanitizer (TSan), a race detector.
//
//===----------------------------------------------------------------------===//
#include "sanitizer_common/sanitizer_placement_new.h"
#include "tsan_rtl.h"
#include "tsan_mman.h"
#include "tsan_flags.h"
namespace __tsan {
Processor *ProcCreate() {
void *mem = InternalAlloc(sizeof(Processor));
internal_memset(mem, 0, sizeof(Processor));
Processor *proc = new(mem) Processor;
proc->thr = nullptr;
#if !SANITIZER_GO
AllocatorProcStart(proc);
#endif
if (common_flags()->detect_deadlocks)
proc->dd_pt = ctx->dd->CreatePhysicalThread();
return proc;
}
void ProcDestroy(Processor *proc) {
CHECK_EQ(proc->thr, nullptr);
#if !SANITIZER_GO
AllocatorProcFinish(proc);
#endif
ctx->clock_alloc.FlushCache(&proc->clock_cache);
ctx->metamap.OnProcIdle(proc);
if (common_flags()->detect_deadlocks)
ctx->dd->DestroyPhysicalThread(proc->dd_pt);
proc->~Processor();
InternalFree(proc);
}
void ProcWire(Processor *proc, ThreadState *thr) {
CHECK_EQ(thr->proc1, nullptr);
CHECK_EQ(proc->thr, nullptr);
thr->proc1 = proc;
proc->thr = thr;
}
void ProcUnwire(Processor *proc, ThreadState *thr) {
CHECK_EQ(thr->proc1, proc);
CHECK_EQ(proc->thr, thr);
thr->proc1 = nullptr;
proc->thr = nullptr;
}
} // namespace __tsan