Skip to content

Commit 027b907

Browse files
committed
Fix type mismatches, possibly null operands
1 parent a4a10e9 commit 027b907

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ class CmpIOpConversion : public OpConversionPattern<arith::CmpIOp> {
275275
ConversionPatternRewriter &rewriter) const override {
276276

277277
Type type = adaptor.getLhs().getType();
278-
if (type && !(isa<IntegerType>(type) || emitc::isPointerWideType(type))) {
278+
if (!type || !(isa<IntegerType>(type) || emitc::isPointerWideType(type))) {
279279
return rewriter.notifyMatchFailure(
280-
op, "expected integer or size_t/ssize_t type");
280+
op, "expected integer or size_t/ssize_t/ptrdiff_t type");
281281
}
282282

283283
bool needsUnsigned = needsUnsignedCmp(op.getPredicate());
@@ -330,21 +330,21 @@ class CastConversion : public OpConversionPattern<ArithOp> {
330330
ConversionPatternRewriter &rewriter) const override {
331331

332332
Type opReturnType = this->getTypeConverter()->convertType(op.getType());
333-
if (opReturnType && !(isa_and_nonnull<IntegerType>(opReturnType) ||
333+
if (!opReturnType || !(isa<IntegerType>(opReturnType) ||
334334
emitc::isPointerWideType(opReturnType)))
335335
return rewriter.notifyMatchFailure(
336-
op, "expected integer or size_t/ssize_t result type");
336+
op, "expected integer or size_t/ssize_t/ptrdiff_t result type");
337337

338338
if (adaptor.getOperands().size() != 1) {
339339
return rewriter.notifyMatchFailure(
340340
op, "CastConversion only supports unary ops");
341341
}
342342

343343
Type operandType = adaptor.getIn().getType();
344-
if (operandType && !(isa_and_nonnull<IntegerType>(operandType) ||
344+
if (!operandType || !(isa<IntegerType>(operandType) ||
345345
emitc::isPointerWideType(operandType)))
346346
return rewriter.notifyMatchFailure(
347-
op, "expected integer or size_t/ssize_t operand type");
347+
op, "expected integer or size_t/ssize_t/ptrdiff_t operand type");
348348

349349
// Signed (sign-extending) casts from i1 are not supported.
350350
if (operandType.isInteger(1) && !castToUnsigned)
@@ -433,7 +433,7 @@ class IntegerOpConversion final : public OpConversionPattern<ArithOp> {
433433
ConversionPatternRewriter &rewriter) const override {
434434

435435
Type type = this->getTypeConverter()->convertType(op.getType());
436-
if (type && !(isa_and_nonnull<IntegerType>(type) ||
436+
if (!type || !(isa_and_nonnull<IntegerType>(type) ||
437437
emitc::isPointerWideType(type))) {
438438
return rewriter.notifyMatchFailure(
439439
op, "expected integer or size_t/ssize_t/ptrdiff_t type");
@@ -517,10 +517,10 @@ class ShiftOpConversion : public OpConversionPattern<ArithOp> {
517517
ConversionPatternRewriter &rewriter) const override {
518518

519519
Type type = this->getTypeConverter()->convertType(op.getType());
520-
if (type && !(isa_and_nonnull<IntegerType>(type) ||
520+
if (!type || !(isa_and_nonnull<IntegerType>(type) ||
521521
emitc::isPointerWideType(type))) {
522522
return rewriter.notifyMatchFailure(
523-
op, "expected integer or size_t/ssize_t type");
523+
op, "expected integer or size_t/ssize_t/ptrdiff_t type");
524524
}
525525

526526
if (type.isInteger(1)) {

mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir

+11-11
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ func.func @arith_shift_left_index(%amount: i32) {
199199
%cst0 = "arith.constant"() {value = 42 : index} : () -> (index)
200200
%cast1 = arith.index_cast %amount : i32 to index
201201
// CHECK-DAG: %[[C1:[^ ]*]] = "emitc.constant"(){{.*}}value = 42{{.*}}!emitc.size_t
202-
// CHECK-DAG: %[[Cast1:[^ ]*]] = emitc.cast %[[AMOUNT]] : i32 to !emitc.ssize_t
203-
// CHECK-DAG: %[[AmountIdx:[^ ]*]] = emitc.cast %[[Cast1]] : !emitc.ssize_t to !emitc.size_t
202+
// CHECK-DAG: %[[Cast1:[^ ]*]] = emitc.cast %[[AMOUNT]] : i32 to !emitc.ptrdiff_t
203+
// CHECK-DAG: %[[AmountIdx:[^ ]*]] = emitc.cast %[[Cast1]] : !emitc.ptrdiff_t to !emitc.size_t
204204
// CHECK-DAG: %[[Byte:[^ ]*]] = "emitc.constant"{{.*}}value = 8{{.*}}index
205205
// CHECK-DAG: %[[SizeOf:[^ ]*]] = emitc.call_opaque "sizeof"(%[[Byte]]) : (!emitc.size_t) -> !emitc.size_t
206206
// CHECK-DAG: %[[SizeConstant:[^ ]*]] = emitc.mul %[[Byte]], %[[SizeOf]] : (!emitc.size_t, !emitc.size_t) -> !emitc.size_t
@@ -220,8 +220,8 @@ func.func @arith_shift_left_index(%amount: i32) {
220220
// CHECK-SAME: %[[AMOUNT:.*]]: i32
221221
func.func @arith_shift_right_index(%amount: i32) {
222222
// CHECK-DAG: %[[C1:[^ ]*]] = "emitc.constant"(){{.*}}value = 42{{.*}}!emitc.size_t
223-
// CHECK-DAG: %[[Cast1:[^ ]*]] = emitc.cast %[[AMOUNT]] : i32 to !emitc.ssize_t
224-
// CHECK-DAG: %[[AmountIdx:[^ ]*]] = emitc.cast %[[Cast1]] : !emitc.ssize_t to !emitc.size_t
223+
// CHECK-DAG: %[[Cast1:[^ ]*]] = emitc.cast %[[AMOUNT]] : i32 to !emitc.ptrdiff_t
224+
// CHECK-DAG: %[[AmountIdx:[^ ]*]] = emitc.cast %[[Cast1]] : !emitc.ptrdiff_t to !emitc.size_t
225225
%arg0 = "arith.constant"() {value = 42 : index} : () -> (index)
226226
%arg1 = arith.index_cast %amount : i32 to index
227227

@@ -236,17 +236,17 @@ func.func @arith_shift_right_index(%amount: i32) {
236236
// CHECK: emitc.yield %[[Ternary]] : !emitc.size_t
237237
%2 = arith.shrui %arg0, %arg1 : index
238238

239-
// CHECK-DAG: %[[SC1:[^ ]*]] = emitc.cast %[[C1]] : !emitc.size_t to !emitc.ssize_t
239+
// CHECK-DAG: %[[SC1:[^ ]*]] = emitc.cast %[[C1]] : !emitc.size_t to !emitc.ptrdiff_t
240240
// CHECK-DAG: %[[SByte:[^ ]*]] = "emitc.constant"{{.*}}value = 8{{.*}}index{{.*}}!emitc.size_t
241241
// CHECK-DAG: %[[SSizeOf:[^ ]*]] = emitc.call_opaque "sizeof"(%[[SByte]]) : (!emitc.size_t) -> !emitc.size_t
242242
// CHECK-DAG: %[[SSizeConstant:[^ ]*]] = emitc.mul %[[SByte]], %[[SSizeOf]] : (!emitc.size_t, !emitc.size_t) -> !emitc.size_t
243243
// CHECK-DAG: %[[SCmpNoExcess:[^ ]*]] = emitc.cmp lt, %[[AmountIdx]], %[[SSizeConstant]] : (!emitc.size_t, !emitc.size_t) -> i1
244-
// CHECK-DAG: %[[SZero:[^ ]*]] = "emitc.constant"{{.*}}value = 0{{.*}}!emitc.ssize_t
245-
// CHECK: %[[SShiftRes:[^ ]*]] = emitc.expression : !emitc.ssize_t
246-
// CHECK: %[[SHRSI:[^ ]*]] = emitc.bitwise_right_shift %[[SC1]], %[[AmountIdx]] : (!emitc.ssize_t, !emitc.size_t) -> !emitc.ssize_t
247-
// CHECK: %[[STernary:[^ ]*]] = emitc.conditional %[[SCmpNoExcess]], %[[SHRSI]], %[[SZero]] : !emitc.ssize_t
248-
// CHECK: emitc.yield %[[STernary]] : !emitc.ssize_t
249-
// CHECK: emitc.cast %[[SShiftRes]] : !emitc.ssize_t to !emitc.size_t
244+
// CHECK-DAG: %[[SZero:[^ ]*]] = "emitc.constant"{{.*}}value = 0{{.*}}!emitc.ptrdiff_t
245+
// CHECK: %[[SShiftRes:[^ ]*]] = emitc.expression : !emitc.ptrdiff_t
246+
// CHECK: %[[SHRSI:[^ ]*]] = emitc.bitwise_right_shift %[[SC1]], %[[AmountIdx]] : (!emitc.ptrdiff_t, !emitc.size_t) -> !emitc.ptrdiff_t
247+
// CHECK: %[[STernary:[^ ]*]] = emitc.conditional %[[SCmpNoExcess]], %[[SHRSI]], %[[SZero]] : !emitc.ptrdiff_t
248+
// CHECK: emitc.yield %[[STernary]] : !emitc.ptrdiff_t
249+
// CHECK: emitc.cast %[[SShiftRes]] : !emitc.ptrdiff_t to !emitc.size_t
250250
%3 = arith.shrsi %arg0, %arg1 : index
251251

252252
return

0 commit comments

Comments
 (0)