Skip to content

Commit

Permalink
[CilkSanitizer] Fixed dependency-checking code for unusual exit block…
Browse files Browse the repository at this point in the history
…s of loops, specifically, loop blocks terminated by unreachable. This patch addresses issue llvm#84.
  • Loading branch information
neboat authored and tarunprabhu committed Oct 12, 2023
1 parent 601e6a0 commit e71af8c
Show file tree
Hide file tree
Showing 2 changed files with 5,812 additions and 6 deletions.
20 changes: 14 additions & 6 deletions llvm/lib/Transforms/Instrumentation/CilkSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,17 +1114,25 @@ static bool DependenceMightRace(
DT.findNearestCommonDominator(Src->getParent(), Dst->getParent()));
// Find the loop depth of that spindle.
unsigned MaxLoopDepthToCheck = LI.getLoopDepth(DomSpindle->getEntry());
// It's possible that Src or Dst appears to have a smaller loop depth than the
// entry of DomSpindle. For example, LoopInfo might not consider Src or Dst
// part of a loop if they belong to blocks terminated by unreachable.
if (MaxLoopDepthToCheck > LI.getLoopDepth(Src->getParent()))
MaxLoopDepthToCheck = LI.getLoopDepth(Src->getParent());
if (MaxLoopDepthToCheck > LI.getLoopDepth(Dst->getParent()))
MaxLoopDepthToCheck = LI.getLoopDepth(Dst->getParent());

// Check if dependence does not depend on looping.
if (0 == MaxLoopDepthToCheck)
// If there's no loop to worry about, then the existence of the dependence
// implies the potential for a race.
return true;

assert(MinObjDepth <= MaxLoopDepthToCheck &&
"Minimum loop depth of underlying object cannot be greater "
"than maximum loop depth of dependence.");

if (MaxLoopDepthToCheck == MinObjDepth) {
// Dependence does not depend on looping.
if (!MaxLoopDepthToCheck)
// If there's no loop to worry about, then the existence of the dependence
// implies the potential for a race.
return true;

if (TI.getTaskFor(Src->getParent()) == TI.getTaskFor(Dst->getParent()))
return false;

Expand Down
Loading

0 comments on commit e71af8c

Please sign in to comment.