[mlir] fix a crash if the dialect is missing a data layout interface
authorAlex Zinenko <zinenko@google.com>
Wed, 9 Jun 2021 09:51:04 +0000 (11:51 +0200)
committerAlex Zinenko <zinenko@google.com>
Wed, 9 Jun 2021 15:46:27 +0000 (17:46 +0200)
The top-level verifier of data layout specifications delegates verification of
entries with identifier keys to the dialect of the identifier prefix. This flow
was missing a check whether the dialect actually implements the relevant
interface.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D103945

mlir/lib/Interfaces/DataLayoutInterfaces.cpp
mlir/test/Interfaces/DataLayoutInterfaces/types.mlir

index 1f219c1..f32acd5 100644 (file)
@@ -440,6 +440,11 @@ LogicalResult mlir::detail::verifyDataLayoutSpec(DataLayoutSpecInterface spec,
 
     const auto *iface =
         dialect->getRegisteredInterface<DataLayoutDialectInterface>();
+    if (!iface) {
+      return emitError(loc)
+             << "the '" << dialect->getNamespace()
+             << "' dialect does not support identifier data layout entries";
+    }
     if (failed(iface->verifyEntry(kvp.second, loc)))
       return failure();
   }
index 02adc7f..8c1fe50 100644 (file)
@@ -7,6 +7,13 @@ module attributes { dlti.dl_spec = #dlti.dl_spec<
 
 // -----
 
+// expected-error@below {{the 'test' dialect does not support identifier data layout entries}}
+"test.op_with_data_layout"() { dlti.dl_spec = #dlti.dl_spec<
+  #dlti.dl_entry<index, 32>,
+  #dlti.dl_entry<"test.foo", [32]>>} : () -> ()
+
+// -----
+
 // CHECK-LABEL: @index
 module @index attributes { dlti.dl_spec = #dlti.dl_spec<
   #dlti.dl_entry<index, 32>>} {