1! RUN: %S/test_folding.sh %s %t %flang_fc1 2! REQUIRES: shell 3! Test intrinsic function folding edge case (both expected value and messages) 4! These tests make assumptions regarding real(4) extrema. 5 6#define TEST_ISNAN(v) logical, parameter :: test_##v =.NOT.(v.EQ.v) 7 8 9module real_tests 10 ! Test real(4) intrinsic folding on edge cases (inf and NaN) 11 12 real(4), parameter :: r4_pmax = 3.4028235E38 13 real(4), parameter :: r4_nmax = -3.4028235E38 14 !WARN: invalid argument on division 15 real(4), parameter :: r4_nan = 0._4/0._4 16 !WARN: division by zero 17 real(4), parameter :: r4_pinf = 1._4/0._4 18 !WARN: division by zero 19 real(4), parameter :: r4_ninf = -1._4/0._4 20 21 !WARN: invalid argument on intrinsic function 22 real(4), parameter :: nan_r4_acos1 = acos(1.1) 23 TEST_ISNAN(nan_r4_acos1) 24 !WARN: invalid argument on intrinsic function 25 real(4), parameter :: nan_r4_acos2 = acos(r4_pmax) 26 TEST_ISNAN(nan_r4_acos2) 27 !WARN: invalid argument on intrinsic function 28 real(4), parameter :: nan_r4_acos3 = acos(r4_nmax) 29 TEST_ISNAN(nan_r4_acos3) 30 !WARN: invalid argument on intrinsic function 31 real(4), parameter :: nan_r4_acos4 = acos(r4_ninf) 32 TEST_ISNAN(nan_r4_acos4) 33 !WARN: invalid argument on intrinsic function 34 real(4), parameter :: nan_r4_acos5 = acos(r4_pinf) 35 TEST_ISNAN(nan_r4_acos5) 36 37 !WARN: overflow on intrinsic function 38 logical, parameter :: test_exp_overflow = exp(256._4).EQ.r4_pinf 39end module 40 41module parentheses 42 ! Test parentheses in folding (they are kept around constants to keep the 43 ! distinction between variable and expressions and require special care). 44 real(4), parameter :: x_nop = 0.1_4 45 real(4), parameter :: x_p = (x_nop) 46 logical, parameter :: test_parentheses1 = acos(x_p).EQ.acos(x_nop) 47end module 48 49module specific_extremums 50 ! f18 accepts all type kinds for the arguments of specific extremum intrinsics 51 ! instead of of only default kind (or double precision for DMAX1 and DMIN1). 52 ! This extensions is implemented by using the related generic intrinsic and 53 ! converting the result. 54 ! The tests below are cases where an implementation that converts the arguments to the 55 ! standard required types instead would give different results than the implementation 56 ! specified for f18 (converting the result). 57 integer(8), parameter :: max_i32_8 = 2_8**31-1 58 integer, parameter :: expected_min0 = int(min(max_i32_8, 2_8*max_i32_8), 4) 59 !WARN: argument types do not match specific intrinsic 'min0' requirements; using 'min' generic instead and converting the result to INTEGER(4) if needed 60 integer, parameter :: result_min0 = min0(max_i32_8, 2_8*max_i32_8) 61 ! result_min0 would be -2 if arguments were converted to default integer. 62 logical, parameter :: test_min0 = expected_min0 .EQ. result_min0 63 64 real, parameter :: expected_amax0 = real(max(max_i32_8, 2_8*max_i32_8), 4) 65 !WARN: argument types do not match specific intrinsic 'amax0' requirements; using 'max' generic instead and converting the result to REAL(4) if needed 66 real, parameter :: result_amax0 = amax0(max_i32_8, 2_8*max_i32_8) 67 ! result_amax0 would be 2.1474836E+09 if arguments were converted to default integer first. 68 logical, parameter :: test_amax0 = expected_amax0 .EQ. result_amax0 69end module 70