During serialization, the operand number must be used to get the
values assocaited with an operand. Using the argument number in Op
specification was wrong since some of the elements in the arguments
list might be attributes on the operation. This resulted in a segfault
during serialization.
Add a test that exercise that path.
PiperOrigin-RevId:
260977758
--- /dev/null
+// RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s
+
+func @spirv_variables() -> () {
+ spv.module "Logical" "VulkanKHR" {
+ // CHECK: [[INIT:%.*]] = spv.constant 4.000000e+00 : f32
+ // CHECK: {{%.*}} = spv.Variable init([[INIT]]) bind(1, 0) : !spv.ptr<f32, Input>
+ %0 = spv.constant 4.0 : f32
+ %2 = spv.Variable init(%0) bind(1, 0) : !spv.ptr<f32, Input>
+ }
+ return
+}
\ No newline at end of file
auto argument = op.getArg(i);
os << " {\n";
if (argument.is<NamedTypeConstraint *>()) {
- os << " for (auto arg : op.getODSOperands(" << i << ")) {\n";
+ os << " for (auto arg : op.getODSOperands(" << operandNum << ")) {\n";
os << " auto argID = findValueID(arg);\n";
os << " if (!argID) {\n";
os << " emitError(op.getLoc(), \"operand " << operandNum