Skip to content

Commit bba5951

Browse files
authored
[MLIR] Fix an assert that contains a mistake in conditional operator (#95668)
This is described in (N2) https://pvs-studio.com/en/blog/posts/cpp/1126/ so caught by the PVS Studio analyzer. Warning message - V502 Perhaps the '?:' operator works in a different way than it was expected. The '?:' operator has a lower priority than the '+' operator. LoopEmitter.cpp 983 V502 Perhaps the '?:' operator works in a different way than it was expected. The '?:' operator has a lower priority than the '+' operator. LoopEmitter.cpp 1039 The assert should be assert(bArgs.size() == reduc.size() + (needsUniv ? 1 : 0)); since + has higher precedence and ? has lower. This further can be reduce to assert(aArgs.size() == reduc.size() + needsUniv); because needUniv is a bool value which is implicitly converted to 0 or
1 parent 06aa078 commit bba5951

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mlir/lib/Dialect/SparseTensor/Transforms/Utils/LoopEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ std::pair<Operation *, Value> LoopEmitter::emitWhileLoopOverTensorsAtLvls(
542542
}
543543
// The remaining block arguments are user-provided reduction values and an
544544
// optional universal index. Make sure their sizes match.
545-
assert(bArgs.size() == reduc.size() + needsUniv ? 1 : 0);
545+
assert(bArgs.size() == reduc.size() + needsUniv);
546546
builder.create<scf::ConditionOp>(loc, whileCond, before->getArguments());
547547

548548
// Generates loop body.
@@ -560,7 +560,7 @@ std::pair<Operation *, Value> LoopEmitter::emitWhileLoopOverTensorsAtLvls(
560560
}
561561

562562
// In-place update on reduction variable.
563-
assert(aArgs.size() == reduc.size() + needsUniv ? 1 : 0);
563+
assert(aArgs.size() == reduc.size() + needsUniv);
564564
for (unsigned i = 0, e = reduc.size(); i < e; i++)
565565
reduc[i] = aArgs[i];
566566

0 commit comments

Comments
 (0)