brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.0 KiB · 027db20 Raw
100 lines · plain
1! RUN: %python %S/test_folding.py %s %flang_fc1 -pedantic2! 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 8module real_tests9  ! Test real(4) intrinsic folding on edge cases (inf and NaN)10 11  real(4), parameter :: r4_pmax = 3.4028235E3812  real(4), parameter :: r4_nmax = -3.4028235E3813  !WARN: warning: invalid argument on division [-Wfolding-exception]14  real(4), parameter :: r4_nan = 0._4/0._415  !WARN: warning: division by zero [-Wfolding-exception]16  real(4), parameter :: r4_pinf = 1._4/0._417  !WARN: warning: division by zero [-Wfolding-exception]18  real(4), parameter :: r4_ninf = -1._4/0._419 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 zero39  complex(4), parameter :: c4_clog1 = clog((0., 0.))40  !WARN: warning: MOD: P argument is zero [-Wfolding-avoids-runtime-crash]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 zero45  real(4), parameter :: r4_gamma1 = gamma(0.)46  !WARN: warning: argument must not be a negative integer or zero47  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 zero50  real(4), parameter :: r4_log_gamma1 = log_gamma(0.)51  !WARN: warning: argument must not be a negative integer or zero52  real(4), parameter :: r4_log_gamma2 = log_gamma(-100001.)53  !WARN: warning: 'x' and 'y' arguments must not be both zero54  real(4), parameter :: r4_atan2 = atan2(0., 0.)55 56  !WARN: warning: overflow on evaluation of intrinsic function or operation [-Wfolding-exception]57  logical, parameter :: test_exp_overflow = exp(256._4).EQ.r4_pinf58 contains59  subroutine s1(a,j)60    !WARN: warning: MOD: P argument is zero [-Wfolding-avoids-runtime-crash]61    print *, mod(a, 0.)62    !WARN: warning: MODULO: P argument is zero [-Wfolding-avoids-runtime-crash]63    print *, modulo(a, 0.)64    !WARN: warning: MOD: P argument is zero [-Wfolding-avoids-runtime-crash]65    print *, mod(j, 0.)66    !WARN: warning: MODULO: P argument is zero [-Wfolding-avoids-runtime-crash]67    print *, modulo(j, 0.)68  end69end module70 71module parentheses72  ! Test parentheses in folding (they are kept around constants to keep the73  ! distinction between variable and expressions and require special care).74  real(4), parameter :: x_nop = 0.1_475  real(4), parameter :: x_p = (x_nop)76  logical, parameter :: test_parentheses1 = acos(x_p).EQ.acos(x_nop)77end module78 79module specific_extremums80  ! f18 accepts all type kinds for the arguments of specific extremum intrinsics81  ! instead of of only default kind (or double precision for DMAX1 and DMIN1).82  ! This extensions is implemented by using the related generic intrinsic and83  ! converting the result.84  ! The tests below are cases where an implementation that converts the arguments to the85  ! standard required types instead would give different results than the implementation86  ! specified for f18 (converting the result).87  integer(8), parameter :: max_i32_8 = 2_8**31-188  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 [-Wuse-generic-intrinsic-when-specific-doesnt-match]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_min093 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 [-Wuse-generic-intrinsic-when-specific-doesnt-match]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_amax099end module100