Skip to content

Commit

Permalink
[flang] Fix one regression failure related to BIND(C) statement
Browse files Browse the repository at this point in the history
For BIND(C) statement, two common block with the same name can have the
same bind name. Fix the regression failure by adding this check. Also add
the regression tests.

Co-authored-by: Jean Perier <jperier@nvidia.com>

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D127841
  • Loading branch information
PeixinQiao committed Jun 15, 2022
1 parent 9c8fe39 commit 60e3599
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion flang/lib/Semantics/check-declarations.cpp
Expand Up @@ -1892,7 +1892,10 @@ void CheckHelper::CheckBindC(const Symbol &symbol) {
auto pair{bindC_.emplace(*name, symbol)};
if (!pair.second) {
const Symbol &other{*pair.first->second};
if (DefinesBindCName(other) && !context_.HasError(other)) {
// Two common blocks with the same name can have the same BIND(C) name.
if ((!symbol.has<CommonBlockDetails>() ||
symbol.name() != other.name()) &&
DefinesBindCName(other) && !context_.HasError(other)) {
if (auto *msg{messages_.Say(symbol.name(),
"Two symbols have the same BIND(C) name '%s'"_err_en_US,
*name)}) {
Expand Down
21 changes: 21 additions & 0 deletions flang/test/Semantics/declarations03.f90
Expand Up @@ -48,3 +48,24 @@ module m
integer, bind(c, name="ss2") :: s5

end

subroutine common1()
real :: x
common /com/ x
bind(c, name='xcom') /com/ ! no error
end subroutine

subroutine common2()
real :: x
common /com/ x
bind(c, name='xcom') /com/ ! no error
end subroutine

module a
integer, bind(c, name="int") :: i
end module

module b
!ERROR: Two symbols have the same BIND(C) name 'int'
integer, bind(c, name="int") :: i
end module

0 comments on commit 60e3599

Please sign in to comment.