From c6a23df691fbfb1330d1fef71a4ac8b453b62a87 Mon Sep 17 00:00:00 2001 From: Katherine Rasmussen Date: Tue, 7 Jul 2020 12:31:06 -0700 Subject: [PATCH] [flang] Make 'num_images()' intrinsic I added 'num_images()' to the list of functions that are evaluated as intrinsic. I also added a test file in flang/test/Semantics to test calls to 'num_images()'. There was a call to 'num_images()' in flang/test/Semantics/call10.f90 that expected an error, now it no longer produces an error. So I edited that file accordingly. I also edited the intrinsics unit test to add further testing of 'num_images()'. Differential Revision: https://reviews.llvm.org/D83142 --- flang/documentation/Intrinsics.md | 2 +- flang/lib/Evaluate/intrinsics.cpp | 6 +++++- flang/test/Semantics/call10.f90 | 1 - flang/test/Semantics/num_images.f90 | 30 +++++++++++++++++++++++++++++ flang/unittests/Evaluate/intrinsics.cpp | 34 +++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 flang/test/Semantics/num_images.f90 diff --git a/flang/documentation/Intrinsics.md b/flang/documentation/Intrinsics.md index 381f3a3..8fd0676 100644 --- a/flang/documentation/Intrinsics.md +++ b/flang/documentation/Intrinsics.md @@ -701,7 +701,7 @@ This phase currently supports all the intrinsic procedures listed above but the | Intrinsic Category | Intrinsic Procedures Lacking Support | | --- | --- | -| Coarray intrinsic functions | LCOBOUND, UCOBOUND, FAILED_IMAGES, GET_TEAM, IMAGE_INDEX, NUM_IMAGES, STOPPED_IMAGES, TEAM_NUMBER, THIS_IMAGE, COSHAPE | +| Coarray intrinsic functions | LCOBOUND, UCOBOUND, FAILED_IMAGES, GET_TEAM, IMAGE_INDEX, STOPPED_IMAGES, TEAM_NUMBER, THIS_IMAGE, COSHAPE | | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE | | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY| | Non-standard intrinsic functions | AND, OR, XOR, LSHIFT, RSHIFT, SHIFT, ZEXT, IZEXT, COSD, SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, DCMPLX, EQV, NEQV, INT8, JINT, JNINT, KNINT, LOC, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, INT_PTR_KIND, ISNAN, MALLOC | diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp index be155f8..6237499 100644 --- a/flang/lib/Evaluate/intrinsics.cpp +++ b/flang/lib/Evaluate/intrinsics.cpp @@ -581,6 +581,10 @@ static const IntrinsicInterface genericIntrinsicFunction[]{ Rank::dimReduced, IntrinsicClass::transformationalFunction}, {"not", {{"i", SameInt}}, SameInt}, // NULL() is a special case handled in Probe() below + {"num_images", {}, DefaultInt, Rank::scalar, + IntrinsicClass::transformationalFunction}, + {"num_images", {{"team_number", AnyInt, Rank::scalar}}, DefaultInt, + Rank::scalar, IntrinsicClass::transformationalFunction}, {"out_of_range", {{"x", AnyIntOrReal}, {"mold", AnyIntOrReal, Rank::scalar}}, DefaultLogical}, @@ -724,7 +728,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{ // TODO: Coarray intrinsic functions // LCOBOUND, UCOBOUND, FAILED_IMAGES, GET_TEAM, IMAGE_INDEX, -// NUM_IMAGES, STOPPED_IMAGES, TEAM_NUMBER, THIS_IMAGE, +// STOPPED_IMAGES, TEAM_NUMBER, THIS_IMAGE, // COSHAPE // TODO: Non-standard intrinsic functions // AND, OR, XOR, LSHIFT, RSHIFT, SHIFT, ZEXT, IZEXT, diff --git a/flang/test/Semantics/call10.f90 b/flang/test/Semantics/call10.f90 index 5966b89..e7b29c7 100644 --- a/flang/test/Semantics/call10.f90 +++ b/flang/test/Semantics/call10.f90 @@ -185,7 +185,6 @@ module m ! implicit sync all !ERROR: Procedure 'this_image' referenced in pure subprogram 's14' must be pure too img = this_image() - !ERROR: Procedure 'num_images' referenced in pure subprogram 's14' must be pure too nimgs = num_images() i = img ! i is ready to use diff --git a/flang/test/Semantics/num_images.f90 b/flang/test/Semantics/num_images.f90 new file mode 100644 index 0000000..788b542 --- /dev/null +++ b/flang/test/Semantics/num_images.f90 @@ -0,0 +1,30 @@ +! RUN: %S/test_errors.sh %s %t %f18 +! Check for semantic errors in num_images() function calls + +subroutine test + + ! correct calls, should produce no errors + print *, num_images() + print *, num_images(team_number=1) + print *, num_images(1) + + ! incorrectly typed argument + ! the error is seen as too many arguments to the num_images() call with no arguments + !ERROR: too many actual arguments for intrinsic 'num_images' + print *, num_images(3.4) + + ! call with too many arguments + !ERROR: too many actual arguments for intrinsic 'num_images' + print *, num_images(1, 1) + + ! keyword argument with incorrect type + !ERROR: unknown keyword argument to intrinsic 'num_images' + print *, num_images(team_number=3.4) + + ! incorrect keyword argument + !ERROR: unknown keyword argument to intrinsic 'num_images' + print *, num_images(team_numbers=1) + + !TODO: test num_images() calls related to team_type argument + +end subroutine diff --git a/flang/unittests/Evaluate/intrinsics.cpp b/flang/unittests/Evaluate/intrinsics.cpp index 7123ef6..57f7196 100644 --- a/flang/unittests/Evaluate/intrinsics.cpp +++ b/flang/unittests/Evaluate/intrinsics.cpp @@ -257,6 +257,40 @@ void TestIntrinsics() { TestCall{defaults, table, "idint"} .Push(Const(Scalar{})) .DoCall(Int4::GetType()); + + TestCall{defaults, table, "num_images"}.DoCall(Int4::GetType()); + TestCall{defaults, table, "num_images"} + .Push(Const(Scalar{})) + .DoCall(Int4::GetType()); + TestCall{defaults, table, "num_images"} + .Push(Const(Scalar{})) + .DoCall(Int4::GetType()); + TestCall{defaults, table, "num_images"} + .Push(Const(Scalar{})) + .DoCall(Int4::GetType()); + TestCall{defaults, table, "num_images"} + .Push(Named("team_number", Const(Scalar{}))) + .DoCall(Int4::GetType()); + TestCall{defaults, table, "num_images"} + .Push(Const(Scalar{})) + .Push(Const(Scalar{})) + .DoCall(); // too many args + TestCall{defaults, table, "num_images"} + .Push(Named("bad", Const(Scalar{}))) + .DoCall(); // bad keyword + TestCall{defaults, table, "num_images"} + .Push(Const(Scalar{})) + .DoCall(); // bad type + TestCall{defaults, table, "num_images"} + .Push(Const(Scalar{})) + .DoCall(); // bad type + TestCall{defaults, table, "num_images"} + .Push(Const(Scalar{})) + .DoCall(); // bad type + TestCall{defaults, table, "num_images"} + .Push(Const(Scalar{})) + .DoCall(); // bad type + // TODO: test other intrinsics } } // namespace Fortran::evaluate -- 2.7.4