Index: flang/lib/Evaluate/intrinsics.cpp =================================================================== --- flang/lib/Evaluate/intrinsics.cpp +++ flang/lib/Evaluate/intrinsics.cpp @@ -1543,17 +1543,32 @@ dummy[dummyArgPatterns - 1].optionality == Optionality::repeats}; std::vector actualForDummy( isMaxMin ? 0 : dummyArgPatterns, nullptr); - int missingActualArguments{0}; + bool anyMissingActualArgument{false}; std::set maxMinKeywords; + bool anyKeyword{false}; + int which{0}; for (std::optional &arg : arguments) { - if (!arg) { - ++missingActualArguments; - } else if (arg->isAlternateReturn()) { - messages.Say(arg->sourceLocation(), - "alternate return specifier not acceptable on call to intrinsic '%s'"_err_en_US, - name); - return std::nullopt; - } else if (isMaxMin) { + ++which; + if (arg) { + if (arg->isAlternateReturn()) { + messages.Say(arg->sourceLocation(), + "alternate return specifier not acceptable on call to intrinsic '%s'"_err_en_US, + name); + return std::nullopt; + } + if (arg->keyword()) { + anyKeyword = true; + } else if (anyKeyword) { + messages.Say(arg ? arg->sourceLocation() : std::nullopt, + "actual argument #%d without a keyword may not follow an actual argument with a keyword"_err_en_US, + which); + return std::nullopt; + } + } else { + anyMissingActualArgument = true; + continue; + } + if (isMaxMin) { if (CheckMaxMinArgument(arg->keyword(), maxMinKeywords, name, messages)) { actualForDummy.push_back(&*arg); } else { @@ -1561,7 +1576,6 @@ } } else { bool found{false}; - int slot{missingActualArguments}; for (std::size_t j{0}; j < dummyArgPatterns && !found; ++j) { if (dummy[j].optionality == Optionality::missing) { continue; @@ -1584,7 +1598,7 @@ } } } else { - found = !actualForDummy[j] && slot-- == 0; + found = !actualForDummy[j] && !anyMissingActualArgument; } if (found) { actualForDummy[j] = &*arg; Index: flang/lib/Semantics/check-call.cpp =================================================================== --- flang/lib/Semantics/check-call.cpp +++ flang/lib/Semantics/check-call.cpp @@ -873,8 +873,11 @@ actuals.size(), proc.dummyArguments.size()); } std::map kwArgs; + bool anyKeyword{false}; + int which{1}; for (auto &x : actuals) { - if (x && x->keyword()) { + if (!x) { + } else if (x->keyword()) { auto emplaced{ kwArgs.try_emplace(x->keyword()->ToString(), std::move(*x))}; if (!emplaced.second) { @@ -883,7 +886,13 @@ *x->keyword()); } x.reset(); + anyKeyword = true; + } else if (anyKeyword) { + messages.Say(x ? x->sourceLocation() : std::nullopt, + "Actual argument #%d without a keyword may not follow any actual argument with a keyword"_err_en_US, + which); } + ++which; } if (!kwArgs.empty()) { int index{0}; Index: flang/test/Evaluate/fold-ishftc.f90 =================================================================== --- flang/test/Evaluate/fold-ishftc.f90 +++ flang/test/Evaluate/fold-ishftc.f90 @@ -1,7 +1,7 @@ ! RUN: %python %S/test_folding.py %s %flang_fc1 ! Tests folding of ISHFTC module m - integer, parameter :: shift8s(*) = ishftc(257, shift = [(ict, ict = -8, 8)], 8) + integer, parameter :: shift8s(*) = ishftc(257, shift = [(ict, ict = -8, 8)], size=8) integer, parameter :: expect1(*) = 256 + [1, 2, 4, 8, 16, 32, 64, 128, & 1, 2, 4, 8, 16, 32, 64, 128, 1] logical, parameter :: test_1 = all(shift8s == expect1) Index: flang/test/Semantics/collectives01.f90 =================================================================== --- flang/test/Semantics/collectives01.f90 +++ flang/test/Semantics/collectives01.f90 @@ -135,7 +135,7 @@ !ERROR: 'errmsg=' argument has unacceptable rank 1 call co_sum(d, errmsg=character_array) - !ERROR: too many actual arguments for intrinsic 'co_sum' + !ERROR: actual argument #5 without a keyword may not follow an actual argument with a keyword call co_sum(r, result_image=1, stat=status, errmsg=message, 3.4) ! keyword argument with incorrect name Index: flang/test/Semantics/collectives02.f90 =================================================================== --- flang/test/Semantics/collectives02.f90 +++ flang/test/Semantics/collectives02.f90 @@ -120,7 +120,7 @@ !ERROR: 'errmsg=' argument has unacceptable rank 1 call co_min(d, errmsg=character_array) - !ERROR: too many actual arguments for intrinsic 'co_min' + !ERROR: actual argument #5 without a keyword may not follow an actual argument with a keyword call co_min(r, result_image=1, stat=status, errmsg=message, 3.4) !ERROR: unknown keyword argument to intrinsic 'co_min' Index: flang/test/Semantics/collectives03.f90 =================================================================== --- flang/test/Semantics/collectives03.f90 +++ flang/test/Semantics/collectives03.f90 @@ -120,7 +120,7 @@ !ERROR: 'errmsg=' argument has unacceptable rank 1 call co_max(d, errmsg=character_array) - !ERROR: too many actual arguments for intrinsic 'co_max' + !ERROR: actual argument #5 without a keyword may not follow an actual argument with a keyword call co_max(r, result_image=1, stat=status, errmsg=message, 3.4) !ERROR: unknown keyword argument to intrinsic 'co_max' Index: flang/test/Semantics/collectives04.f90 =================================================================== --- flang/test/Semantics/collectives04.f90 +++ flang/test/Semantics/collectives04.f90 @@ -126,7 +126,7 @@ !ERROR: 'errmsg=' argument has unacceptable rank 1 call co_broadcast(d, errmsg=character_array, source_image=1) - !ERROR: too many actual arguments for intrinsic 'co_broadcast' + !ERROR: actual argument #5 without a keyword may not follow an actual argument with a keyword call co_broadcast(r, source_image=1, stat=status, errmsg=message, 3.4) !ERROR: unknown keyword argument to intrinsic 'co_broadcast' Index: flang/test/Semantics/lcobound.f90 =================================================================== --- flang/test/Semantics/lcobound.f90 +++ flang/test/Semantics/lcobound.f90 @@ -104,8 +104,11 @@ !ERROR: missing mandatory 'coarray=' argument n = lcobound(dim=i, kind=c_int32_t) + !ERROR: actual argument #2 without a keyword may not follow an actual argument with a keyword n = lcobound(coarray=scalar_coarray, i) + n = lcobound(coarray=scalar_coarray, dim=i) + !ERROR: missing mandatory 'coarray=' argument lcobounds = lcobound() Index: flang/test/Semantics/ucobound.f90 =================================================================== --- flang/test/Semantics/ucobound.f90 +++ flang/test/Semantics/ucobound.f90 @@ -104,8 +104,11 @@ !ERROR: missing mandatory 'coarray=' argument n = ucobound(dim=i, kind=c_int32_t) + !ERROR: actual argument #2 without a keyword may not follow an actual argument with a keyword n = ucobound(coarray=scalar_coarray, i) + n = ucobound(coarray=scalar_coarray, dim=i) + !ERROR: missing mandatory 'coarray=' argument ucobounds = ucobound()