Skip to content

Commit 79b0576

Browse files
committed
[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
1 parent 62c08c0 commit 79b0576

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ def LLVM_AnyAggregate : Type<
130130

131131
// Type constraint accepting any LLVM non-aggregate type, i.e. not structure or
132132
// array.
133-
def LLVM_AnyNonAggregate : Type<Neg<LLVM_AnyAggregate.predicate>,
134-
"LLVM non-aggregate type">;
133+
def LLVM_AnyNonAggregate : Type<And<[LLVM_Type.predicate,
134+
Neg<LLVM_AnyAggregate.predicate>]>,
135+
"LLVM-compatible non-aggregate type">;
135136

136137
// Type constraint accepting any LLVM vector type.
137138
def LLVM_AnyVector : Type<CPred<"::mlir::LLVM::isCompatibleVectorType($_self)">,

mlir/test/Dialect/LLVMIR/invalid.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,3 +1119,11 @@ llvm.func @caller() {
11191119
}
11201120

11211121
llvm.func @callee() -> !llvm.struct<(i32, f32)>
1122+
1123+
// -----
1124+
1125+
func @bitcast(%arg0: vector<2x3xf32>) {
1126+
// expected-error @below {{op operand #0 must be LLVM-compatible non-aggregate type}}
1127+
llvm.bitcast %arg0 : vector<2x3xf32> to vector<2x3xi32>
1128+
return
1129+
}

0 commit comments

Comments
 (0)