Fortran: Follow fixes to -freal-{4,8}-real* handling [PR99355,PR57871]

gcc/fortran/ChangeLog:

	PR fortran/99355
	PR fortran/57871
	* invoke.texi (-freal{4,8}-real-*): Extend description.
	* primary.c (match_real_constant): Also promote real literals
	with '_kind' number.

gcc/testsuite/ChangeLog:

	* gfortran.dg/real4-10-real8-10.f90: Add check for real literals
	with '_kind' number.
	* gfortran.dg/real4-10-real8-16.f90: Likewise.
	* gfortran.dg/real4-10-real8-4.f90: Likewise.
	* gfortran.dg/real4-10.f90: Likewise.
	* gfortran.dg/real4-16-real8-10.f90: Likewise.
	* gfortran.dg/real4-16-real8-16.f90: Likewise.
	* gfortran.dg/real4-16-real8-4.f90: Likewise.
	* gfortran.dg/real4-16.f90: Likewise.
	* gfortran.dg/real4-8-real8-10.f90: Likewise.
	* gfortran.dg/real4-8-real8-16.f90: Likewise.
	* gfortran.dg/real4-8-real8-4.f90: Likewise.
	* gfortran.dg/real4-8.f90: Likewise.
	* gfortran.dg/real8-10.f90: Likewise.
	* gfortran.dg/real8-16.f90: Likewise.
	* gfortran.dg/real8-4.f90: Likewise.
This commit is contained in:
Tobias Burnus 2021-03-05 10:43:11 +01:00
parent 8d240b3f06
commit 80cf2facbb
17 changed files with 94 additions and 34 deletions

View File

@ -520,13 +520,24 @@ representation of the translated Fortran code, produced by
@cindex options, real kind type promotion
Promote all @code{REAL(KIND=M)} entities to @code{REAL(KIND=N)} entities.
If @code{REAL(KIND=N)} is unavailable, then an error will be issued.
All other real kind types are unaffected by this option.
The @code{-freal-4-} flags also affect the default real kind and the
@code{-freal-8-} flags also the double-precision real kind. All other
real-kind types are unaffected by this option. The promotion is also
applied to real literal constants of default and double-precision kind
and a specified kind number of 4 or 8, respectively.
However, @code{-fdefault-real-8}, @code{-fdefault-real-10},
@code{-fdefault-real-10}, and @code{-fdefault-double-8} take precedence
for the default and double-precision real kinds, both for real literal
constants and for declarations without a kind number.
Note that for @code{REAL(KIND=KIND(1.0))} the literal may get promoted and
then the result may get promoted again.
These options should be used with care and may not be suitable for your
codes. Areas of possible concern include calls to external procedures,
alignment in @code{EQUIVALENCE} and/or @code{COMMON}, generic interfaces,
BOZ literal constant conversion, and I/O. Inspection of the intermediate
representation of the translated Fortran code, produced by
@option{-fdump-tree-original}, is suggested.
BOZ literal constant conversion, and I/O and calls to intrinsic procedures
when passing a value to the @code{kind=} dummy argument. Inspection of the
intermediate representation of the translated Fortran code, produced by
@option{-fdump-fortran-original} or @option{-fdump-tree-original}, is suggested.
@item -std=@var{std}
@opindex @code{std=}@var{std} option

View File

@ -666,6 +666,25 @@ done:
if (kind == -1)
goto cleanup;
if (kind == 4)
{
if (flag_real4_kind == 8)
kind = 8;
if (flag_real4_kind == 10)
kind = 10;
if (flag_real4_kind == 16)
kind = 16;
}
else if (kind == 8)
{
if (flag_real8_kind == 4)
kind = 4;
if (flag_real8_kind == 10)
kind = 10;
if (flag_real8_kind == 16)
kind = 16;
}
switch (exp_char)
{
case 'd':

View File

@ -2,6 +2,7 @@
! { dg-additional-options "-w -freal-4-real-10 -freal-8-real-10" }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -9,6 +10,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -18,6 +20,6 @@ program test
!print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
!print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 10)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 10)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 10)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 10)) stop 2
end program test

View File

@ -3,6 +3,7 @@
! { dg-require-effective-target fortran_real_16 }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -10,6 +11,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -19,6 +21,6 @@ program test
!print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
!print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 10)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 16)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 10)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 16)) stop 2
end program test

View File

@ -2,6 +2,7 @@
! { dg-additional-options "-w -freal-4-real-10 -freal-8-real-4" }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -9,6 +10,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -18,6 +20,6 @@ program test
!print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
!print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 10)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d5)] /= 4)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 10)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d5)] /= 4)) stop 2
end program test

View File

@ -2,6 +2,7 @@
! { dg-additional-options "-w -freal-4-real-10" }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -9,6 +10,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -18,6 +20,6 @@ program test
!print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
!print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 10)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 8)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 10)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 8)) stop 2
end program test

View File

@ -3,6 +3,7 @@
! { dg-require-effective-target fortran_real_16 }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -10,6 +11,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -19,6 +21,6 @@ program test
!print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
!print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 16)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 10)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 16)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 10)) stop 2
end program test

View File

@ -3,6 +3,7 @@
! { dg-require-effective-target fortran_real_16 }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -10,6 +11,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -19,6 +21,6 @@ program test
!print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
!print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 16)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 16)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 16)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 16)) stop 2
end program test

View File

@ -3,6 +3,7 @@
! { dg-require-effective-target fortran_real_16 }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -10,6 +11,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -19,6 +21,6 @@ program test
!print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
!print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 16)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d5)] /= 4)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 16)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d5)] /= 4)) stop 2
end program test

View File

@ -3,6 +3,7 @@
! { dg-require-effective-target fortran_real_16 }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -10,6 +11,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -19,6 +21,6 @@ program test
!print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
!print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 16)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 8)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 16)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 8)) stop 2
end program test

View File

@ -2,6 +2,7 @@
! { dg-additional-options "-w -freal-4-real-8 -freal-8-real-10" }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -9,6 +10,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -18,6 +20,6 @@ program test
print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(r1), kind(r2), kind(r3), kind(r4)] /= 8)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 10)) stop 2
if (any ([kind(r1), kind(1.0_4), kind(1.0_k4), kind(r2), kind(r3), kind(r4)] /= 8)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 10)) stop 2
end program test

View File

@ -3,6 +3,7 @@
! { dg-require-effective-target fortran_real_16 }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -10,6 +11,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -19,6 +21,6 @@ program test
!print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
!print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 8)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 16)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 8)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 16)) stop 2
end program test

View File

@ -2,6 +2,7 @@
! { dg-additional-options "-w -freal-4-real-8 -freal-8-real-4" }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -9,6 +10,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -18,6 +20,6 @@ program test
print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 8)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d5)] /= 4)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 8)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d5)] /= 4)) stop 2
end program test

View File

@ -2,6 +2,7 @@
! { dg-additional-options "-w -freal-4-real-8" }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -9,6 +10,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -18,6 +20,6 @@ program test
!print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
!print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 8)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 8)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 8)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 8)) stop 2
end program test

View File

@ -2,6 +2,7 @@
! { dg-additional-options "-w -freal-8-real-10" }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -9,6 +10,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -18,6 +20,6 @@ program test
!print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
!print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 4)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 10)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 4)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 10)) stop 2
end program test

View File

@ -3,6 +3,7 @@
! { dg-require-effective-target fortran_real_16 }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -10,6 +11,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -19,6 +21,6 @@ program test
!print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
!print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 4)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 16)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 4)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 16)) stop 2
end program test

View File

@ -2,6 +2,7 @@
! { dg-additional-options "-w -freal-8-real-4" }
!
! PR fortran/99355
! PR fortran/99355 comment 10 to 13 + PR fortran/57871
!
program test
@ -9,6 +10,7 @@ program test
real*4:: r2
real(4) :: r3
real(selected_real_kind(p=6)) :: r4
integer, parameter :: k4 = 4, k8 = 8
double precision :: d1
real*8 :: d2
@ -18,6 +20,6 @@ program test
!print '(tr3,a10,10(tr1,i2))', 'single', kind(r1), kind(r2), kind(r3), kind(r4)
!print '(tr3,a10,10(tr1,i2))', 'double', kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)
if (any ([kind(1.0), kind(r1), kind(r2), kind(r3), kind(r4)] /= 4)) stop 1
if (any ([kind(1.d0), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 4)) stop 2
if (any ([kind(1.0), kind(1.0_4), kind(1.0_k4), kind(r1), kind(r2), kind(r3), kind(r4)] /= 4)) stop 1
if (any ([kind(1.d0), kind(1.0_8), kind(1.0_k8), kind(d1), kind(d2), kind(d3), kind(d4), kind(d5)] /= 4)) stop 2
end program test