Skip to content

Commit

Permalink
[SV] Fix heap-use-after-free in recent SVExtractTestCode change.
Browse files Browse the repository at this point in the history
We iterate over the instances of a module in the instance graph, and
during that iteration, erase some of the uses. This causes a
heap-use-after-free that ASAN detects. A simple fix is to use
llvm::make_early_inc_range, which allows us to safely iterate over a
range while we erase things from the range.

Fixes #4081.
  • Loading branch information
mikeurbach committed Oct 11, 2022
1 parent d0e8334 commit 300ca7b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Dialect/SV/Transforms/SVExtractTestCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ static void inlineInputOnly(hw::HWModuleOp oldMod,
hw::InstanceGraphNode *node = instanceGraph.lookup(oldMod);
OpBuilder b(oldMod);
bool allInlined = true;
for (hw::InstanceRecord *use : node->uses()) {
for (hw::InstanceRecord *use : llvm::make_early_inc_range(node->uses())) {
// If there is no instance, move on.
hw::HWInstanceLike instLike = use->getInstance();
if (!instLike) {
Expand Down

0 comments on commit 300ca7b

Please sign in to comment.