This is an archive of the discontinued LLVM Phabricator instance.

[flang] Complement one-to-one association check of bind name and entity name
ClosedPublic

Authored by peixin on Jun 3 2022, 5:54 AM.

Details

Summary

As Fortran 2018 C802 and C873, if bind name is specified, there can only
be only one entity. The check for common block is missed before. As
Fortran 2018 8.5.5 point 2, the bind name is one identifier, which is
unique. That is, one entity can not have multiple bind names. Also add
this check.

Diff Detail

Event Timeline

peixin created this revision.Jun 3 2022, 5:54 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 3 2022, 5:54 AM
klausler added inline comments.Jun 7 2022, 8:50 AM
flang/lib/Semantics/check-declarations.cpp
380

Would be less confusing if you reversed the test and deleted the return statement.

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

This is written in a confusing style. Try this:

auto oldName{symbol.GetBindName()};
symbol.SetBindName(std::move(*label));
if (oldName) {
  if (auto newName{symbol.GetBindName()}) {
    if (*oldName != *newName) {
      // error
    }
  }
}
peixin updated this revision to Diff 435076.Jun 8 2022, 1:46 AM
peixin added a comment.Jun 8 2022, 1:49 AM

Addressed the comments from @klausler .

flang/lib/Semantics/check-declarations.cpp
380

Fixed.

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

symbol.GetBindName() returns the pointer to oldName. After symbol.SetBindName, oldName points to the new symbol.GetBindName(). So oldName must store the value of bind name. But change the style as suggested.

jeanPerier accepted this revision.Jun 13 2022, 7:15 AM
jeanPerier added inline comments.
flang/lib/Semantics/resolve-names.cpp
1685
if (std::string newBindName* = symbol.GetBindName()) {
...
}
This revision is now accepted and ready to land.Jun 13 2022, 7:15 AM
peixin updated this revision to Diff 436620.Jun 13 2022, 7:10 PM

Address the comments from @jeanPerier .

This program no longer compiles after this patch:

subroutine subr

bind(c,name="foo") /blk/
integer j
common /blk/ j
print *, j

end
program main

bind(c,name="foo") /blk/
integer j
common /blk/ j
j = 123
call subr

end

peixin added a comment.EditedJun 15 2022, 5:56 PM

This program no longer compiles after this patch:

subroutine subr

bind(c,name="foo") /blk/
integer j
common /blk/ j
print *, j

end
program main

bind(c,name="foo") /blk/
integer j
common /blk/ j
j = 123
call subr

end

Thanks for this. @jeanPerier has sent me one similar regression test yesterday and it has been fixed by https://reviews.llvm.org/rG60e359943bfc22155cd239c9b40b3e4c41026915.