LLVM 20.0.0git
Macros | Functions | Variables
ThreadSanitizer.cpp File Reference
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Analysis/CaptureTracking.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/EscapeEnumerator.h"
#include "llvm/Transforms/Utils/Instrumentation.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "tsan"
 

Functions

 STATISTIC (NumInstrumentedReads, "Number of instrumented reads")
 
 STATISTIC (NumInstrumentedWrites, "Number of instrumented writes")
 
 STATISTIC (NumOmittedReadsBeforeWrite, "Number of reads ignored due to following writes")
 
 STATISTIC (NumAccessesWithBadSize, "Number of accesses with bad size")
 
 STATISTIC (NumInstrumentedVtableWrites, "Number of vtable ptr writes")
 
 STATISTIC (NumInstrumentedVtableReads, "Number of vtable ptr reads")
 
 STATISTIC (NumOmittedReadsFromConstantGlobals, "Number of reads from constant globals")
 
 STATISTIC (NumOmittedReadsFromVtable, "Number of vtable reads")
 
 STATISTIC (NumOmittedNonCaptured, "Number of accesses ignored due to capturing")
 
static bool isVtableAccess (Instruction *I)
 
static bool shouldInstrumentReadWriteFromAddress (const Module *M, Value *Addr)
 
static bool isTsanAtomic (const Instruction *I)
 
static ConstantIntcreateOrdering (IRBuilder<> *IRB, AtomicOrdering ord)
 

Variables

static cl::opt< boolClInstrumentMemoryAccesses ("tsan-instrument-memory-accesses", cl::init(true), cl::desc("Instrument memory accesses"), cl::Hidden)
 
static cl::opt< boolClInstrumentFuncEntryExit ("tsan-instrument-func-entry-exit", cl::init(true), cl::desc("Instrument function entry and exit"), cl::Hidden)
 
static cl::opt< boolClHandleCxxExceptions ("tsan-handle-cxx-exceptions", cl::init(true), cl::desc("Handle C++ exceptions (insert cleanup blocks for unwinding)"), cl::Hidden)
 
static cl::opt< boolClInstrumentAtomics ("tsan-instrument-atomics", cl::init(true), cl::desc("Instrument atomics"), cl::Hidden)
 
static cl::opt< boolClInstrumentMemIntrinsics ("tsan-instrument-memintrinsics", cl::init(true), cl::desc("Instrument memintrinsics (memset/memcpy/memmove)"), cl::Hidden)
 
static cl::opt< boolClDistinguishVolatile ("tsan-distinguish-volatile", cl::init(false), cl::desc("Emit special instrumentation for accesses to volatiles"), cl::Hidden)
 
static cl::opt< boolClInstrumentReadBeforeWrite ("tsan-instrument-read-before-write", cl::init(false), cl::desc("Do not eliminate read instrumentation for read-before-writes"), cl::Hidden)
 
static cl::opt< boolClCompoundReadBeforeWrite ("tsan-compound-read-before-write", cl::init(false), cl::desc("Emit special compound instrumentation for reads-before-writes"), cl::Hidden)
 
const char kTsanModuleCtorName [] = "tsan.module_ctor"
 
const char kTsanInitName [] = "__tsan_init"
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "tsan"

Definition at line 51 of file ThreadSanitizer.cpp.

Function Documentation

◆ createOrdering()

static ConstantInt * createOrdering ( IRBuilder<> *  IRB,
AtomicOrdering  ord 
)
static

◆ isTsanAtomic()

static bool isTsanAtomic ( const Instruction I)
static

◆ isVtableAccess()

static bool isVtableAccess ( Instruction I)
static

Definition at line 347 of file ThreadSanitizer.cpp.

References I, and llvm::Tag.

◆ shouldInstrumentReadWriteFromAddress()

static bool shouldInstrumentReadWriteFromAddress ( const Module M,
Value Addr 
)
static

◆ STATISTIC() [1/9]

STATISTIC ( NumAccessesWithBadSize  ,
"Number of accesses with bad size"   
)

◆ STATISTIC() [2/9]

STATISTIC ( NumInstrumentedReads  ,
"Number of instrumented reads"   
)

◆ STATISTIC() [3/9]

STATISTIC ( NumInstrumentedVtableReads  ,
"Number of vtable ptr reads"   
)

◆ STATISTIC() [4/9]

STATISTIC ( NumInstrumentedVtableWrites  ,
"Number of vtable ptr writes"   
)

◆ STATISTIC() [5/9]

STATISTIC ( NumInstrumentedWrites  ,
"Number of instrumented writes"   
)

◆ STATISTIC() [6/9]

STATISTIC ( NumOmittedNonCaptured  ,
"Number of accesses ignored due to capturing"   
)

◆ STATISTIC() [7/9]

STATISTIC ( NumOmittedReadsBeforeWrite  ,
"Number of reads ignored due to following writes"   
)

◆ STATISTIC() [8/9]

STATISTIC ( NumOmittedReadsFromConstantGlobals  ,
"Number of reads from constant globals"   
)

◆ STATISTIC() [9/9]

STATISTIC ( NumOmittedReadsFromVtable  ,
"Number of vtable reads"   
)

Variable Documentation

◆ ClCompoundReadBeforeWrite

cl::opt< bool > ClCompoundReadBeforeWrite("tsan-compound-read-before-write", cl::init(false), cl::desc("Emit special compound instrumentation for reads-before-writes"), cl::Hidden) ( "tsan-compound-read-before-write"  ,
cl::init(false)  ,
cl::desc("Emit special compound instrumentation for reads-before-writes")  ,
cl::Hidden   
)
static

◆ ClDistinguishVolatile

cl::opt< bool > ClDistinguishVolatile("tsan-distinguish-volatile", cl::init(false), cl::desc("Emit special instrumentation for accesses to volatiles"), cl::Hidden) ( "tsan-distinguish-volatile"  ,
cl::init(false)  ,
cl::desc("Emit special instrumentation for accesses to volatiles")  ,
cl::Hidden   
)
static

◆ ClHandleCxxExceptions

cl::opt< bool > ClHandleCxxExceptions("tsan-handle-cxx-exceptions", cl::init(true), cl::desc("Handle C++ exceptions (insert cleanup blocks for unwinding)"), cl::Hidden) ( "tsan-handle-cxx-exceptions"  ,
cl::init(true ,
cl::desc("Handle C++ exceptions (insert cleanup blocks for unwinding)")  ,
cl::Hidden   
)
static

◆ ClInstrumentAtomics

cl::opt< bool > ClInstrumentAtomics("tsan-instrument-atomics", cl::init(true), cl::desc("Instrument atomics"), cl::Hidden) ( "tsan-instrument-atomics"  ,
cl::init(true ,
cl::desc("Instrument atomics")  ,
cl::Hidden   
)
static

◆ ClInstrumentFuncEntryExit

cl::opt< bool > ClInstrumentFuncEntryExit("tsan-instrument-func-entry-exit", cl::init(true), cl::desc("Instrument function entry and exit"), cl::Hidden) ( "tsan-instrument-func-entry-exit"  ,
cl::init(true ,
cl::desc("Instrument function entry and exit")  ,
cl::Hidden   
)
static

◆ ClInstrumentMemIntrinsics

cl::opt< bool > ClInstrumentMemIntrinsics("tsan-instrument-memintrinsics", cl::init(true), cl::desc("Instrument memintrinsics (memset/memcpy/memmove)"), cl::Hidden) ( "tsan-instrument-memintrinsics"  ,
cl::init(true ,
cl::desc("Instrument memintrinsics (memset/memcpy/memmove)")  ,
cl::Hidden   
)
static

◆ ClInstrumentMemoryAccesses

cl::opt< bool > ClInstrumentMemoryAccesses("tsan-instrument-memory-accesses", cl::init(true), cl::desc("Instrument memory accesses"), cl::Hidden) ( "tsan-instrument-memory-accesses"  ,
cl::init(true ,
cl::desc("Instrument memory accesses")  ,
cl::Hidden   
)
static

◆ ClInstrumentReadBeforeWrite

cl::opt< bool > ClInstrumentReadBeforeWrite("tsan-instrument-read-before-write", cl::init(false), cl::desc("Do not eliminate read instrumentation for read-before-writes"), cl::Hidden) ( "tsan-instrument-read-before-write"  ,
cl::init(false)  ,
cl::desc("Do not eliminate read instrumentation for read-before-writes")  ,
cl::Hidden   
)
static

◆ kTsanInitName

const char kTsanInitName[] = "__tsan_init"

Definition at line 97 of file ThreadSanitizer.cpp.

◆ kTsanModuleCtorName

const char kTsanModuleCtorName[] = "tsan.module_ctor"

Definition at line 96 of file ThreadSanitizer.cpp.