This is an archive of the discontinued LLVM Phabricator instance.

[flang] Add semantic check for C1520
ClosedPublic

Authored by peixin on Jun 14 2022, 1:23 AM.

Details

Summary

As Fortran 2018 C1520, if proc-language-binding-spec with NAME= is
specified, then proc-decl-list shall contain exactly one proc-decl,
which shall neither have the POINTER attribute nor be a dummy procedure.
Add this check.

Diff Detail

Event Timeline

peixin created this revision.Jun 14 2022, 1:23 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: jdoerfert. · View Herald Transcript
peixin requested review of this revision.Jun 14 2022, 1:23 AM

This patch fails to catch the most important part of the constraint: that only one entity may appear.

flang/lib/Semantics/resolve-names.cpp
1050

The data member should be hasBindCName_ and it is its own comment.

4687

auto *bindC{...};
hasBindCName_ = bindC && bindC->v;

This patch fails to catch the most important part of the constraint: that only one entity may appear.

It is checked in check-declarations.cpp, which has better message format. This constraint has the same style as common block and varaibles. I also add the test case in this patch. This one:

!ERROR: Two symbols have the same BIND(C) name 'aaa'
procedure(proc), bind(c, name="aaa") :: pc1, pc2
peixin updated this revision to Diff 437013.Jun 14 2022, 8:23 PM

Address the code style comments.

peixin added inline comments.Jun 14 2022, 11:41 PM
flang/lib/Semantics/resolve-names.cpp
1050

Thanks. Fixed.

4687

This is not correct for procedure(proc), bind(c, name="bbb"), pointer :: pc3 since it has multiple parser::ProcAttrSpec. Also add one break here to speedup this analysis. Put the assignment not in the if condition will also fail for the case procedure(proc), bind(c, name="pc8"), bind(c), pointer :: pc8 (Check the test case below).

klausler added inline comments.Jun 21 2022, 8:57 AM
flang/lib/Semantics/resolve-names.cpp
4766

Can this check be done in check-declarations?

peixin added inline comments.Jun 21 2022, 7:50 PM
flang/lib/Semantics/resolve-names.cpp
4766

It seems not since it is unknown if the bind name is from NAME= specifier. The test cases are added in this patch:

!ERROR: BIND(C) procedure with NAME= specified can neither have POINTER attribute nor be a dummy procedure
procedure(proc), bind(c, name="pc6"), pointer :: pc6

procedure(proc), bind(c), pointer :: pc7
klausler accepted this revision.Jun 22 2022, 8:37 AM
This revision is now accepted and ready to land.Jun 22 2022, 8:37 AM
This revision was automatically updated to reflect the committed changes.