[flang] Fix one regression failure related to BIND(C) statement

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
This commit is contained in:
PeixinQiao 2022-06-15 21:10:36 +08:00
parent 9c8fe394cf
commit 60e359943b
2 changed files with 25 additions and 1 deletions

View File

@ -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)}) {

View File

@ -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