Skip to content

Commit

Permalink
[daphneir] fix null value dereference (#881)
Browse files Browse the repository at this point in the history
This patch uses a pre-increment range-based iterator which prevents
a null value dereference in this specific loop.
  • Loading branch information
philipportner committed Oct 30, 2024
1 parent 8857018 commit cfd34a4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/compiler/lowering/VectorizeComputationsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,20 @@ void VectorizeComputationsPass::runOnOperation() {

auto pipelineReplaceResults = pipelineOp->getResults().drop_front(resultsIx).take_front(numResults);
resultsIx += numResults;
for (auto z : llvm::zip(v->getResults(), pipelineReplaceResults)) {
auto old = std::get<0>(z);
auto replacement = std::get<1>(z);
for (auto [old, replacement] : llvm::zip(v->getResults(), pipelineReplaceResults)) {

// TODO: switch to type based size inference instead
// FIXME: if output is dynamic sized, we can't do this
// replace `NumRowOp` and `NumColOp`s for output size inference
for (auto &use : old.getUses()) {
// FIXME: there are cases where old.getUses returns a null value, which should not happen.
// This indicates that we messed up somewhere in this pass and at this point, we have
// an invalid IR. See #881, using the safer llvm::make_early_inc_range iterator circumvents the segfault
// at this point, but dose not resolve the root cause (invalid IR).
for (auto &use : llvm::make_early_inc_range(old.getUses())) {
auto *op = use.getOwner();
if (!op)
continue;

if (auto nrowOp = llvm::dyn_cast<daphne::NumRowsOp>(op)) {
nrowOp.replaceAllUsesWith(pipelineOp.getOutRows()[replacement.getResultNumber()]);
nrowOp.erase();
Expand Down

0 comments on commit cfd34a4

Please sign in to comment.