Skip to content

Commit 577a565

Browse files
benvanikAWoloszyn
authored andcommitted
Verifying that vm.import ops have a module.func separator. (#19808)
This was being verified on parsing but not on ops lowered into imports from other dialects (extern func.func ops, etc).
1 parent 1d97492 commit 577a565

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,18 @@ buildFlatBufferModule(IREE::VM::TargetOptions vmOptions,
330330
importFuncOps.resize(ordinalCounts.getImportFuncs());
331331
exportFuncOps.resize(ordinalCounts.getExportFuncs());
332332
internalFuncOps.resize(ordinalCounts.getInternalFuncs());
333-
334333
for (auto &op : moduleOp.getBlock().getOperations()) {
335334
if (auto funcOp = dyn_cast<IREE::VM::FuncOp>(op)) {
336335
internalFuncOps[funcOp.getOrdinal()->getLimitedValue()] = funcOp;
337336
} else if (auto exportOp = dyn_cast<IREE::VM::ExportOp>(op)) {
338337
exportFuncOps[exportOp.getOrdinal()->getLimitedValue()] = exportOp;
339338
} else if (auto importOp = dyn_cast<IREE::VM::ImportOp>(op)) {
340339
importFuncOps[importOp.getOrdinal()->getLimitedValue()] = importOp;
340+
if (!importOp.getName().contains('.')) {
341+
return importOp.emitOpError("must reference a function in a module "
342+
"(@module_name.func_name); got unscoped `@")
343+
<< importOp.getName() << "`";
344+
}
341345
}
342346
}
343347

compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/test/dependencies.mlir

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
// RUN: iree-compile --split-input-file --compile-mode=vm \
2-
// RUN: --iree-vm-bytecode-module-output-format=flatbuffer-text %s | FileCheck %s
1+
// RUN: iree-compile \
2+
// RUN: --split-input-file \
3+
// RUN: --compile-mode=vm \
4+
// RUN: --iree-vm-bytecode-module-output-format=flatbuffer-text %s | \
5+
// RUN: FileCheck %s
36

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

3235
}
36+
37+
// -----
38+
39+
vm.module @import_funcs_invalid {
40+
// expected-error@+1 {{'vm.import' op must reference a function in a module}}
41+
vm.import private @missing_module_name.fn()
42+
}

0 commit comments

Comments
 (0)