[flang-commits] [flang] b6713fe - [flang] Add one semantic check for procedure bind(C) interface-name
via flang-commits
flang-commits at lists.llvm.org
Wed Jun 8 09:39:02 PDT 2022
Author: PeixinQiao
Date: 2022-06-09T00:38:14+08:00
New Revision: b6713feec76af095fa066aa6a4aad72783e5d7d2
URL: https://github.com/llvm/llvm-project/commit/b6713feec76af095fa066aa6a4aad72783e5d7d2
DIFF: https://github.com/llvm/llvm-project/commit/b6713feec76af095fa066aa6a4aad72783e5d7d2.diff
LOG: [flang] Add one semantic check for procedure bind(C) interface-name
As Fortran 2018 C1521, in procedure declaration statement, if
proc-language-binding-spec (bind(c)) is specified, the proc-interface
shall appear, it shall be an interface-name, and interface-name shall
be declared with a proc-language-binding-spec.
Reviewed By: klausler, Jean Perier
Differential Revision: https://reviews.llvm.org/D127121
Added:
flang/test/Semantics/bind-c03.f90
Modified:
flang/lib/Semantics/check-declarations.cpp
flang/test/Semantics/modfile16.f90
flang/test/Semantics/resolve82.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index b193252442db9..fff0197bf9a82 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -1897,6 +1897,13 @@ void CheckHelper::CheckBindC(const Symbol &symbol) {
}
}
}
+ if (const auto *proc{symbol.detailsIf<ProcEntityDetails>()}) {
+ if (!proc->interface().symbol() ||
+ !proc->interface().symbol()->attrs().test(Attr::BIND_C)) {
+ messages_.Say(symbol.name(),
+ "An interface name with BIND attribute must be specified if the BIND attribute is specified in a procedure declaration statement"_err_en_US);
+ }
+ }
}
bool CheckHelper::CheckDioDummyIsData(
diff --git a/flang/test/Semantics/bind-c03.f90 b/flang/test/Semantics/bind-c03.f90
new file mode 100644
index 0000000000000..03a544b1954d7
--- /dev/null
+++ b/flang/test/Semantics/bind-c03.f90
@@ -0,0 +1,24 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! Check for C1521
+! If proc-language-binding-spec (bind(c)) is specified, the proc-interface
+! shall appear, it shall be an interface-name, and interface-name shall be
+! declared with a proc-language-binding-spec.
+
+module m
+
+ interface
+ subroutine proc1() bind(c)
+ end
+ subroutine proc2()
+ end
+ end interface
+
+ procedure(proc1), bind(c) :: pc1 ! no error
+
+ !ERROR: An interface name with BIND attribute must be specified if the BIND attribute is specified in a procedure declaration statement
+ procedure(proc2), bind(c) :: pc2
+
+ !ERROR: An interface name with BIND attribute must be specified if the BIND attribute is specified in a procedure declaration statement
+ procedure(integer), bind(c) :: pc3
+
+end
diff --git a/flang/test/Semantics/modfile16.f90 b/flang/test/Semantics/modfile16.f90
index 9599f19a6b7e8..2c596fc500814 100644
--- a/flang/test/Semantics/modfile16.f90
+++ b/flang/test/Semantics/modfile16.f90
@@ -6,15 +6,6 @@ module m
type, bind(c) :: t
real :: c
end type
- real :: d
- external :: d
- bind(c, name='dd') :: d
- real :: e
- bind(c, name='ee') :: e
- external :: e
- bind(c, name='ff') :: f
- real :: f
- external :: f
contains
subroutine sub() bind(c, name='sub')
end
@@ -28,9 +19,6 @@ subroutine sub() bind(c, name='sub')
! type,bind(c)::t
! real(4)::c
! end type
-! procedure(real(4)),bind(c, name="dd")::d
-! procedure(real(4)),bind(c, name="ee")::e
-! procedure(real(4)),bind(c, name="ff")::f
!contains
! subroutine sub() bind(c, name="sub")
! end
diff --git a/flang/test/Semantics/resolve82.f90 b/flang/test/Semantics/resolve82.f90
index ef216abd23dbc..69cf407884c23 100644
--- a/flang/test/Semantics/resolve82.f90
+++ b/flang/test/Semantics/resolve82.f90
@@ -19,6 +19,7 @@ end function procFunc
!WARNING: Attribute 'PRIVATE' cannot be used more than once
procedure(procFunc), private, pointer, private :: proc2
!WARNING: Attribute 'BIND(C)' cannot be used more than once
+ !ERROR: An interface name with BIND attribute must be specified if the BIND attribute is specified in a procedure declaration statement
procedure(procFunc), bind(c), pointer, bind(c) :: proc3
!WARNING: Attribute 'PROTECTED' cannot be used more than once
procedure(procFunc), protected, pointer, protected :: proc4
More information about the flang-commits
mailing list