[PATCH] D68924: CodeExtractor: NFC: Use Range based loop

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 13 11:32:21 PDT 2019


fhahn added a comment.

In D68924#1707545 <https://reviews.llvm.org/D68924#1707545>, @hiraditya wrote:

> Tried the following, I get test failures and crashes.
>
>   diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
>   index 3e1bea77f6c..c4661fde0fb 100644
>   --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
>   +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
>   @@ -929,8 +929,7 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
>      // Rewrite branches to basic blocks outside of the loop to new dummy blocks
>      // within the new function. This must be done before we lose track of which
>      // blocks were originally in the code region.
>   -  std::vector<User *> Users(header->user_begin(), header->user_end());
>   -  for (auto &U : Users)
>   +  for (auto U : header->users())
>        // The BasicBlock which contains the branch is not in the region
>        // modify the branch target to a new block
>        if (Instruction *I = dyn_cast<Instruction>(U))
>
>
> Failing Tests (6):
>
>   LLVM :: Transforms/CodeExtractor/PartialInlineAndOr.ll
>   LLVM :: Transforms/CodeExtractor/PartialInlineOr.ll
>   LLVM :: Transforms/CodeExtractor/PartialInlineOrAnd.ll    // Crashed: Assertion `(Flags & RF_IgnoreMissingLocals) && "Referenced value not in value map!"' failed.
>   LLVM :: Transforms/HotColdSplit/eh-pads.ll
>   LLVM :: Transforms/HotColdSplit/outline-multiple-entry-region.ll
>   LLVM :: Transforms/HotColdSplit/unwind.ll


I guess you are seeing some segfaults, right? The problem is that in the loop, you change header's users (I->replaceUsesOfWith()), which invalidates the range iterator. I am not entirely sure how the users() iterator range is implemented, but you might be able to use `make_early_inc_range(header->users())`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68924/new/

https://reviews.llvm.org/D68924





More information about the llvm-commits mailing list