Skip to content

Commit 5dc6463

Browse files
committed
[CilkSanitizer] Fixed dependency-checking code for unusual exit blocks of loops, specifically, loop blocks terminated by unreachable. This patch addresses issue llvm#84.
1 parent bcbfa8d commit 5dc6463

File tree

2 files changed

+5812
-6
lines changed

2 files changed

+5812
-6
lines changed

llvm/lib/Transforms/Instrumentation/CilkSanitizer.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -1114,17 +1114,25 @@ static bool DependenceMightRace(
11141114
DT.findNearestCommonDominator(Src->getParent(), Dst->getParent()));
11151115
// Find the loop depth of that spindle.
11161116
unsigned MaxLoopDepthToCheck = LI.getLoopDepth(DomSpindle->getEntry());
1117+
// It's possible that Src or Dst appears to have a smaller loop depth than the
1118+
// entry of DomSpindle. For example, LoopInfo might not consider Src or Dst
1119+
// part of a loop if they belong to blocks terminated by unreachable.
1120+
if (MaxLoopDepthToCheck > LI.getLoopDepth(Src->getParent()))
1121+
MaxLoopDepthToCheck = LI.getLoopDepth(Src->getParent());
1122+
if (MaxLoopDepthToCheck > LI.getLoopDepth(Dst->getParent()))
1123+
MaxLoopDepthToCheck = LI.getLoopDepth(Dst->getParent());
1124+
1125+
// Check if dependence does not depend on looping.
1126+
if (0 == MaxLoopDepthToCheck)
1127+
// If there's no loop to worry about, then the existence of the dependence
1128+
// implies the potential for a race.
1129+
return true;
1130+
11171131
assert(MinObjDepth <= MaxLoopDepthToCheck &&
11181132
"Minimum loop depth of underlying object cannot be greater "
11191133
"than maximum loop depth of dependence.");
11201134

11211135
if (MaxLoopDepthToCheck == MinObjDepth) {
1122-
// Dependence does not depend on looping.
1123-
if (!MaxLoopDepthToCheck)
1124-
// If there's no loop to worry about, then the existence of the dependence
1125-
// implies the potential for a race.
1126-
return true;
1127-
11281136
if (TI.getTaskFor(Src->getParent()) == TI.getTaskFor(Dst->getParent()))
11291137
return false;
11301138

0 commit comments

Comments
 (0)