[flang-commits] [flang] cff7fad - [flang] Catch repeated BIND(C) attribute specifications for a symbol

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Mon Feb 13 18:07:28 PST 2023


Author: Peter Klausler
Date: 2023-02-13T18:07:16-08:00
New Revision: cff7fad1544a299f2509ccd845065cbb3a531cd1

URL: https://github.com/llvm/llvm-project/commit/cff7fad1544a299f2509ccd845065cbb3a531cd1
DIFF: https://github.com/llvm/llvm-project/commit/cff7fad1544a299f2509ccd845065cbb3a531cd1.diff

LOG: [flang] Catch repeated BIND(C) attribute specifications for a symbol

A BIND(C) attribute statement or type-declaration-stmt attribute, just
like most attributes, can only appear once.  Name resolution was excluding
the BIND(C) attribute from its check for duplicated attributes, but I
don't see a reason that remains to do so.

Differential Revision: https://reviews.llvm.org/D143834

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Semantics/bind-c02.f90
    flang/test/Semantics/declarations03.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 8c32a74ec9c6..4cd6905f6235 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -2672,8 +2672,8 @@ void ScopeHandler::MakeExternal(Symbol &symbol) {
 
 bool ScopeHandler::CheckDuplicatedAttr(
     SourceName name, const Symbol &symbol, Attr attr) {
-  if (attr == Attr::SAVE || attr == Attr::BIND_C) {
-    // these are checked elsewhere
+  if (attr == Attr::SAVE) {
+    // checked elsewhere
   } else if (symbol.attrs().test(attr)) { // C815
     if (symbol.implicitAttrs().test(attr)) {
       // Implied attribute is now confirmed explicitly

diff  --git a/flang/test/Semantics/bind-c02.f90 b/flang/test/Semantics/bind-c02.f90
index c1b44ccd887f..9ff6cf54bfa0 100644
--- a/flang/test/Semantics/bind-c02.f90
+++ b/flang/test/Semantics/bind-c02.f90
@@ -6,10 +6,10 @@
 module m
 
   interface
-    subroutine proc() bind(c)
+    subroutine proc()
     end
   end interface
-  procedure(proc), bind(c) :: pc1
+  procedure(proc) :: pc1
   !ERROR: Only variable and named common block can be in BIND statement
   bind(c) :: proc
   !ERROR: Only variable and named common block can be in BIND statement

diff  --git a/flang/test/Semantics/declarations03.f90 b/flang/test/Semantics/declarations03.f90
index 6eda65c95fc5..3459b2287b2b 100644
--- a/flang/test/Semantics/declarations03.f90
+++ b/flang/test/Semantics/declarations03.f90
@@ -32,6 +32,7 @@ module m
   !ERROR: The entity 's1' has multiple BIND names
   integer :: s1
   bind(c, name="gg") :: s1
+  !ERROR: BIND_C attribute was already specified on 's1'
   bind(c, name="hh") :: s1
 
   !ERROR: Two entities have the same global name 'ii'
@@ -41,10 +42,12 @@ module m
 
   !ERROR: The entity 's4' has multiple BIND names
   integer, bind(c, name="ss1") :: s4
+  !ERROR: BIND_C attribute was already specified on 's4'
   bind(c, name="jj") :: s4
 
   !ERROR: The entity 's5' has multiple BIND names
   bind(c, name="kk") :: s5
+  !ERROR: BIND_C attribute was already specified on 's5'
   integer, bind(c, name="ss2") :: s5
 
 end


        


More information about the flang-commits mailing list