[flang-commits] [flang] bc2a85f - [flang] Add co_broadcast to the list of intrinsics
Katherine Rasmussen via flang-commits
flang-commits at lists.llvm.org
Wed Sep 28 09:31:17 PDT 2022
Author: Katherine Rasmussen
Date: 2022-09-28T09:29:11-07:00
New Revision: bc2a85f16c5825ebbfe8a07d5159fcb028f2e5d5
URL: https://github.com/llvm/llvm-project/commit/bc2a85f16c5825ebbfe8a07d5159fcb028f2e5d5
DIFF: https://github.com/llvm/llvm-project/commit/bc2a85f16c5825ebbfe8a07d5159fcb028f2e5d5.diff
LOG: [flang] Add co_broadcast to the list of intrinsics
Add the collective subroutine, co_broadcast, to the list
of intrinsic subroutines. Add co_broadcast to the check
for coindexed objects for the first, third, and fourth dummy
arguments. Update the co_broadcast semantics test.
Reviewed By: jeanPerier
Differential Revision: https://reviews.llvm.org/D134786
Added:
Modified:
flang/docs/Intrinsics.md
flang/lib/Evaluate/intrinsics.cpp
flang/test/Semantics/collectives04.f90
Removed:
################################################################################
diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index 8d5785f6f0c9..baa0609c7cca 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -752,7 +752,7 @@ This phase currently supports all the intrinsic procedures listed above but the
| 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 |
| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, SYSTEM_CLOCK |
| Atomic intrinsic subroutines | ATOMIC_ADD &al. |
-| Collective intrinsic subroutines | CO_BROADCAST &al. |
+| Collective intrinsic subroutines | CO_REDUCE |
### Intrinsic Function Folding
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 5ba70de58915..b87f44b9d6b9 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -1087,6 +1087,16 @@ static const SpecificIntrinsicInterface specificIntrinsicFunction[]{
static const IntrinsicInterface intrinsicSubroutine[]{
{"abort", {}, {}, Rank::elemental, IntrinsicClass::impureSubroutine},
+ {"co_broadcast",
+ {{"a", AnyData, Rank::anyOrAssumedRank, Optionality::required,
+ common::Intent::InOut},
+ {"source_image", AnyInt, Rank::scalar, Optionality::required,
+ common::Intent::In},
+ {"stat", AnyInt, Rank::scalar, Optionality::optional,
+ common::Intent::Out},
+ {"errmsg", DefaultChar, Rank::scalar, Optionality::optional,
+ common::Intent::InOut}},
+ {}, Rank::elemental, IntrinsicClass::collectiveSubroutine},
{"co_max",
{{"a", AnyIntOrRealOrChar, Rank::anyOrAssumedRank,
Optionality::required, common::Intent::InOut},
@@ -1219,7 +1229,7 @@ static const IntrinsicInterface intrinsicSubroutine[]{
// TODO: Intrinsic subroutine EVENT_QUERY
// TODO: Atomic intrinsic subroutines: ATOMIC_ADD &al.
-// TODO: Collective intrinsic subroutines: CO_BROADCAST &al.
+// TODO: Collective intrinsic subroutines: co_reduce
// Finds a built-in derived type and returns it as a DynamicType.
static DynamicType GetBuiltinDerivedType(
@@ -2472,7 +2482,8 @@ static bool ApplySpecificChecks(SpecificCall &call, FoldingContext &context) {
}
} else if (name == "associated") {
return CheckAssociated(call, context);
- } else if (name == "co_max" || name == "co_min" || name == "co_sum") {
+ } else if (name == "co_broadcast" || name == "co_max" || name == "co_min" ||
+ name == "co_sum") {
bool aOk{CheckForCoindexedObject(context, call.arguments[0], name, "a")};
bool statOk{
CheckForCoindexedObject(context, call.arguments[2], name, "stat")};
diff --git a/flang/test/Semantics/collectives04.f90 b/flang/test/Semantics/collectives04.f90
index 4bfaf2999df3..37b5b2fcd533 100644
--- a/flang/test/Semantics/collectives04.f90
+++ b/flang/test/Semantics/collectives04.f90
@@ -1,5 +1,4 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
-! XFAIL: *
! This test checks for semantic errors in co_broadcast subroutine calls based on
! the co_broadcast interface defined in section 16.9.46 of the Fortran 2018 standard.
! To Do: add co_broadcast to the list of intrinsics
@@ -10,8 +9,8 @@ program test_co_broadcast
type foo_t
end type
- integer i, integer_array(1), coindexed_integer[*], status
- character(len=1) c, character_array(1), coindexed_character[*], message
+ integer i, integer_array(1), coindexed_integer[*], status, coindexed_source_image[*], repeated_status
+ character(len=1) c, character_array(1), coindexed_character[*], message, repeated_message
double precision d, double_precision_array(1)
type(foo_t) f
real r, real_array(1), coindexed_real[*]
@@ -31,82 +30,111 @@ program test_co_broadcast
!___ standard-conforming calls with keyword arguments ___
! all arguments present
- call co_broadcast(a=i, source_image=1, stat=status, errmsg=message)
- call co_broadcast(source_image=1, a=i, errmsg=message, stat=status)
+ call co_broadcast(a=i, source_image=1, stat=status, errmsg=message)
+ call co_broadcast(source_image=1, a=i, errmsg=message, stat=status)
! one optional argument not present
call co_broadcast(a=d, source_image=1, errmsg=message)
call co_broadcast(a=f, source_image=1, stat=status )
! two optional arguments not present
- call co_broadcast(a=r, source_image=1 )
+ call co_broadcast(a=r, source_image=1 )
+ call co_broadcast(a=r, source_image=coindexed_source_image )
!___ non-standard-conforming calls ___
+ !ERROR: missing mandatory 'a=' argument
+ call co_broadcast()
+
+ !ERROR: repeated keyword argument to intrinsic 'co_broadcast'
+ call co_broadcast(a=i, a=c)
+
+ !ERROR: repeated keyword argument to intrinsic 'co_broadcast'
+ call co_broadcast(d, source_image=1, source_image=3)
+
+ !ERROR: repeated keyword argument to intrinsic 'co_broadcast'
+ call co_broadcast(d, 1, stat=status, stat=repeated_status)
+
+ !ERROR: repeated keyword argument to intrinsic 'co_broadcast'
+ call co_broadcast(d, 1, status, errmsg=message, errmsg=repeated_message)
+
+ !ERROR: keyword argument to intrinsic 'co_broadcast' was supplied positionally by an earlier actual argument
+ call co_broadcast(i, 1, a=c)
+
+ !ERROR: keyword argument to intrinsic 'co_broadcast' was supplied positionally by an earlier actual argument
+ call co_broadcast(i, 1, status, source_image=1)
+
+ !ERROR: keyword argument to intrinsic 'co_broadcast' was supplied positionally by an earlier actual argument
+ call co_broadcast(i, 1, status, stat=repeated_status)
+
+ !ERROR: keyword argument to intrinsic 'co_broadcast' was supplied positionally by an earlier actual argument
+ call co_broadcast(i, 1, status, message, errmsg=repeated_message)
+
!ERROR: missing mandatory 'a=' argument
call co_broadcast(source_image=1, stat=status, errmsg=message)
!ERROR: missing mandatory 'source_image=' argument
- call co_broadcast(a=c, stat=status, errmsg=message)
+ call co_broadcast(c)
+
+ !ERROR: missing mandatory 'source_image=' argument
+ call co_broadcast(a=c, stat=status, errmsg=message)
- ! argument 'a' is intent(inout)
!ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'a=' must be definable
call co_broadcast(a=1+1, source_image=1)
-
- ! argument 'a' shall not be a coindexed object
- !ERROR: to be determined
+
+ !ERROR: 'a' argument to 'co_broadcast' may not be a coindexed object
call co_broadcast(a=coindexed_real[1], source_image=1)
-
+
! 'source_image' argument shall be an integer
!ERROR: Actual argument for 'source_image=' has bad type 'LOGICAL(4)'
call co_broadcast(i, source_image=bool)
-
+
! 'source_image' argument shall be an integer scalar
!ERROR: 'source_image=' argument has unacceptable rank 1
call co_broadcast(c, source_image=integer_array)
-
- ! 'stat' argument shall be intent(out)
+
!ERROR: Actual argument associated with INTENT(OUT) dummy argument 'stat=' must be definable
call co_broadcast(a=i, source_image=1, stat=1+1, errmsg=message)
- ! 'stat' argument shall be noncoindexed
- !ERROR: to be determined
+ !ERROR: 'stat' argument to 'co_broadcast' may not be a coindexed object
call co_broadcast(d, stat=coindexed_integer[1], source_image=1)
-
+
! 'stat' argument shall be an integer
!ERROR: Actual argument for 'stat=' has bad type 'CHARACTER(KIND=1,LEN=1_8)'
call co_broadcast(r, stat=message, source_image=1)
-
- ! 'stat' argument shall be an integer scalar
+
!ERROR: 'stat=' argument has unacceptable rank 1
call co_broadcast(i, stat=integer_array, source_image=1)
-
- ! 'errmsg' argument shall be intent(inout)
+
!ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'errmsg=' must be definable
call co_broadcast(a=i, source_image=1, stat=status, errmsg='c')
- ! 'errmsg' argument shall be noncoindexed
- !ERROR: to be determined
+ !ERROR: 'errmsg' argument to 'co_broadcast' may not be a coindexed object
call co_broadcast(c, errmsg=coindexed_character[1], source_image=1)
! 'errmsg' argument shall be a character
- !ERROR: to be determined
+ !ERROR: Actual argument for 'errmsg=' has bad type 'INTEGER(4)'
call co_broadcast(c, 1, status, i)
! 'errmsg' argument shall be a character
- !ERROR: to be determined
+ !ERROR: Actual argument for 'errmsg=' has bad type 'INTEGER(4)'
call co_broadcast(c, errmsg=i, source_image=1)
- ! 'errmsg' argument shall be character scalar
!ERROR: 'errmsg=' argument has unacceptable rank 1
call co_broadcast(d, errmsg=character_array, source_image=1)
-
- ! the error is seen as too many arguments to the co_broadcast() call
+
!ERROR: too many actual arguments for intrinsic 'co_broadcast'
call co_broadcast(r, source_image=1, stat=status, errmsg=message, 3.4)
-
- ! keyword argument with incorrect name
+
!ERROR: unknown keyword argument to intrinsic 'co_broadcast'
call co_broadcast(fake=3.4)
-
+
+ !ERROR: unknown keyword argument to intrinsic 'co_broadcast'
+ call co_broadcast(a=i, result_image=1, stat=status, errmsg=message)
+
+ !ERROR: 'a' argument to 'co_broadcast' may not be a coindexed object
+ !ERROR: 'errmsg' argument to 'co_broadcast' may not be a coindexed object
+ !ERROR: 'stat' argument to 'co_broadcast' may not be a coindexed object
+ call co_broadcast(source_image=coindexed_source_image[1], a=coindexed_real[1], errmsg=coindexed_character[1], stat=coindexed_integer[1])
+
end program test_co_broadcast
More information about the flang-commits
mailing list