diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp --- a/flang/lib/Lower/CallInterface.cpp +++ b/flang/lib/Lower/CallInterface.cpp @@ -935,9 +935,6 @@ Fortran::common::TypeCategory::Derived)) { passBy = PassEntityBy::Value; prop = Property::Value; - if (type.isa()) - fir::emitFatalError( - loc, "array with VALUE attribute is not interoperable"); if (fir::isa_builtin_cptr_type(type)) { auto recTy = type.dyn_cast(); mlir::Type fieldTy = recTy.getTypeList()[0].second; diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -429,10 +429,15 @@ 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 @@ return; } CheckConflicting(symbol, Attr::BIND_C, Attr::PARAMETER); + CheckConflicting(symbol, Attr::BIND_C, Attr::ELEMENTAL); if (symbol.has() && !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 --- /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