Skip to content

Commit 7e03751

Browse files
committed
[flang1] Fix an MIN/MAX intrinsic bug
This patch solves two problems: 1.According to the fortran 2008 standard, add syntax check for MAX/MIN intrinsic, as follows: The arguments shall all be of the same type which shall be integer, real, or character and they shall all have the same kind type parameter. 2.The final type of argument with MIN/MAX intrinsic is determined by the type of highest precision atgument, not the first argument.
1 parent 08b46d7 commit 7e03751

File tree

11 files changed

+298
-0
lines changed

11 files changed

+298
-0
lines changed

test/f90_correct/inc/min_max_1.mk

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
build: $(SRC)/$(TEST).F90
6+
@echo ------------------------------------ building test $(TEST)
7+
-$(FC) -c $(SRC)/$(TEST).F90 > $(TEST).rslt 2>&1
8+
9+
run:
10+
@echo ------------------------------------ nothing to run for test $(TEST)
11+
12+
verify: $(TEST).rslt
13+
@echo ------------------------------------ verifying test $(TEST)
14+
$(COMP_CHECK) $(SRC)/$(TEST).F90 $(TEST).rslt $(FC)

test/f90_correct/inc/min_max_2.mk

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
build: $(SRC)/$(TEST).F90
6+
@echo ------------------------------------ building test $(TEST)
7+
-$(FC) -c $(SRC)/$(TEST).F90 > $(TEST).rslt 2>&1
8+
9+
run:
10+
@echo ------------------------------------ nothing to run for test $(TEST)
11+
12+
verify: $(TEST).rslt
13+
@echo ------------------------------------ verifying test $(TEST)
14+
$(COMP_CHECK) $(SRC)/$(TEST).F90 $(TEST).rslt $(FC)

test/f90_correct/inc/min_max_3.mk

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
build: $(SRC)/$(TEST).F90
6+
@echo ------------------------------------ building test $(TEST)
7+
-$(FC) -c $(SRC)/$(TEST).F90 > $(TEST).rslt 2>&1
8+
9+
run:
10+
@echo ------------------------------------ nothing to run for test $(TEST)
11+
12+
verify: $(TEST).rslt
13+
@echo ------------------------------------ verifying test $(TEST)
14+
$(COMP_CHECK) $(SRC)/$(TEST).F90 $(TEST).rslt $(FC)

test/f90_correct/lit/min_max_1.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3+
# See https://llvm.org/LICENSE.txt for license information.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
# Shared lit script for each tests. Run bash commands that run tests with make.
7+
8+
# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
9+
# RUN: cat %t | FileCheck %S/runmake

test/f90_correct/lit/min_max_2.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3+
# See https://llvm.org/LICENSE.txt for license information.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
# Shared lit script for each tests. Run bash commands that run tests with make.
7+
8+
# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
9+
# RUN: cat %t | FileCheck %S/runmake

test/f90_correct/lit/min_max_3.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3+
# See https://llvm.org/LICENSE.txt for license information.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
# Shared lit script for each tests. Run bash commands that run tests with make.
7+
8+
# REQUIRES: quadfp
9+
# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
10+
# RUN: cat %t | FileCheck %S/runmake

test/f90_correct/src/min_max_1.F90

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
! See https://llvm.org/LICENSE.txt for license information.
3+
! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
! Test that MIN/MAX intrinsic have not the same kind type parameter.
6+
7+
program test
8+
real(kind = 4) :: r4 = 1.0
9+
real(kind = 8) :: r8 = 1.0
10+
integer(kind = 1) :: i1 = 1
11+
integer(kind = 2) :: i2 = 1
12+
integer(kind = 4) :: i4 = 1
13+
integer(kind = 8) :: i8 = 1
14+
character(len = 1) :: c = "a"
15+
real :: res
16+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
17+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
18+
res = max(r4, i1)
19+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
20+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
21+
res = min(r4, i1)
22+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
23+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
24+
res = max(r4, i2)
25+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
26+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
27+
res = min(r4, i2)
28+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
29+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
30+
res = max(r4, i4)
31+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
32+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
33+
res = min(r4, i4)
34+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
35+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
36+
res = max(r4, i8)
37+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
38+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
39+
res = min(r4, i8)
40+
!{error "PGF90-S-0074-Illegal number or type of arguments to max"}
41+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
42+
res = max(r4, c)
43+
!{error "PGF90-S-0074-Illegal number or type of arguments to min"}
44+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
45+
res = min(r4, c)
46+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
47+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
48+
res = max(r8, i1)
49+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
50+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
51+
res = min(r8, i1)
52+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
53+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
54+
res = max(r8, i2)
55+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
56+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
57+
res = min(r8, i2)
58+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
59+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
60+
res = max(r8, i4)
61+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
62+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
63+
res = min(r8, i4)
64+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
65+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
66+
res = max(r8, i8)
67+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
68+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
69+
res = min(r8, i8)
70+
!{error "PGF90-S-0074-Illegal number or type of arguments to max"}
71+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
72+
res = max(r8, c)
73+
!{error "PGF90-S-0074-Illegal number or type of arguments to min"}
74+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
75+
res = min(r8, c)
76+
end

test/f90_correct/src/min_max_2.F90

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
! See https://llvm.org/LICENSE.txt for license information.
3+
! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
! Test that MIN/MAX intrinsic have not INTEGER, REAL, or CHARACTER arguments.
6+
7+
program test
8+
complex(kind = 4) :: c1 = 1.0
9+
complex(kind = 4) :: c2 = 1.0
10+
logical :: l1 = .true.
11+
logical :: l2 = .true.
12+
real :: res
13+
!{error "PGF90-S-0155-Arguments must be INTEGER, REAL, or CHARACTER!"}
14+
!{error "PGF90-S-0155-Arguments must be INTEGER, REAL, or CHARACTER!"}
15+
res = max(c1, c2)
16+
!{error "PGF90-S-0155-Arguments must be INTEGER, REAL, or CHARACTER!"}
17+
!{error "PGF90-S-0155-Arguments must be INTEGER, REAL, or CHARACTER!"}
18+
res = min(l1, l2)
19+
end
20+

test/f90_correct/src/min_max_3.F90

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
! See https://llvm.org/LICENSE.txt for license information.
3+
! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
! Test that MIN/MAX intrinsic have not the same kind type parameter.
6+
7+
program test
8+
real(kind = 16) :: r16 = 1.0
9+
integer(kind = 1) :: i1 = 1
10+
integer(kind = 2) :: i2 = 1
11+
integer(kind = 4) :: i4 = 1
12+
integer(kind = 8) :: i8 = 1
13+
character(len = 1) :: c = "a"
14+
real :: res
15+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
16+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
17+
res = max(r16, i1)
18+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
19+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
20+
res = min(r16, i1)
21+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
22+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
23+
res = max(r16, i2)
24+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
25+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
26+
res = min(r16, i2)
27+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
28+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
29+
res = max(r16, i4)
30+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
31+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
32+
res = min(r16, i4)
33+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
34+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
35+
res = max(r16, i8)
36+
!{warning "PGF90-W-0093-Type conversion of expression performed"}
37+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
38+
res = min(r16, i8)
39+
!{error "PGF90-S-0074-Illegal number or type of arguments to max"}
40+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
41+
res = max(r16, c)
42+
!{error "PGF90-S-0074-Illegal number or type of arguments to min"}
43+
!{error "PGF90-S-0155-Arguments must have the same kind type parameter!"}
44+
res = min(r16, c)
45+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
!
2+
! Part of the LLVM Project, under the Apache License v2.0 with LLVM
3+
! Exceptions.
4+
! See https://llvm.org/LICENSE.txt for license information.
5+
! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
!
7+
! Test that MIN/MAX intrinsic have different kind type.
8+
!
9+
! RUN: %flang -emit-llvm -S %s -o %t
10+
! RUN: cat %t | FileCheck %s -check-prefix=CHECK-DTYPE
11+
12+
! CHECK-DTYPE: fpext float {{%.*}} to double
13+
program test
14+
real(kind = 4) :: r4 = 2.0
15+
real(kind = 8) :: r8 = 1.0
16+
real(kind = 8) :: res
17+
res = min(r4, r8)
18+
end
19+

0 commit comments

Comments
 (0)