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