Skip to content

Commit 11140cc

Browse files
authored
[mlir] mark ChangeResult as nodiscard (#76147)
This enum is used by dataflow analyses to indicate whether further propagation is necessary to reach the fix point. Accidentally discarding such a value will likely lead to propagation stopping early, leading to incomplete or incorrect results. The most egregious example is the duality between `join` on the analysis class, which triggers propagation internally, and `join` on the lattice class that does not and expects the caller to trigger it depending on the returned `ChangeResult`.
1 parent 72003ad commit 11140cc

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

mlir/include/mlir/Analysis/DataFlowFramework.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ namespace mlir {
3030
//===----------------------------------------------------------------------===//
3131

3232
/// A result type used to indicate if a change happened. Boolean operations on
33-
/// ChangeResult behave as though `Change` is truthy.
34-
enum class ChangeResult {
33+
/// ChangeResult behave as though `Change` is truth.
34+
enum class [[nodiscard]] ChangeResult {
3535
NoChange,
3636
Change,
3737
};

mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void LivenessAnalysis::visitCallOperand(OpOperand &operand) {
191191

192192
void LivenessAnalysis::setToExitState(Liveness *lattice) {
193193
// This marks values of type (2) liveness as "live".
194-
lattice->markLive();
194+
(void)lattice->markLive();
195195
}
196196

197197
//===----------------------------------------------------------------------===//

mlir/test/lib/Analysis/TestDataFlowFramework.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ LogicalResult FooAnalysis::initialize(Operation *top) {
100100
return top->emitError("expected at least one block in the region");
101101

102102
// Initialize the top-level state.
103-
getOrCreate<FooState>(&top->getRegion(0).front())->join(0);
103+
(void)getOrCreate<FooState>(&top->getRegion(0).front())->join(0);
104104

105105
// Visit all nested blocks and operations.
106106
for (Block &block : top->getRegion(0)) {

0 commit comments

Comments
 (0)