mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-22 23:24:59 +00:00
[sanitizer] fix instrumentation with -mllvm -sanitizer-coverage-block-threshold=0 to actually do something useful.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231736 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -111,6 +111,9 @@ class SanitizerCoverageModule : public ModulePass {
|
|||||||
ArrayRef<Instruction *> IndirCalls);
|
ArrayRef<Instruction *> IndirCalls);
|
||||||
void SetNoSanitizeMetada(Instruction *I);
|
void SetNoSanitizeMetada(Instruction *I);
|
||||||
void InjectCoverageAtBlock(Function &F, BasicBlock &BB, bool UseCalls);
|
void InjectCoverageAtBlock(Function &F, BasicBlock &BB, bool UseCalls);
|
||||||
|
unsigned NumberOfInstrumentedBlocks() {
|
||||||
|
return SanCovFunction->getNumUses() + SanCovWithCheckFunction->getNumUses();
|
||||||
|
}
|
||||||
Function *SanCovFunction;
|
Function *SanCovFunction;
|
||||||
Function *SanCovWithCheckFunction;
|
Function *SanCovWithCheckFunction;
|
||||||
Function *SanCovIndirCallFunction;
|
Function *SanCovIndirCallFunction;
|
||||||
@@ -192,10 +195,11 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
|
|||||||
for (auto &F : M)
|
for (auto &F : M)
|
||||||
runOnFunction(F);
|
runOnFunction(F);
|
||||||
|
|
||||||
|
auto N = NumberOfInstrumentedBlocks();
|
||||||
|
|
||||||
// Now we know how many elements we need. Create an array of guards
|
// Now we know how many elements we need. Create an array of guards
|
||||||
// with one extra element at the beginning for the size.
|
// with one extra element at the beginning for the size.
|
||||||
Type *Int32ArrayNTy =
|
Type *Int32ArrayNTy = ArrayType::get(Int32Ty, N + 1);
|
||||||
ArrayType::get(Int32Ty, SanCovFunction->getNumUses() + 1);
|
|
||||||
GlobalVariable *RealGuardArray = new GlobalVariable(
|
GlobalVariable *RealGuardArray = new GlobalVariable(
|
||||||
M, Int32ArrayNTy, false, GlobalValue::PrivateLinkage,
|
M, Int32ArrayNTy, false, GlobalValue::PrivateLinkage,
|
||||||
Constant::getNullValue(Int32ArrayNTy), "__sancov_gen_cov");
|
Constant::getNullValue(Int32ArrayNTy), "__sancov_gen_cov");
|
||||||
@@ -211,8 +215,7 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
|
|||||||
// Make sure the array is 16-aligned.
|
// Make sure the array is 16-aligned.
|
||||||
static const int kCounterAlignment = 16;
|
static const int kCounterAlignment = 16;
|
||||||
Type *Int8ArrayNTy =
|
Type *Int8ArrayNTy =
|
||||||
ArrayType::get(Int8Ty, RoundUpToAlignment(SanCovFunction->getNumUses(),
|
ArrayType::get(Int8Ty, RoundUpToAlignment(N, kCounterAlignment));
|
||||||
kCounterAlignment));
|
|
||||||
RealEightBitCounterArray = new GlobalVariable(
|
RealEightBitCounterArray = new GlobalVariable(
|
||||||
M, Int8ArrayNTy, false, GlobalValue::PrivateLinkage,
|
M, Int8ArrayNTy, false, GlobalValue::PrivateLinkage,
|
||||||
Constant::getNullValue(Int8ArrayNTy), "__sancov_gen_cov_counter");
|
Constant::getNullValue(Int8ArrayNTy), "__sancov_gen_cov_counter");
|
||||||
@@ -233,7 +236,7 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
|
|||||||
IRB.SetInsertPoint(CtorFunc->getEntryBlock().getTerminator());
|
IRB.SetInsertPoint(CtorFunc->getEntryBlock().getTerminator());
|
||||||
IRB.CreateCall4(
|
IRB.CreateCall4(
|
||||||
SanCovModuleInit, IRB.CreatePointerCast(RealGuardArray, Int32PtrTy),
|
SanCovModuleInit, IRB.CreatePointerCast(RealGuardArray, Int32PtrTy),
|
||||||
ConstantInt::get(IntptrTy, SanCovFunction->getNumUses()),
|
ConstantInt::get(IntptrTy, N),
|
||||||
ClUse8bitCounters
|
ClUse8bitCounters
|
||||||
? IRB.CreatePointerCast(RealEightBitCounterArray, Int8PtrTy)
|
? IRB.CreatePointerCast(RealEightBitCounterArray, Int8PtrTy)
|
||||||
: Constant::getNullValue(Int8PtrTy),
|
: Constant::getNullValue(Int8PtrTy),
|
||||||
@@ -333,7 +336,7 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
|
|||||||
SmallVector<Value *, 1> Indices;
|
SmallVector<Value *, 1> Indices;
|
||||||
Value *GuardP = IRB.CreateAdd(
|
Value *GuardP = IRB.CreateAdd(
|
||||||
IRB.CreatePointerCast(GuardArray, IntptrTy),
|
IRB.CreatePointerCast(GuardArray, IntptrTy),
|
||||||
ConstantInt::get(IntptrTy, (1 + SanCovFunction->getNumUses()) * 4));
|
ConstantInt::get(IntptrTy, (1 + NumberOfInstrumentedBlocks()) * 4));
|
||||||
Type *Int32PtrTy = PointerType::getUnqual(IRB.getInt32Ty());
|
Type *Int32PtrTy = PointerType::getUnqual(IRB.getInt32Ty());
|
||||||
GuardP = IRB.CreateIntToPtr(GuardP, Int32PtrTy);
|
GuardP = IRB.CreateIntToPtr(GuardP, Int32PtrTy);
|
||||||
if (UseCalls) {
|
if (UseCalls) {
|
||||||
@@ -357,7 +360,7 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
|
|||||||
IRB.SetInsertPoint(IP);
|
IRB.SetInsertPoint(IP);
|
||||||
Value *P = IRB.CreateAdd(
|
Value *P = IRB.CreateAdd(
|
||||||
IRB.CreatePointerCast(EightBitCounterArray, IntptrTy),
|
IRB.CreatePointerCast(EightBitCounterArray, IntptrTy),
|
||||||
ConstantInt::get(IntptrTy, SanCovFunction->getNumUses() - 1));
|
ConstantInt::get(IntptrTy, NumberOfInstrumentedBlocks() - 1));
|
||||||
P = IRB.CreateIntToPtr(P, IRB.getInt8PtrTy());
|
P = IRB.CreateIntToPtr(P, IRB.getInt8PtrTy());
|
||||||
LoadInst *LI = IRB.CreateLoad(P);
|
LoadInst *LI = IRB.CreateLoad(P);
|
||||||
Value *Inc = IRB.CreateAdd(LI, ConstantInt::get(IRB.getInt8Ty(), 1));
|
Value *Inc = IRB.CreateAdd(LI, ConstantInt::get(IRB.getInt8Ty(), 1));
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
; RUN: opt < %s -sancov -sanitizer-coverage-level=1 -S | FileCheck %s --check-prefix=CHECK1
|
; RUN: opt < %s -sancov -sanitizer-coverage-level=1 -S | FileCheck %s --check-prefix=CHECK1
|
||||||
; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -S | FileCheck %s --check-prefix=CHECK2
|
; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -S | FileCheck %s --check-prefix=CHECK2
|
||||||
; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=10 -S | FileCheck %s --check-prefix=CHECK2
|
; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=10 -S | FileCheck %s --check-prefix=CHECK2
|
||||||
|
; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=0 -S | FileCheck %s --check-prefix=CHECK_WITH_CHECK
|
||||||
; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=1 -S | FileCheck %s --check-prefix=CHECK_WITH_CHECK
|
; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=1 -S | FileCheck %s --check-prefix=CHECK_WITH_CHECK
|
||||||
; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-block-threshold=10 -S | FileCheck %s --check-prefix=CHECK3
|
; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-block-threshold=10 -S | FileCheck %s --check-prefix=CHECK3
|
||||||
; RUN: opt < %s -sancov -sanitizer-coverage-level=4 -S | FileCheck %s --check-prefix=CHECK4
|
; RUN: opt < %s -sancov -sanitizer-coverage-level=4 -S | FileCheck %s --check-prefix=CHECK4
|
||||||
@@ -51,6 +52,10 @@ entry:
|
|||||||
; CHECK_WITH_CHECK-LABEL: define void @foo
|
; CHECK_WITH_CHECK-LABEL: define void @foo
|
||||||
; CHECK_WITH_CHECK: __sanitizer_cov_with_check
|
; CHECK_WITH_CHECK: __sanitizer_cov_with_check
|
||||||
; CHECK_WITH_CHECK: ret void
|
; CHECK_WITH_CHECK: ret void
|
||||||
|
; CHECK_WITH_CHECK-LABEL: define internal void @sancov.module_ctor
|
||||||
|
; CHECK_WITH_CHECK-NOT: ret
|
||||||
|
; CHECK_WITH_CHECK: call void @__sanitizer_cov_module_init({{.*}}, i64 4,
|
||||||
|
; CHECK_WITH_CHECK: ret
|
||||||
|
|
||||||
; CHECK2-LABEL: define void @foo
|
; CHECK2-LABEL: define void @foo
|
||||||
; CHECK2: call void @__sanitizer_cov
|
; CHECK2: call void @__sanitizer_cov
|
||||||
|
Reference in New Issue
Block a user