Skip to content

Commit a21089a

Browse files
authored
[flang] Support COSHAPE() intrinsic function (#125286)
Enable COSHAPE in the intrinsics table and enable its test.
1 parent 9a49a03 commit a21089a

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

flang/lib/Evaluate/intrinsics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
421421
{"cos", {{"x", SameFloating}}, SameFloating},
422422
{"cosd", {{"x", SameFloating}}, SameFloating},
423423
{"cosh", {{"x", SameFloating}}, SameFloating},
424+
{"coshape", {{"coarray", AnyData, Rank::coarray}, SizeDefaultKIND}, KINDInt,
425+
Rank::vector, IntrinsicClass::inquiryFunction},
424426
{"count", {{"mask", AnyLogical, Rank::array}, OptionalDIM, DefaultingKIND},
425427
KINDInt, Rank::dimReduced, IntrinsicClass::transformationalFunction},
426428
{"cshift",
@@ -1054,8 +1056,6 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
10541056
{"__builtin_numeric_storage_size", {}, DefaultInt},
10551057
};
10561058

1057-
// TODO: Coarray intrinsic functions
1058-
// COSHAPE
10591059
// TODO: Non-standard intrinsic functions
10601060
// SHIFT,
10611061
// COMPL, EQV, NEQV, INT8, JINT, JNINT, KNINT,

flang/test/Semantics/coshape.f90

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
! RUN: %python %S/test_errors.py %s %flang_fc1
2-
! XFAIL: *
32
! Check for semantic errors in coshape() function,
43
! as defined in section 16.9.55 of the Fortran
54
! 2018 standard
@@ -8,18 +7,21 @@ program coshape_tests
87
use iso_c_binding, only : c_int32_t, c_int64_t
98
implicit none
109

10+
type t
11+
real x
12+
end type
1113
integer array(1), non_coarray(1), scalar_coarray[*], array_coarray(1)[*], non_constant, scalar_result
1214
real real_coarray[*]
1315
complex complex_coarray[*]
1416
character char_array(1)
1517
logical non_integer, logical_coarray[*]
18+
type(t) derived_scalar_coarray[*], derived_array_coarray(1)[*]
1619
integer, allocatable :: codimensions(:)
1720

1821
!___ standard-conforming statement with no optional arguments present ___
1922
codimensions = coshape(scalar_coarray)
2023
codimensions = coshape(array_coarray)
2124
codimensions = coshape(array_coarray(1))
22-
codimensions = coshape(scalar_coarray[1])
2325
codimensions = coshape(real_coarray)
2426
codimensions = coshape(logical_coarray)
2527
codimensions = coshape(complex_coarray)
@@ -33,54 +35,79 @@ program coshape_tests
3335

3436
!___ non-conforming statements ___
3537
! coarray argument must be a coarray
38+
!ERROR: 'coarray=' argument must have corank > 0 for intrinsic 'coshape'
3639
codimensions = coshape(non_coarray)
40+
!ERROR: 'coarray=' argument must have corank > 0 for intrinsic 'coshape'
41+
codimensions = coshape(derived_scalar_coarray[1]%x)
42+
!ERROR: 'coarray=' argument must have corank > 0 for intrinsic 'coshape'
43+
codimensions = coshape(derived_array_coarray[1]%x)
44+
!ERROR: 'coarray=' argument must have corank > 0 for intrinsic 'coshape'
45+
codimensions = coshape(array_coarray[1])
46+
!ERROR: 'coarray=' argument must have corank > 0 for intrinsic 'coshape'
47+
codimensions = coshape(scalar_coarray[1])
3748

3849
! kind argument must be an integer
50+
!ERROR: Actual argument for 'kind=' has bad type 'LOGICAL(4)'
3951
codimensions = coshape(scalar_coarray, non_integer)
4052

4153
! kind argument must be a constant expression
54+
!ERROR: 'kind=' argument must be a constant scalar integer whose value is a supported kind for the intrinsic result type
4255
codimensions = coshape(real_coarray, non_constant)
4356

4457
! kind argument must be an integer scalar
58+
!ERROR: 'kind=' argument has unacceptable rank 1
4559
codimensions = coshape(complex_coarray, array)
4660

4761
! missing all arguments
62+
!ERROR: missing mandatory 'coarray=' argument
4863
codimensions = coshape()
4964

5065
! missing mandatory argument
66+
!ERROR: missing mandatory 'coarray=' argument
5167
codimensions = coshape(kind=c_int32_t)
5268

5369
! incorrect typing for mandatory argument
70+
!ERROR: 'coarray=' argument must have corank > 0 for intrinsic 'coshape'
5471
codimensions = coshape(3.4)
5572

5673
! incorrect typing for coarray argument
74+
!ERROR: 'coarray=' argument must have corank > 0 for intrinsic 'coshape'
5775
codimensions = coshape(coarray=3.4)
5876

5977
! too many arguments
78+
!ERROR: too many actual arguments for intrinsic 'coshape'
6079
codimensions = coshape(scalar_coarray, c_int32_t, 0)
6180

6281
! incorrect typing with correct keyword for coarray argument
82+
!ERROR: 'coarray=' argument must have corank > 0 for intrinsic 'coshape'
6383
codimensions = coshape(coarray=non_coarray)
6484

6585
! correct typing with incorrect keyword for coarray argument
86+
!ERROR: unknown keyword argument to intrinsic 'coshape'
6687
codimensions = coshape(c=real_coarray)
6788

6889
! incorrect typing with correct keyword for kind argument
90+
!ERROR: Actual argument for 'kind=' has bad type 'LOGICAL(4)'
6991
codimensions = coshape(complex_coarray, kind=non_integer)
7092

7193
! correct typing with incorrect keyword for kind argument
94+
!ERROR: unknown keyword argument to intrinsic 'coshape'
7295
codimensions = coshape(logical_coarray, kinds=c_int32_t)
7396

7497
! repeated keyword for coarray argument
98+
!ERROR: repeated keyword argument to intrinsic 'coshape'
7599
codimensions = coshape(coarray=scalar_coarray, coarray=real_coarray)
76100

77101
! repeated keyword for kind argument
102+
!ERROR: repeated keyword argument to intrinsic 'coshape'
78103
codimensions = coshape(real_coarray, kind=c_int32_t, kind=c_int64_t)
79104

80105
! result must be a rank 1 array
106+
!ERROR: No intrinsic or user-defined ASSIGNMENT(=) matches scalar INTEGER(4) and rank 1 array of INTEGER(4)
81107
scalar_result = coshape(scalar_coarray)
82108

83109
! result must be an integer array
110+
!ERROR: No intrinsic or user-defined ASSIGNMENT(=) matches operand types CHARACTER(KIND=1) and INTEGER(4)
84111
char_array = coshape(real_coarray)
85112

86113
end program coshape_tests

0 commit comments

Comments
 (0)