Skip to content

Commit 8a60048

Browse files
committed
Fix free after use caused by iterator invalidation
Fixes llvm#51
1 parent d1924d9 commit 8a60048

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

llvm/lib/Analysis/OmpSsRegionAnalysis.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,22 @@ void OmpSsRegionAnalysisPass::getOmpSsFunctionInfo(
645645
}
646646
}
647647

648+
std::unique_ptr<std::vector<Instruction *>> StackCopy;
649+
648650
for (auto It = succ_begin(BB); It != succ_end(BB); ++It) {
649651
if (!Visited.count(*It)) {
650652
Worklist.push_back(*It);
651653
Visited.insert(*It);
652654
// Forward Stack, since we are setting visited here
653655
// we do this only once per BB
654-
BBTaskStacks[*It].append(Stack.begin(), Stack.end());
656+
if (!StackCopy) {
657+
// We need to copy Stacki, otherwise &Stack as an iterator would be
658+
// invalidated after BBTaskStacks[*It].
659+
StackCopy.reset(
660+
new std::vector<Instruction *>(Stack.begin(), Stack.end()));
661+
}
662+
663+
BBTaskStacks[*It].append(StackCopy->begin(), StackCopy->end());
655664
}
656665
}
657666
}

0 commit comments

Comments
 (0)