[Mlir-commits] [mlir] 79b0576 - [mlir] Tighten LLVM_AnyNonAggregate ODS type constraint

Alex Zinenko llvmlistbot at llvm.org
Wed Aug 11 07:30:30 PDT 2021


Author: Alex Zinenko
Date: 2021-08-11T16:30:19+02:00
New Revision: 79b0576dd477c1d6ad608486ffff6213cca32db9

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

LOG: [mlir] Tighten LLVM_AnyNonAggregate ODS type constraint

The constraint was checking that the type is not an LLVM structure or array
type, but was not checking that it is an LLVM-compatible type, making it accept
incorrect types. As a result, some LLVM dialect ops could process values that
are not compatible with the LLVM dialect leading to further issues with
conversions and translations that assume all values are LLVM-compatible. Make
LLVM_AnyNonAggregate only accept LLVM-compatible types.

Reviewed By: cota, akuegel

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
    mlir/test/Dialect/LLVMIR/invalid.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
index 750cf53a1e99c..29ebdcd987117 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
@@ -130,8 +130,9 @@ def LLVM_AnyAggregate : Type<
 
 // Type constraint accepting any LLVM non-aggregate type, i.e. not structure or
 // array.
-def LLVM_AnyNonAggregate : Type<Neg<LLVM_AnyAggregate.predicate>,
-                               "LLVM non-aggregate type">;
+def LLVM_AnyNonAggregate : Type<And<[LLVM_Type.predicate,
+                                     Neg<LLVM_AnyAggregate.predicate>]>,
+                               "LLVM-compatible non-aggregate type">;
 
 // Type constraint accepting any LLVM vector type.
 def LLVM_AnyVector : Type<CPred<"::mlir::LLVM::isCompatibleVectorType($_self)">,

diff  --git a/mlir/test/Dialect/LLVMIR/invalid.mlir b/mlir/test/Dialect/LLVMIR/invalid.mlir
index 38b7e4023c9b2..22fe88d7df415 100644
--- a/mlir/test/Dialect/LLVMIR/invalid.mlir
+++ b/mlir/test/Dialect/LLVMIR/invalid.mlir
@@ -1119,3 +1119,11 @@ llvm.func @caller() {
 }
 
 llvm.func @callee() -> !llvm.struct<(i32, f32)>
+
+// -----
+
+func @bitcast(%arg0: vector<2x3xf32>) {
+  // expected-error @below {{op operand #0 must be LLVM-compatible non-aggregate type}}
+  llvm.bitcast %arg0 : vector<2x3xf32> to vector<2x3xi32>
+  return
+}


        


More information about the Mlir-commits mailing list