Skip to content

Commit adb58ab

Browse files
committed
add predicate to strengthen verifier
1 parent c54efad commit adb58ab

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ def IsBoxAddressOrValueTypePred
6868
def fir_BoxAddressOrValueType : Type<IsBoxAddressOrValueTypePred,
6969
"fir.box or fir.class type or reference">;
7070

71+
def RefOfConstantSizeAggregateTypePred
72+
: CPred<"::fir::isRefOfConstantSizeAggregateType($_self)">;
73+
def AnyRefOfConstantSizeAggregateType : TypeConstraint<
74+
RefOfConstantSizeAggregateTypePred,
75+
"a reference type to a constant size fir.array, fir.char, or fir.type">;
76+
7177
//===----------------------------------------------------------------------===//
7278
// Memory SSA operations
7379
//===----------------------------------------------------------------------===//
@@ -363,8 +369,8 @@ def fir_CopyOp : fir_Op<"copy", []> {
363369
TODO: add FirAliasTagOpInterface to carry TBAA.
364370
}];
365371

366-
let arguments = (ins Arg<AnyReferenceLike, "", [MemRead]>:$source,
367-
Arg<AnyReferenceLike, "", [MemWrite]>:$destination,
372+
let arguments = (ins Arg<AnyRefOfConstantSizeAggregateType, "", [MemRead]>:$source,
373+
Arg<AnyRefOfConstantSizeAggregateType, "", [MemWrite]>:$destination,
368374
OptionalAttr<UnitAttr>:$no_overlap);
369375

370376
let builders = [OpBuilder<(ins "mlir::Value":$source,

flang/include/flang/Optimizer/Dialect/FIRType.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,13 @@ inline bool isBoxProcAddressType(mlir::Type t) {
498498
return t && mlir::isa<fir::BoxProcType>(t);
499499
}
500500

501+
inline bool isRefOfConstantSizeAggregateType(mlir::Type t) {
502+
t = fir::dyn_cast_ptrEleTy(t);
503+
return t &&
504+
mlir::isa<fir::CharacterType, fir::RecordType, fir::SequenceType>(t) &&
505+
!hasDynamicSize(t);
506+
}
507+
501508
/// Return a string representation of `ty`.
502509
///
503510
/// fir.array<10x10xf32> -> prefix_10x10xf32

flang/test/Fir/invalid.fir

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,16 +1033,25 @@ func.func @bad_copy_1(%arg0: !fir.ref<!t>, %arg1: !fir.ref<!t2>) {
10331033

10341034
!t=!fir.type<sometype{i:i32}>
10351035
func.func @bad_copy_2(%arg0: !fir.ref<!t>, %arg1: !t) {
1036-
// expected-error@+1{{'fir.copy' op operand #0 must be any reference, but got '!fir.type<sometype{i:i32}>'}}
1036+
// expected-error@+1{{'fir.copy' op operand #0 must be a reference type to a constant size fir.array, fir.char, or fir.type, but got '!fir.type<sometype{i:i32}>'}}
10371037
fir.copy %arg1 to %arg0 no_overlap : !t, !fir.ref<!t>
10381038
return
10391039
}
10401040

10411041
// -----
10421042

10431043
!t=!fir.array<?xi32>
1044-
func.func @test_copy(%arg0: !fir.ref<!t>, %arg1: !fir.ref<!t>) {
1045-
// expected-error@+1{{'fir.copy' op source value type must have a compile time constant size}}
1044+
func.func @bad_copy_3(%arg0: !fir.ref<!t>, %arg1: !fir.ref<!t>) {
1045+
// expected-error@+1{{'fir.copy' op operand #0 must be a reference type to a constant size fir.array, fir.char, or fir.type, but got '!fir.ref<!fir.array<?xi32>>'}}
1046+
fir.copy %arg0 to %arg1 no_overlap : !fir.ref<!t>, !fir.ref<!t>
1047+
return
1048+
}
1049+
1050+
// -----
1051+
1052+
!t=f32
1053+
func.func @bad_copy_4(%arg0: !fir.ref<!t>, %arg1: !fir.ref<!t>) {
1054+
// expected-error@+1{{'fir.copy' op operand #0 must be a reference type to a constant size fir.array, fir.char, or fir.type, but got '!fir.ref<f32>'}}
10461055
fir.copy %arg0 to %arg1 no_overlap : !fir.ref<!t>, !fir.ref<!t>
10471056
return
10481057
}

0 commit comments

Comments
 (0)