[flang-commits] [flang] ac44cb7 - [flang] Add two semantic checks about BIND(C) attribute

via flang-commits flang-commits at lists.llvm.org
Mon Oct 24 19:21:23 PDT 2022


Author: Peixin-Qiao
Date: 2022-10-25T10:19:54+08:00
New Revision: ac44cb7617a8e46cc23e0d1def4764f7bc13f978

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

LOG: [flang] Add two semantic checks about BIND(C) attribute

As Fortran 2018 C1546, an elemental procedure shall not have the BIND
attribute.

As 18.3.6, it does not mention that an array with VALUE can be
interoperable. It is not reasonable to pass an array by value when the
array is too large. Forbid it to be consistent with gfortran/ifort.

Reviewed By: jeanPerier

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

Added: 
    flang/test/Semantics/bind-c08.f90

Modified: 
    flang/lib/Lower/CallInterface.cpp
    flang/lib/Semantics/check-declarations.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp
index 5dfe949939ad9..190c5619dface 100644
--- a/flang/lib/Lower/CallInterface.cpp
+++ b/flang/lib/Lower/CallInterface.cpp
@@ -935,9 +935,6 @@ class Fortran::lower::CallInterfaceImpl {
                             Fortran::common::TypeCategory::Derived)) {
           passBy = PassEntityBy::Value;
           prop = Property::Value;
-          if (type.isa<fir::SequenceType>())
-            fir::emitFatalError(
-                loc, "array with VALUE attribute is not interoperable");
           if (fir::isa_builtin_cptr_type(type)) {
             auto recTy = type.dyn_cast<fir::RecordType>();
             mlir::Type fieldTy = recTy.getTypeList()[0].second;

diff  --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 0586dead49d2b..7bd26202c4cbc 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -429,10 +429,15 @@ void CheckHelper::CheckValue(
   if (symbol.attrs().test(Attr::VOLATILE)) {
     messages_.Say("VALUE attribute may not apply to a VOLATILE"_err_en_US);
   }
-  if (innermostSymbol_ && IsBindCProcedure(*innermostSymbol_) &&
-      IsOptional(symbol)) {
-    messages_.Say(
-        "VALUE attribute may not apply to an OPTIONAL in a BIND(C) procedure"_err_en_US);
+  if (innermostSymbol_ && IsBindCProcedure(*innermostSymbol_)) {
+    if (IsOptional(symbol)) {
+      messages_.Say(
+          "VALUE attribute may not apply to an OPTIONAL in a BIND(C) procedure"_err_en_US);
+    }
+    if (symbol.Rank() > 0) {
+      messages_.Say(
+          "VALUE attribute may not apply to an array in a BIND(C) procedure"_err_en_US);
+    }
   }
   if (derived) {
     if (FindCoarrayUltimateComponent(*derived)) {
@@ -1914,6 +1919,7 @@ void CheckHelper::CheckBindC(const Symbol &symbol) {
     return;
   }
   CheckConflicting(symbol, Attr::BIND_C, Attr::PARAMETER);
+  CheckConflicting(symbol, Attr::BIND_C, Attr::ELEMENTAL);
   if (symbol.has<ObjectEntityDetails>() && !symbol.owner().IsModule()) {
     messages_.Say(symbol.name(),
         "A variable with BIND(C) attribute may only appear in the specification part of a module"_err_en_US);

diff  --git a/flang/test/Semantics/bind-c08.f90 b/flang/test/Semantics/bind-c08.f90
new file mode 100644
index 0000000000000..fe04f7c5e8c2a
--- /dev/null
+++ b/flang/test/Semantics/bind-c08.f90
@@ -0,0 +1,11 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! Check for C1546 and 18.3.6
+
+! ERROR: 'test1' may not have both the BIND(C) and ELEMENTAL attributes
+elemental subroutine test1() bind(c)
+end
+
+subroutine test3(x) bind(c)
+  ! ERROR: VALUE attribute may not apply to an array in a BIND(C) procedure
+  integer, value :: x(100)
+end


        


More information about the flang-commits mailing list