mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-19 04:32:19 +00:00
[dfsan] Fix non-determinism bug in non-zero label check annotator.
We now use a std::vector instead of a DenseSet to store the list of label checks so that we can iterate over it deterministically. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216255 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
54056f1760
commit
f5377021c5
@ -280,7 +280,7 @@ struct DFSanFunction {
|
|||||||
DenseMap<AllocaInst *, AllocaInst *> AllocaShadowMap;
|
DenseMap<AllocaInst *, AllocaInst *> AllocaShadowMap;
|
||||||
std::vector<std::pair<PHINode *, PHINode *> > PHIFixups;
|
std::vector<std::pair<PHINode *, PHINode *> > PHIFixups;
|
||||||
DenseSet<Instruction *> SkipInsts;
|
DenseSet<Instruction *> SkipInsts;
|
||||||
DenseSet<Value *> NonZeroChecks;
|
std::vector<Value *> NonZeroChecks;
|
||||||
bool AvoidNewBlocks;
|
bool AvoidNewBlocks;
|
||||||
|
|
||||||
struct CachedCombinedShadow {
|
struct CachedCombinedShadow {
|
||||||
@ -802,18 +802,16 @@ bool DataFlowSanitizer::runOnModule(Module &M) {
|
|||||||
// yet). To make our life easier, do this work in a pass after the main
|
// yet). To make our life easier, do this work in a pass after the main
|
||||||
// instrumentation.
|
// instrumentation.
|
||||||
if (ClDebugNonzeroLabels) {
|
if (ClDebugNonzeroLabels) {
|
||||||
for (DenseSet<Value *>::iterator i = DFSF.NonZeroChecks.begin(),
|
for (Value *V : DFSF.NonZeroChecks) {
|
||||||
e = DFSF.NonZeroChecks.end();
|
|
||||||
i != e; ++i) {
|
|
||||||
Instruction *Pos;
|
Instruction *Pos;
|
||||||
if (Instruction *I = dyn_cast<Instruction>(*i))
|
if (Instruction *I = dyn_cast<Instruction>(V))
|
||||||
Pos = I->getNextNode();
|
Pos = I->getNextNode();
|
||||||
else
|
else
|
||||||
Pos = DFSF.F->getEntryBlock().begin();
|
Pos = DFSF.F->getEntryBlock().begin();
|
||||||
while (isa<PHINode>(Pos) || isa<AllocaInst>(Pos))
|
while (isa<PHINode>(Pos) || isa<AllocaInst>(Pos))
|
||||||
Pos = Pos->getNextNode();
|
Pos = Pos->getNextNode();
|
||||||
IRBuilder<> IRB(Pos);
|
IRBuilder<> IRB(Pos);
|
||||||
Value *Ne = IRB.CreateICmpNE(*i, DFSF.DFS.ZeroShadow);
|
Value *Ne = IRB.CreateICmpNE(V, DFSF.DFS.ZeroShadow);
|
||||||
BranchInst *BI = cast<BranchInst>(SplitBlockAndInsertIfThen(
|
BranchInst *BI = cast<BranchInst>(SplitBlockAndInsertIfThen(
|
||||||
Ne, Pos, /*Unreachable=*/false, ColdCallWeights));
|
Ne, Pos, /*Unreachable=*/false, ColdCallWeights));
|
||||||
IRBuilder<> ThenIRB(BI);
|
IRBuilder<> ThenIRB(BI);
|
||||||
@ -878,7 +876,7 @@ Value *DFSanFunction::getShadow(Value *V) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NonZeroChecks.insert(Shadow);
|
NonZeroChecks.push_back(Shadow);
|
||||||
} else {
|
} else {
|
||||||
Shadow = DFS.ZeroShadow;
|
Shadow = DFS.ZeroShadow;
|
||||||
}
|
}
|
||||||
@ -1138,7 +1136,7 @@ void DFSanVisitor::visitLoadInst(LoadInst &LI) {
|
|||||||
Shadow = DFSF.combineShadows(Shadow, PtrShadow, &LI);
|
Shadow = DFSF.combineShadows(Shadow, PtrShadow, &LI);
|
||||||
}
|
}
|
||||||
if (Shadow != DFSF.DFS.ZeroShadow)
|
if (Shadow != DFSF.DFS.ZeroShadow)
|
||||||
DFSF.NonZeroChecks.insert(Shadow);
|
DFSF.NonZeroChecks.push_back(Shadow);
|
||||||
|
|
||||||
DFSF.setShadow(&LI, Shadow);
|
DFSF.setShadow(&LI, Shadow);
|
||||||
}
|
}
|
||||||
@ -1480,7 +1478,7 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
|
|||||||
LoadInst *LI = NextIRB.CreateLoad(DFSF.getRetvalTLS());
|
LoadInst *LI = NextIRB.CreateLoad(DFSF.getRetvalTLS());
|
||||||
DFSF.SkipInsts.insert(LI);
|
DFSF.SkipInsts.insert(LI);
|
||||||
DFSF.setShadow(CS.getInstruction(), LI);
|
DFSF.setShadow(CS.getInstruction(), LI);
|
||||||
DFSF.NonZeroChecks.insert(LI);
|
DFSF.NonZeroChecks.push_back(LI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1534,7 +1532,7 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
|
|||||||
ExtractValueInst::Create(NewCS.getInstruction(), 1, "", Next);
|
ExtractValueInst::Create(NewCS.getInstruction(), 1, "", Next);
|
||||||
DFSF.SkipInsts.insert(ExShadow);
|
DFSF.SkipInsts.insert(ExShadow);
|
||||||
DFSF.setShadow(ExVal, ExShadow);
|
DFSF.setShadow(ExVal, ExShadow);
|
||||||
DFSF.NonZeroChecks.insert(ExShadow);
|
DFSF.NonZeroChecks.push_back(ExShadow);
|
||||||
|
|
||||||
CS.getInstruction()->replaceAllUsesWith(ExVal);
|
CS.getInstruction()->replaceAllUsesWith(ExVal);
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,16 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3
|
|||||||
|
|
||||||
declare i32 @g()
|
declare i32 @g()
|
||||||
|
|
||||||
; CHECK: define { i32, i16 } @"dfs$f"(i32, i16)
|
; CHECK: define { i32, i16 } @"dfs$f"(i32, i32, i16, i16)
|
||||||
define i32 @f(i32) {
|
define i32 @f(i32, i32) {
|
||||||
; CHECK: [[LOCALLABELALLOCA:%.*]] = alloca i16
|
; CHECK: [[LOCALLABELALLOCA:%.*]] = alloca i16
|
||||||
; CHECK: [[ARGCMP:%.*]] = icmp ne i16 %1, 0
|
|
||||||
; CHECK: br i1 [[ARGCMP]]
|
|
||||||
%i = alloca i32
|
%i = alloca i32
|
||||||
store i32 %0, i32* %i
|
; CHECK: [[ARGCMP1:%.*]] = icmp ne i16 %3, 0
|
||||||
|
; CHECK: br i1 [[ARGCMP1]]
|
||||||
|
; CHECK: [[ARGCMP2:%.*]] = icmp ne i16 %2, 0
|
||||||
|
; CHECK: br i1 [[ARGCMP2]]
|
||||||
|
%x = add i32 %0, %1
|
||||||
|
store i32 %x, i32* %i
|
||||||
; CHECK: [[CALL:%.*]] = call { i32, i16 } @"dfs$g"()
|
; CHECK: [[CALL:%.*]] = call { i32, i16 } @"dfs$g"()
|
||||||
; CHECK: [[CALLLABEL:%.*]] = extractvalue { i32, i16 } [[CALL]], 1
|
; CHECK: [[CALLLABEL:%.*]] = extractvalue { i32, i16 } [[CALL]], 1
|
||||||
; CHECK: [[CALLCMP:%.*]] = icmp ne i16 [[CALLLABEL]], 0
|
; CHECK: [[CALLCMP:%.*]] = icmp ne i16 [[CALLLABEL]], 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user