[Flang] enable fir.is_present and fir.absent with function types

Fortran dummy procedures and procedure pointer can be OPTIONAL, and
there is no technical reason to prevent fir.is_present and
fir.absent from accepting function types, so allow it and add test.

Note: This is part of upstreaming from the fir-dev branch of
https://github.com/flang-compiler/f18-llvm-project. This patch is
basically upstreaming the following PR.
https://github.com/flang-compiler/f18-llvm-project/pull/1568

Reviewed By: clementval

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
This commit is contained in:
Kiran Chandramohan 2022-06-24 08:45:33 +00:00
parent ae7fbcd199
commit 703b1054e9
2 changed files with 35 additions and 1 deletions

View File

@ -580,7 +580,7 @@ def AnyBoxLike : TypeConstraint<Or<[fir_BoxType.predicate,
fir_BoxCharType.predicate, fir_BoxProcType.predicate]>, "any box">;
def AnyRefOrBoxLike : TypeConstraint<Or<[AnyReferenceLike.predicate,
AnyBoxLike.predicate]>,
AnyBoxLike.predicate, FunctionType.predicate]>,
"any reference or box like">;
def AnyRefOrBox : TypeConstraint<Or<[fir_ReferenceType.predicate,
fir_HeapType.predicate, fir_PointerType.predicate, fir_BoxType.predicate]>,

View File

@ -51,3 +51,37 @@ func.func @bar3() -> i1 {
%1 = fir.call @foo3(%0) : (!fir.boxchar<1>) -> i1
return %1 : i1
}
// CHECK-LABEL: @foo4(
// CHECK-SAME: ptr %[[arg:.*]])
func.func @foo4(%arg0: !fir.boxproc<(i32)->(i64)>) -> i1 {
// CHECK: %[[ptr:.*]] = ptrtoint ptr %[[arg]] to i64
// CHECK: icmp ne i64 %[[ptr]], 0
%0 = fir.is_present %arg0 : (!fir.boxproc<(i32)->(i64)>) -> i1
return %0 : i1
}
// CHECK-LABEL: @bar4
func.func @bar4() -> i1 {
%0 = fir.absent !fir.boxproc<(i32)->(i64)>
// CHECK: call i1 @foo4(ptr null)
%1 = fir.call @foo4(%0) : (!fir.boxproc<(i32)->(i64)>) -> i1
return %1 : i1
}
// CHECK-LABEL: @foo5(
// CHECK-SAME: ptr %[[arg:.*]])
func.func @foo5(%arg0: (i32)->(i64)) -> i1 {
// CHECK: %[[ptr:.*]] = ptrtoint ptr %[[arg]] to i64
// CHECK: icmp ne i64 %[[ptr]], 0
%0 = fir.is_present %arg0 : ((i32)->(i64)) -> i1
return %0 : i1
}
// CHECK-LABEL: @bar5
func.func @bar5() -> i1 {
%0 = fir.absent (i32)->(i64)
// CHECK: call i1 @foo5(ptr null)
%1 = fir.call @foo5(%0) : ((i32)->(i64)) -> i1
return %1 : i1
}