This is an archive of the discontinued LLVM Phabricator instance.

[flang] add evaluate::IsAllocatableDesignator helper
ClosedPublic

Authored by jeanPerier on Apr 1 2022, 5:53 AM.

Details

Summary

Previously, some semantic checks that are checking if an entity is an
allocatable were relying on the expression being a designator whose
last symbol has the allocatable attribute.

This is wrong since this was considering substrings and array sections of
allocatables as being allocatable. This is wrong (see NOTE 2 in
Fortran 2018 section 9.5.3).

Add evaluate::IsAllocatableDesignator to correctly test this.
Also add some semantic tests for ALLOCATED to test the newly added helper.
Note that ifort and nag are rejecting coindexed-named-object in
ALLOCATED (allocated(coarray_scalar_alloc[2])).
I think it is wrong given allocated argument is intent(in) as per
16.2.1 point 3.
So 15.5.2.6 point 4 regarding allocatable dummy is not violated (If the actual
argument is a coindexed object, the dummy argument shall have the INTENT (IN)
attribute.) and I think this is valid. gfortran accepts it.

The need for this helper was exposed in https://reviews.llvm.org/D122779.

Diff Detail

Event Timeline

jeanPerier created this revision.Apr 1 2022, 5:53 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: jdoerfert. · View Herald Transcript
jeanPerier requested review of this revision.Apr 1 2022, 5:53 AM
peixin added inline comments.Apr 1 2022, 8:13 AM
flang/include/flang/Evaluate/tools.h
917

Nit: Remove expr to be consistent with others.

flang/lib/Evaluate/tools.cpp
1097

Should you add one comment (2018 9.5.3 NOTE 2) here?

peixin added inline comments.Apr 1 2022, 8:37 AM
flang/lib/Semantics/check-call.cpp
404

This fix is not tested in this patch. So can you move the test case in call05.f90 in D122779 to this case? D122779 will focus on the other check (The actual argument shall have deferred the same type parameters as the dummy argument if the argument is allocatable or pointer variable). It's better to keep one patch as complete.

There is a naming clash with semantics::IsAllocatable().

schweitz accepted this revision.Apr 1 2022, 9:59 AM
schweitz added a subscriber: schweitz.

LGTM.

This revision is now accepted and ready to land.Apr 1 2022, 9:59 AM

There is a naming clash with semantics::IsAllocatable().

I see. Would evaluate::IsAllocatableEntity() sounds good to you ?

There is a naming clash with semantics::IsAllocatable().

I see. Would evaluate::IsAllocatableEntity() sounds good to you ?

"Designator" seems best. "Variable" would also work, but the only variables that aren't designators are the returned values of pointer-valued functions, and they cannot be allocatable.

Rename evaluate::IsAllocatable to evaluate::IsAllocatableDesignator.
Add Call05.f90 relevant tests from https://reviews.llvm.org/D122779.
Remove arg name in declaration and add reference to standard.

klausler accepted this revision.Apr 1 2022, 12:31 PM
jeanPerier marked 3 inline comments as done.Apr 1 2022, 12:31 PM

This fix is not tested in this patch. So can you move the test case in call05.f90 in D122779 to this case?

Sure, done. I will add you as a contributor to this patch.

jeanPerier retitled this revision from [flang] add evaluate::IsAllocatable helper to [flang] add evaluate::IsAllocatableDesignator helper.Apr 1 2022, 12:32 PM
jeanPerier edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.
peixin added a comment.Apr 1 2022, 6:46 PM

This fix is not tested in this patch. So can you move the test case in call05.f90 in D122779 to this case?

Sure, done. I will add you as a contributor to this patch.

Thanks, @jeanPerier .

peixin added a comment.Apr 4 2022, 8:24 PM

Cherry-pick this and D122779 to fir-dev in https://github.com/flang-compiler/f18-llvm-project/pull/1557 since D122779 made some changes in lowering test cases in case that it affects the upstreaming work.