[flang-commits] [flang] 60e3599 - [flang] Fix one regression failure related to BIND(C) statement
via flang-commits
flang-commits at lists.llvm.org
Wed Jun 15 06:11:08 PDT 2022
Author: PeixinQiao
Date: 2022-06-15T21:10:36+08:00
New Revision: 60e359943bfc22155cd239c9b40b3e4c41026915
URL: https://github.com/llvm/llvm-project/commit/60e359943bfc22155cd239c9b40b3e4c41026915
DIFF: https://github.com/llvm/llvm-project/commit/60e359943bfc22155cd239c9b40b3e4c41026915.diff
LOG: [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 at nvidia.com>
Reviewed By: clementval
Differential Revision: https://reviews.llvm.org/D127841
Added:
Modified:
flang/lib/Semantics/check-declarations.cpp
flang/test/Semantics/declarations03.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index c8260f598c150..9f5eeadd07b32 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -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)}) {
diff --git a/flang/test/Semantics/declarations03.f90 b/flang/test/Semantics/declarations03.f90
index a6709c25684fe..cf6d44374a1ba 100644
--- a/flang/test/Semantics/declarations03.f90
+++ b/flang/test/Semantics/declarations03.f90
@@ -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
More information about the flang-commits
mailing list