diff --git a/flang/lib/Evaluate/fold-integer.cpp b/flang/lib/Evaluate/fold-integer.cpp --- a/flang/lib/Evaluate/fold-integer.cpp +++ b/flang/lib/Evaluate/fold-integer.cpp @@ -731,7 +731,7 @@ } return i.ISHFT(posVal); })); - } else if (name == "lbound") { + } else if (name == "lbound" || name == "lcobound") { return LBOUND(context, std::move(funcRef)); } else if (name == "leadz" || name == "trailz" || name == "poppar" || name == "popcnt") { @@ -1038,7 +1038,7 @@ } } else if (name == "sum") { return FoldSum(context, std::move(funcRef)); - } else if (name == "ubound") { + } else if (name == "ubound" || name == "ucobound") { return UBOUND(context, std::move(funcRef)); } // TODO: dot_product, ishftc, matmul, sign, transfer diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp --- a/flang/lib/Evaluate/intrinsics.cpp +++ b/flang/lib/Evaluate/intrinsics.cpp @@ -511,6 +511,11 @@ KINDInt, Rank::scalar, IntrinsicClass::inquiryFunction}, {"lbound", {{"array", AnyData, Rank::anyOrAssumedRank}, SizeDefaultKIND}, KINDInt, Rank::vector, IntrinsicClass::inquiryFunction}, + {"lcobound", + {{"coarray", AnyData, Rank::coarray}, RequiredDIM, SizeDefaultKIND}, + KINDInt, Rank::scalar, IntrinsicClass::inquiryFunction}, + {"lcobound", {{"coarray", AnyData, Rank::coarray}, SizeDefaultKIND}, + KINDInt, Rank::vector, IntrinsicClass::inquiryFunction}, {"leadz", {{"i", AnyInt}}, DefaultInt}, {"len", {{"string", AnyChar, Rank::anyOrAssumedRank}, DefaultingKIND}, KINDInt, Rank::scalar, IntrinsicClass::inquiryFunction}, @@ -834,7 +839,7 @@ }; // TODO: Coarray intrinsic functions -// LCOBOUND, UCOBOUND, FAILED_IMAGES, IMAGE_INDEX, +// UCOBOUND, FAILED_IMAGES, IMAGE_INDEX, // STOPPED_IMAGES, COSHAPE // TODO: Non-standard intrinsic functions // LSHIFT, RSHIFT, SHIFT, ZEXT, IZEXT, diff --git a/flang/test/Semantics/lcobound.f90 b/flang/test/Semantics/lcobound.f90 --- a/flang/test/Semantics/lcobound.f90 +++ b/flang/test/Semantics/lcobound.f90 @@ -1,18 +1,20 @@ ! RUN: %python %S/test_errors.py %s %flang_fc1 -! XFAIL: * ! Check for semantic errors in lcobound() function references program lcobound_tests - use iso_c_binding, only : c_int32_t + use iso_c_binding, only : c_int32_t, c_int64_t implicit none integer n, i, array(1), non_coarray(1), scalar_coarray[*], array_coarray(1)[*], non_constant, scalar - logical non_integer + real real_coarray[*] + logical non_integer, logical_coarray[*] integer, allocatable :: lcobounds(:) !___ standard-conforming statement with no optional arguments present ___ lcobounds = lcobound(scalar_coarray) lcobounds = lcobound(array_coarray) + lcobounds = lcobound(real_coarray) + lcobounds = lcobound(logical_coarray) lcobounds = lcobound(coarray=scalar_coarray) !___ standard-conforming statements with optional dim argument present ___ @@ -41,37 +43,73 @@ n = lcobound(kind=c_int32_t, dim=1, coarray=scalar_coarray) !___ non-conforming statements ___ - n = lcobound(scalar_coarray, dim=1) + !ERROR: DIM=2 dimension is out of range for rank-1 array n = lcobound(array_coarray, dim=2) + + !ERROR: No intrinsic or user-defined ASSIGNMENT(=) matches scalar INTEGER(4) and rank 1 array of INTEGER(4) scalar = lcobound(scalar_coarray) + !ERROR: missing mandatory 'coarray=' argument n = lcobound(dim=i) + !ERROR: Actual argument for 'dim=' has bad type 'LOGICAL(4)' n = lcobound(scalar_coarray, non_integer) + !ERROR: Actual argument for 'dim=' has bad type 'LOGICAL(4)' n = lcobound(scalar_coarray, dim=non_integer) + !ERROR: missing mandatory 'dim=' argument lcobounds = lcobound(scalar_coarray, kind=non_integer) + + !ERROR: Actual argument for 'kind=' has bad type 'LOGICAL(4)' + lcobounds = lcobound(scalar_coarray, dim=1, kind=non_integer) + + !ERROR: missing mandatory 'dim=' argument lcobounds = lcobound(scalar_coarray, kind=non_constant) - n = lcobound(dim=i, kind=c_int32_t) + !ERROR: 'kind=' argument must be a constant scalar integer whose value is a supported kind for the intrinsic result type + lcobounds = lcobound(scalar_coarray, dim=1, kind=non_constant) - n = lcobound(coarray=scalar_coarray, i) + !ERROR: missing mandatory 'coarray=' argument + n = lcobound(dim=i, kind=c_int32_t) + !ERROR: missing mandatory 'dim=' argument lcobounds = lcobound(3.4) + !ERROR: 'coarray=' argument must have corank > 0 for intrinsic 'lcobound' + n = lcobound(coarray=3.4, 1) + + !ERROR: too many actual arguments for intrinsic 'lcobound' n = lcobound(scalar_coarray, i, c_int32_t, 0) + !ERROR: missing mandatory 'dim=' argument lcobounds = lcobound(coarray=non_coarray) + !ERROR: 'coarray=' argument must have corank > 0 for intrinsic 'lcobound' + lcobounds = lcobound(coarray=non_coarray, dim=1) + + !ERROR: Actual argument for 'kind=' has bad type 'LOGICAL(4)' n = lcobound(scalar_coarray, i, kind=non_integer) + !ERROR: 'dim=' argument has unacceptable rank 1 n = lcobound(scalar_coarray, array ) + !ERROR: unknown keyword argument to intrinsic 'lcobound' lcobounds = lcobound(c=scalar_coarray) + !ERROR: unknown keyword argument to intrinsic 'lcobound' n = lcobound(scalar_coarray, dims=i) + !ERROR: unknown keyword argument to intrinsic 'lcobound' n = lcobound(scalar_coarray, i, kinds=c_int32_t) + !ERROR: repeated keyword argument to intrinsic 'lcobound' + n = lcobound(scalar_coarray, dim=1, dim=2) + + !ERROR: repeated keyword argument to intrinsic 'lcobound' + lcobounds = lcobound(coarray=scalar_coarray, coarray=array_coarray) + + !ERROR: repeated keyword argument to intrinsic 'lcobound' + lcobounds = lcobound(scalar_coarray, kind=c_int32_t, kind=c_int64_t) + end program lcobound_tests