Skip to content

Commit

Permalink
Verifying that vm.import ops have a module.func separator. (#19808)
Browse files Browse the repository at this point in the history
This was being verified on parsing but not on ops lowered into imports
from other dialects (extern func.func ops, etc).
  • Loading branch information
benvanik authored Jan 25, 2025
1 parent 6ec861f commit 9201e85
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,18 @@ buildFlatBufferModule(IREE::VM::TargetOptions vmOptions,
importFuncOps.resize(ordinalCounts.getImportFuncs());
exportFuncOps.resize(ordinalCounts.getExportFuncs());
internalFuncOps.resize(ordinalCounts.getInternalFuncs());

for (auto &op : moduleOp.getBlock().getOperations()) {
if (auto funcOp = dyn_cast<IREE::VM::FuncOp>(op)) {
internalFuncOps[funcOp.getOrdinal()->getLimitedValue()] = funcOp;
} else if (auto exportOp = dyn_cast<IREE::VM::ExportOp>(op)) {
exportFuncOps[exportOp.getOrdinal()->getLimitedValue()] = exportOp;
} else if (auto importOp = dyn_cast<IREE::VM::ImportOp>(op)) {
importFuncOps[importOp.getOrdinal()->getLimitedValue()] = importOp;
if (!importOp.getName().contains('.')) {
return importOp.emitOpError("must reference a function in a module "
"(@module_name.func_name); got unscoped `@")
<< importOp.getName() << "`";
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// RUN: iree-compile --split-input-file --compile-mode=vm \
// RUN: --iree-vm-bytecode-module-output-format=flatbuffer-text %s | FileCheck %s
// RUN: iree-compile \
// RUN: --split-input-file \
// RUN: --compile-mode=vm \
// RUN: --iree-vm-bytecode-module-output-format=flatbuffer-text %s | \
// RUN: FileCheck %s

// CHECK-LABEL: "main_module"
// CHECK: "version": 100
Expand Down Expand Up @@ -30,3 +33,10 @@ vm.module @main_module attributes { version = 100 : i32 } {
vm.import private optional @optional.method1() attributes { minimum_version = 11 : i32 }

}

// -----

vm.module @import_funcs_invalid {
// expected-error@+1 {{'vm.import' op must reference a function in a module}}
vm.import private @missing_module_name.fn()
}

0 comments on commit 9201e85

Please sign in to comment.