[Util] Signal pass failure for invalid initialization (#25218) `iree-opt` printed the diagnostic but still exited successfully. `VerifyInitializationOrderPass` returns when its checks fail without calling `signalPassFailure()`, so the pass manager doesn't see the failure. This signals pass failure on all four error paths and adds an exit-status check to the existing tests. Signed-off-by: anutosh491 <andersonbhat491@gmail.com>
diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/VerifyInitializationOrder.cpp b/compiler/src/iree/compiler/Dialect/Util/Transforms/VerifyInitializationOrder.cpp index 9c9605b..67d55a6 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/VerifyInitializationOrder.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/VerifyInitializationOrder.cpp
@@ -418,22 +418,22 @@ // Phase 1: simple checks (no CFG analysis needed). if (failed(verifyModuleOrderDependencies(globalTable, initializerOps, opOrdinalMap, moduleOp))) { - return; + return signalPassFailure(); } if (failed(verifyDoubleInitialization(globalTable, initializerOps))) { - return; + return signalPassFailure(); } if (failed(verifyInitialValueConflicts(globalTable, initializerOps, opOrdinalMap))) { - return; + return signalPassFailure(); } // Phase 2: conservative reachability analysis with warnings. auto reachability = computeInitializerReachability(moduleOp); if (failed(verifyImmutableStoresWithWarnings(globalTable, reachability))) { - return; + return signalPassFailure(); } } };
diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/test/verify_initialization_order.mlir b/compiler/src/iree/compiler/Dialect/Util/Transforms/test/verify_initialization_order.mlir index 92adb8e..b2b6dc6 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/test/verify_initialization_order.mlir +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/test/verify_initialization_order.mlir
@@ -1,4 +1,5 @@ // RUN: iree-opt --split-input-file --verify-diagnostics --iree-util-verify-initialization-order %s | FileCheck %s +// RUN: not iree-opt --split-input-file --iree-util-verify-initialization-order %s 2>&1 | FileCheck %s --check-prefix=FAILURE // Valid: Basic module with correct initialization order. @@ -103,6 +104,7 @@ // ----- // Error: Forward reference in initializer. +// FAILURE: error: initializer at position 0 accesses global '@later_global' defined at position 1 util.initializer { // expected-error @+1 {{initializer at position 0 accesses global '@later_global' defined at position 1}} @@ -126,6 +128,7 @@ // ----- // Error: Double initialization of immutable global. +// FAILURE: error: immutable global '@double_init' is initialized both by initial value and by store in initializer util.global private @double_init = 10 : i32 util.initializer { @@ -150,6 +153,7 @@ // ----- // Error: Store to immutable global in externally reachable function. +// FAILURE: error: store to immutable global '@no_external_store' in function 'public_func' which is reachable from non-initializer contexts util.func public @public_func() { %c42 = arith.constant 42 : i32