| 1 |
! RUN: %python %S/test_folding.py %s %flang_fc1 -pedantic |
| 2 |
! Test intrinsic function folding edge case (both expected value and messages) |
| 3 |
! These tests make assumptions regarding real(4) extrema. |
| 4 |
|
| 5 |
#define TEST_ISNAN(v) logical, parameter :: test_##v =.NOT.(v.EQ.v) |
| 6 |
|
| 7 |
|
| 8 |
module real_tests |
| 9 |
! Test real(4) intrinsic folding on edge cases (inf and NaN) |
| 10 |
|
| 11 |
real(4), parameter :: r4_pmax = 3.4028235E38 |
| 12 |
real(4), parameter :: r4_nmax = -3.4028235E38 |
| 13 |
!WARN: warning: invalid argument on division |
| 14 |
real(4), parameter :: r4_nan = 0._4/0._4 |
| 15 |
!WARN: warning: division by zero |
| 16 |
real(4), parameter :: r4_pinf = 1._4/0._4 |
| 17 |
!WARN: warning: division by zero |
| 18 |
real(4), parameter :: r4_ninf = -1._4/0._4 |
| 19 |
|
| 20 |
!WARN: warning: argument is out of range [-1., 1.] |
| 21 |
real(4), parameter :: nan_r4_acos1 = acos(1.1) |
| 22 |
TEST_ISNAN(nan_r4_acos1) |
| 23 |
!WARN: warning: argument is out of range [-1., 1.] |
| 24 |
real(4), parameter :: nan_r4_acos2 = acos(r4_pmax) |
| 25 |
TEST_ISNAN(nan_r4_acos2) |
| 26 |
!WARN: warning: argument is out of range [-1., 1.] |
| 27 |
real(4), parameter :: nan_r4_acos3 = acos(r4_nmax) |
| 28 |
TEST_ISNAN(nan_r4_acos3) |
| 29 |
!WARN: warning: argument is out of range [-1., 1.] |
| 30 |
real(4), parameter :: nan_r4_acos4 = acos(r4_ninf) |
| 31 |
TEST_ISNAN(nan_r4_acos4) |
| 32 |
!WARN: warning: argument is out of range [-1., 1.] |
| 33 |
real(4), parameter :: nan_r4_acos5 = acos(r4_pinf) |
| 34 |
TEST_ISNAN(nan_r4_acos5) |
| 35 |
!WARN: warning: argument is out of range [-1., 1.] |
| 36 |
real(8), parameter :: nan_r8_dasin1 = dasin(-1.1_8) |
| 37 |
TEST_ISNAN(nan_r8_dasin1) |
| 38 |
!WARN: warning: complex argument must be different from zero |
| 39 |
complex(4), parameter :: c4_clog1 = clog((0., 0.)) |
| 40 |
!WARN: warning: MOD: P argument is zero |
| 41 |
real(4), parameter :: nan_r4_mod = mod(3.5, 0.) |
| 42 |
TEST_ISNAN(nan_r4_mod) |
| 43 |
real(4), parameter :: ok_r4_gamma = gamma(-1.1) |
| 44 |
!WARN: warning: argument must not be a negative integer or zero |
| 45 |
real(4), parameter :: r4_gamma1 = gamma(0.) |
| 46 |
!WARN: warning: argument must not be a negative integer or zero |
| 47 |
real(4), parameter :: r4_gamma2 = gamma(-1.) |
| 48 |
real(4), parameter :: ok_r4_log_gamma = log_gamma(-2.001) |
| 49 |
!WARN: warning: argument must not be a negative integer or zero |
| 50 |
real(4), parameter :: r4_log_gamma1 = log_gamma(0.) |
| 51 |
!WARN: warning: argument must not be a negative integer or zero |
| 52 |
real(4), parameter :: r4_log_gamma2 = log_gamma(-100001.) |
| 53 |
!WARN: warning: 'x' and 'y' arguments must not be both zero |
| 54 |
real(4), parameter :: r4_atan2 = atan2(0., 0.) |
| 55 |
|
| 56 |
!WARN: warning: overflow on evaluation of intrinsic function or operation |
| 57 |
logical, parameter :: test_exp_overflow = exp(256._4).EQ.r4_pinf |
| 58 |
contains |
| 59 |
subroutine s1(a,j) |
| 60 |
!WARN: warning: MOD: P argument is zero |
| 61 |
print *, mod(a, 0.) |
| 62 |
!WARN: warning: MODULO: P argument is zero |
| 63 |
print *, modulo(a, 0.) |
| 64 |
!WARN: warning: MOD: P argument is zero |
| 65 |
print *, mod(j, 0.) |
| 66 |
!WARN: warning: MODULO: P argument is zero |
| 67 |
print *, modulo(j, 0.) |
| 68 |
end |
| 69 |
end module |
| 70 |
|
| 71 |
module parentheses |
| 72 |
! Test parentheses in folding (they are kept around constants to keep the |
| 73 |
! distinction between variable and expressions and require special care). |
| 74 |
real(4), parameter :: x_nop = 0.1_4 |
| 75 |
real(4), parameter :: x_p = (x_nop) |
| 76 |
logical, parameter :: test_parentheses1 = acos(x_p).EQ.acos(x_nop) |
| 77 |
end module |
| 78 |
|
| 79 |
module specific_extremums |
| 80 |
! f18 accepts all type kinds for the arguments of specific extremum intrinsics |
| 81 |
! instead of of only default kind (or double precision for DMAX1 and DMIN1). |
| 82 |
! This extensions is implemented by using the related generic intrinsic and |
| 83 |
! converting the result. |
| 84 |
! The tests below are cases where an implementation that converts the arguments to the |
| 85 |
! standard required types instead would give different results than the implementation |
| 86 |
! specified for f18 (converting the result). |
| 87 |
integer(8), parameter :: max_i32_8 = 2_8**31-1 |
| 88 |
integer, parameter :: expected_min0 = int(min(max_i32_8, 2_8*max_i32_8), 4) |
| 89 |
!WARN: portability: Argument types do not match specific intrinsic 'min0' requirements; using 'min' generic instead and converting the result to INTEGER(4) if needed |
| 90 |
integer, parameter :: result_min0 = min0(max_i32_8, 2_8*max_i32_8) |
| 91 |
! result_min0 would be -2 if arguments were converted to default integer. |
| 92 |
logical, parameter :: test_min0 = expected_min0 .EQ. result_min0 |
| 93 |
|
| 94 |
real, parameter :: expected_amax0 = real(max(max_i32_8, 2_8*max_i32_8), 4) |
| 95 |
!WARN: portability: Argument types do not match specific intrinsic 'amax0' requirements; using 'max' generic instead and converting the result to REAL(4) if needed |
| 96 |
real, parameter :: result_amax0 = amax0(max_i32_8, 2_8*max_i32_8) |
| 97 |
! result_amax0 would be 2.1474836E+09 if arguments were converted to default integer first. |
| 98 |
logical, parameter :: test_amax0 = expected_amax0 .EQ. result_amax0 |
| 99 |
end module |