This is an archive of the discontinued LLVM Phabricator instance.

[flang] Semantic-check for procedure pointers with assumed character length
ClosedPublic

Authored by tislam on Dec 5 2022, 7:55 AM.

Details

Summary

Apply C723 from Fortran 2018 standard for procedure pointers that have assumed character length.

C723 A function name declared with an asterisk type-param-value shall not be an array, a pointer, elemental, or pure. A function
name declared with an asterisk type-param-value shall not have the RECURSIVE attribute.

Diff Detail

Event Timeline

tislam created this revision.Dec 5 2022, 7:55 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 5 2022, 7:55 AM
tislam requested review of this revision.Dec 5 2022, 7:55 AM
DanielCChen requested changes to this revision.Dec 7 2022, 8:50 AM
DanielCChen added inline comments.
flang/lib/Semantics/check-declarations.cpp
356

According to C724 of F2018, a procedure pointer cannot have a result type that is of assumed-length character type, character(*), regardless if it is a dummy procedure or not, so IsDummy should not be checked.

358

I noticed other similar messages use "cannot" instead of "can not". Is there a rule for how the error message should be written?

This revision now requires changes to proceed.Dec 7 2022, 8:50 AM
clementval added inline comments.
flang/lib/Semantics/check-declarations.cpp
358

I'm not aware of any rule but consistency is probably better,

peixin retitled this revision from Semantic-check for procedure pointers with assumed character length to [flang] Semantic-check for procedure pointers with assumed character length.Dec 7 2022, 5:17 PM
peixin added a comment.Dec 7 2022, 5:23 PM

I think you are checking C723, not C724.

I think you are checking C723, not C724.

The constraint that disallows this is
"A function name declared with an asterisk type-param-value shall not be an array, a pointer, elemental, or pure. A function
name declared with an asterisk type-param-value shall not have the RECURSIVE attribute."
in which, "A function name ..... shall not be...., a pointer" disallow a procedure pointer to have assumed-length character type as its result type.

peixin added a comment.Dec 7 2022, 7:45 PM

"A function name declared with an asterisk type-param-value shall not be an array, a pointer, elemental, or pure. A function
name declared with an asterisk type-param-value shall not have the RECURSIVE attribute."

This is C723, not C724.

"A function name declared with an asterisk type-param-value shall not be an array, a pointer, elemental, or pure. A function
name declared with an asterisk type-param-value shall not have the RECURSIVE attribute."

This is C723, not C724.

Ah, Got it. I probably got the version of the standard wrong. Thanks!

tislam edited the summary of this revision. (Show Details)Dec 8 2022, 11:55 AM

"A function name declared with an asterisk type-param-value shall not be an array, a pointer, elemental, or pure. A function
name declared with an asterisk type-param-value shall not have the RECURSIVE attribute."

This is C723, not C724.

Thanks @peixin. I have updated the summary to mention C723.

klausler added a comment.EditedDec 8 2022, 12:58 PM

Assumed-length character function pointer dummy arguments work fine with gfortran and ifort, so this should be a supported extension with a portability warning, not a hard error.

module m
 contains
  subroutine subr(p)
    procedure(character(*)), pointer :: p
    print *, p()
  end subroutine
end module

character(*) function f()
  f = 'abcdefgh'
end function

program test
  use m
  character(4), external :: f
  procedure(character(4)), pointer :: p
  p => f
  call subr(p)
end
klausler requested changes to this revision.Dec 8 2022, 12:58 PM
tislam updated this revision to Diff 482117.Dec 12 2022, 7:25 AM

Addressed review comments. Changes include the following.

  • The message category is changed from ERROR to PORTABILITY.
  • The part "can not" is changed to "cannot" in the message text.
  • Added a new test Semantics/call30.f90 based on the example from @klausler. I added a local procedure pointer with character(*) return type, to the original example.
tislam marked 3 inline comments as done.Dec 12 2022, 7:27 AM
klausler accepted this revision.Dec 12 2022, 7:35 AM
klausler added inline comments.
flang/lib/Semantics/check-declarations.cpp
358

"should not" would be better for a warning.

DanielCChen accepted this revision.Dec 12 2022, 8:12 AM
This revision is now accepted and ready to land.Dec 12 2022, 8:12 AM
tislam updated this revision to Diff 482139.Dec 12 2022, 8:25 AM

Changed "cannot" to "should not" in the message text.

tislam marked an inline comment as done.Dec 12 2022, 8:27 AM
peixin accepted this revision.Dec 15 2022, 7:32 AM

@klausler has accepted this. He is the expert in this area. @tislam So I think you can land this now.