Skip to content

Commit 35159c2

Browse files
authored
[flang] handle intrinsic interfaces in FunctionRef::GetType (#89583)
User functions may be declared with an interface that is a specific intrinsic. In such case, there is no result type available from the procedure symbol (at least without using evaluate::Probe), and FunctionRef::GetType() returned nullopt. This caused lowering to crash. The result type of specific intrinsic procedures is always a lengthless intrinsic type, so it is fully defined in the template argument of FunctionRef. Use it.
1 parent a046242 commit 35159c2

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

flang/include/flang/Evaluate/call.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,18 @@ template <typename A> class FunctionRef : public ProcedureRef {
287287
: ProcedureRef{std::move(p), std::move(a)} {}
288288

289289
std::optional<DynamicType> GetType() const {
290-
if (auto type{proc_.GetType()}) {
290+
if constexpr (IsLengthlessIntrinsicType<A>) {
291+
return A::GetType();
292+
} else if (auto type{proc_.GetType()}) {
291293
// TODO: Non constant explicit length parameters of PDTs result should
292294
// likely be dropped too. This is not as easy as for characters since some
293295
// long lived DerivedTypeSpec pointer would need to be created here. It is
294296
// not clear if this is causing any issue so far since the storage size of
295297
// PDTs is independent of length parameters.
296298
return type->DropNonConstantCharacterLength();
299+
} else {
300+
return std::nullopt;
297301
}
298-
return std::nullopt;
299302
}
300303
};
301304
} // namespace Fortran::evaluate

flang/test/Lower/HLFIR/calls-f77.f90

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,16 @@ subroutine alternate_return_call(n1, n2, k)
186186
! CHECK: ^[[block2]]: // pred: ^bb0
187187
7 k = 1; return
188188
end
189+
190+
! -----------------------------------------------------------------------------
191+
! Test calls to user procedures with intrinsic interfaces
192+
! -----------------------------------------------------------------------------
193+
194+
! CHECK-NAME: func.func @_QPintrinsic_iface()
195+
subroutine intrinsic_iface()
196+
intrinsic acos
197+
real :: x
198+
procedure(acos) :: proc
199+
x = proc(1.0)
200+
end subroutine
201+
! CHECK" fir.call @_QPproc(%{{.*}}) {{.*}}: (!fir.ref<f32>) -> f32

0 commit comments

Comments
 (0)