[WebAssembly] Fix asan issue from https://reviews.llvm.org/D121349
[llvm-project.git] / flang / test / Evaluate / folding20.f90
blobbe012074fb4bda9c37e0f1706fba502cd3fd4a30
1 ! RUN: %python %S/test_folding.py %s %flang_fc1
2 ! Tests reduction intrinsic function folding
3 module m
4 implicit none
5 integer, parameter :: intmatrix(*,*) = reshape([1, 2, 3, 4, 5, 6], [2, 3])
6 logical, parameter :: odds(2,3) = mod(intmatrix, 2) == 1
7 character(*), parameter :: chmatrix(*,*) = reshape(['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr'], [2, 3])
9 logical, parameter :: test_allidentity = all([Logical::])
10 logical, parameter :: test_all = .not. all(odds)
11 logical, parameter :: test_alldim1 = all(.not. all(odds,1))
12 logical, parameter :: test_alldim2 = all(all(odds,2) .eqv. [.true., .false.])
13 logical, parameter :: test_anyidentity = .not. any([Logical::])
14 logical, parameter :: test_any = any(odds)
15 logical, parameter :: test_anydim1 = all(any(odds,1))
16 logical, parameter :: test_anydim2 = all(any(odds,2) .eqv. [.true., .false.])
18 logical, parameter :: test_iallidentity = iall([integer::]) == -1
19 logical, parameter :: test_iall = iall(intmatrix) == 0
20 logical, parameter :: test_iall_masked = iall(intmatrix,odds) == 1
21 logical, parameter :: test_ialldim1 = all(iall(intmatrix,dim=1) == [0, 0, 4])
22 logical, parameter :: test_ialldim2 = all(iall(intmatrix,dim=2) == [1, 0])
23 logical, parameter :: test_ianyidentity = iany([integer::]) == 0
24 logical, parameter :: test_iany = iany(intmatrix) == 7
25 logical, parameter :: test_iany_masked = iany(intmatrix,odds) == 7
26 logical, parameter :: test_ianydim1 = all(iany(intmatrix,dim=1) == [3, 7, 7])
27 logical, parameter :: test_ianydim2 = all(iany(intmatrix,dim=2) == [7, 6])
28 logical, parameter :: test_iparityidentity = iparity([integer::]) == 0
29 logical, parameter :: test_iparity = iparity(intmatrix) == 7
30 logical, parameter :: test_iparity_masked = iparity(intmatrix,odds) == 7
31 logical, parameter :: test_iparitydim1 = all(iparity(intmatrix,dim=1) == [3, 7, 3])
32 logical, parameter :: test_iparitydim2 = all(iparity(intmatrix,dim=2) == [7, 0])
34 logical, parameter :: test_imaxidentity = maxval([integer::]) == -huge(0) - 1
35 logical, parameter :: test_iminidentity = minval([integer::]) == huge(0)
36 logical, parameter :: test_imaxval = maxval(intmatrix) == 6
37 logical, parameter :: test_iminval = minval(intmatrix) == 1
38 logical, parameter :: test_imaxval_masked = maxval(intmatrix,odds) == 5
39 logical, parameter :: test_iminval_masked = minval(intmatrix,.not.odds) == 2
40 logical, parameter :: test_rmaxidentity = maxval([real::]) == -huge(0.0)
41 logical, parameter :: test_rminidentity = minval([real::]) == huge(0.0)
42 logical, parameter :: test_rmaxval = maxval(real(intmatrix)) == 6.0
43 logical, parameter :: test_rminval = minval(real(intmatrix)) == 1.0
44 logical, parameter :: test_rmaxval_scalar_mask = maxval(real(intmatrix), .true.) == 6.0
45 logical, parameter :: test_rminval_scalar_mask = minval(real(intmatrix), .false.) == huge(0.0)
46 logical, parameter :: test_cmaxlen = len(maxval([character*4::])) == 4
47 logical, parameter :: test_cmaxidentity = maxval([character*4::]) == repeat(char(0), 4)
48 logical, parameter :: test_cminidentity = minval([character*4::]) == repeat(char(127), 4)
49 logical, parameter :: test_cmaxval = maxval(chmatrix) == 'pqr'
50 logical, parameter :: test_cminval = minval(chmatrix) == 'abc'
51 logical, parameter :: test_maxvaldim1 = all(maxval(intmatrix,dim=1) == [2, 4, 6])
52 logical, parameter :: test_minvaldim2 = all(minval(intmatrix,dim=2,mask=odds) == [1, huge(0)])
54 logical, parameter :: test_iproductidentity = product([integer::]) == 1
55 logical, parameter :: test_iproduct = product(intmatrix) == 720
56 logical, parameter :: test_iproduct_masked = product(intmatrix,odds) == 15
57 logical, parameter :: test_productdim1 = all(product(intmatrix,dim=1) == [2, 12, 30])
58 logical, parameter :: test_productdim2 = all(product(intmatrix,dim=2) == [15, 48])
59 logical, parameter :: test_rproductidentity = product([real::]) == 1.
60 logical, parameter :: test_rproduct = product(real(intmatrix)) == 720.
61 logical, parameter :: test_cproductidentity = product([complex::]) == (1.,0.)
62 logical, parameter :: test_cproduct = product(cmplx(intmatrix,-intmatrix)) == (0.,5760.)
64 logical, parameter :: test_isumidentity = sum([integer::]) == 0
65 logical, parameter :: test_isum = sum(intmatrix) == 21
66 logical, parameter :: test_isum_masked = sum(intmatrix,odds) == 9
67 logical, parameter :: test_sumdim1 = all(sum(intmatrix,dim=1) == [3, 7, 11])
68 logical, parameter :: test_sumdim2 = all(sum(intmatrix,dim=2) == [9, 12])
69 logical, parameter :: test_rsumidentity = sum([real::]) == 0.
70 logical, parameter :: test_rsum = sum(real(intmatrix)) == 21.
71 logical, parameter :: test_csumidentity = sum([complex::]) == (0.,0.)
72 logical, parameter :: test_csum = sum(cmplx(intmatrix,-intmatrix)) == (21.,-21.)
73 end