[Mlir-commits] [mlir] f6faa71 - [mlir] fix a crash if the dialect is missing a data layout interface

Alex Zinenko llvmlistbot at llvm.org
Wed Jun 9 08:46:40 PDT 2021


Author: Alex Zinenko
Date: 2021-06-09T17:46:27+02:00
New Revision: f6faa71eafbcd52d5154aadf888fce8b3af73c16

URL: https://github.com/llvm/llvm-project/commit/f6faa71eafbcd52d5154aadf888fce8b3af73c16
DIFF: https://github.com/llvm/llvm-project/commit/f6faa71eafbcd52d5154aadf888fce8b3af73c16.diff

LOG: [mlir] fix a crash if the dialect is missing a data layout interface

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Interfaces/DataLayoutInterfaces.cpp b/mlir/lib/Interfaces/DataLayoutInterfaces.cpp
index 1f219c118d804..f32acd5133fd6 100644
--- a/mlir/lib/Interfaces/DataLayoutInterfaces.cpp
+++ b/mlir/lib/Interfaces/DataLayoutInterfaces.cpp
@@ -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();
   }

diff  --git a/mlir/test/Interfaces/DataLayoutInterfaces/types.mlir b/mlir/test/Interfaces/DataLayoutInterfaces/types.mlir
index 02adc7f54544e..8c1fe5020b6c9 100644
--- a/mlir/test/Interfaces/DataLayoutInterfaces/types.mlir
+++ b/mlir/test/Interfaces/DataLayoutInterfaces/types.mlir
@@ -7,6 +7,13 @@ module attributes { dlti.dl_spec = #dlti.dl_spec<
 
 // -----
 
+// expected-error at 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>>} {


        


More information about the Mlir-commits mailing list