diff --git a/stablehlo/reference/Api.cpp b/stablehlo/reference/Api.cpp index d39a46c8c04..a94f0c44cce 100644 --- a/stablehlo/reference/Api.cpp +++ b/stablehlo/reference/Api.cpp @@ -14,6 +14,7 @@ limitations under the License. ==============================================================================*/ #include "stablehlo/reference/Api.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include "llvm/Support/FileSystem.h" @@ -106,6 +107,9 @@ class DefaultInterpreterFallback : public InterpreterFallback { llvm::ErrorOr> evalModule( ModuleOp module, ArrayRef inputs, const InterpreterConfiguration &config) { + if (module.getOps().empty()) + return SmallVector(); + auto mainFunc = getMainFunction(module, config.mainFunction); if (!mainFunc) llvm::report_fatal_error("Requested main function not found."); diff --git a/stablehlo/tests/interpret_probe.mlir b/stablehlo/tests/interpret_probe.mlir index c903dfef1fa..bc1d8178644 100644 --- a/stablehlo/tests/interpret_probe.mlir +++ b/stablehlo/tests/interpret_probe.mlir @@ -1,5 +1,9 @@ // RUN: stablehlo-translate --interpret --probe-output-dir=%T -split-input-file %s +// Test an empty module + +// ----- + func.func @probe_i1() { %0 = stablehlo.constant dense<[[0], [0], [0]]> : tensor<3x1xi1> %1 = stablehlo.constant dense<[[1], [1], [1]]> : tensor<3x1xi1>