From: Tobias Burnus Date: Thu, 4 Mar 2021 07:18:31 +0000 (+0100) Subject: Fortran: Fix -freal-{4,8}-real* handling [PR99355] X-Git-Tag: upstream/12.2.0~9453 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d259ab15761de2d938c24abfba9cdcd2fef91655;p=platform%2Fupstream%2Fgcc.git Fortran: Fix -freal-{4,8}-real* handling [PR99355] Avoid chain kind conversion for, e.g., -freal-4-real-8 -freal-8-real-10. Note that gfc_default_double_kind/gfc_default_double_kind already honors the -freal flags. gcc/fortran/ChangeLog: PR fortran/99355 * decl.c (gfc_match_old_kind_spec, gfc_match_kind_spec): Avoid redoing kind conversions. * primary.c (match_real_constant): Likewise. gcc/testsuite/ChangeLog: PR fortran/99355 * gfortran.dg/real4-10-real8-10.f90: New test. * gfortran.dg/real4-10-real8-16.f90: New test. * gfortran.dg/real4-10-real8-4.f90: New test. * gfortran.dg/real4-10.f90: New test. * gfortran.dg/real4-16-real8-10.f90: New test. * gfortran.dg/real4-16-real8-16.f90: New test. * gfortran.dg/real4-16-real8-4.f90: New test. * gfortran.dg/real4-16.f90: New test. * gfortran.dg/real4-8-real8-10.f90: New test. * gfortran.dg/real4-8-real8-16.f90: New test. * gfortran.dg/real4-8-real8-4.f90: New test. * gfortran.dg/real4-8.f90: New test. * gfortran.dg/real8-10.f90: New test. * gfortran.dg/real8-16.f90: New test. * gfortran.dg/real8-4.f90: New test. --- diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 7239158..947e4f8 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -3066,8 +3066,7 @@ gfc_match_old_kind_spec (gfc_typespec *ts) if (flag_real4_kind == 16) ts->kind = 16; } - - if (ts->kind == 8) + else if (ts->kind == 8) { if (flag_real8_kind == 4) ts->kind = 4; @@ -3246,8 +3245,7 @@ close_brackets: if (flag_real4_kind == 16) ts->kind = 16; } - - if (ts->kind == 8) + else if (ts->kind == 8) { if (flag_real8_kind == 4) ts->kind = 4; diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index 7633e77..9dd1a86 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -676,26 +676,6 @@ done: goto cleanup; } kind = gfc_default_double_kind; - - if (kind == 4) - { - if (flag_real4_kind == 8) - kind = 8; - if (flag_real4_kind == 10) - kind = 10; - if (flag_real4_kind == 16) - kind = 16; - } - - if (kind == 8) - { - if (flag_real8_kind == 4) - kind = 4; - if (flag_real8_kind == 10) - kind = 10; - if (flag_real8_kind == 16) - kind = 16; - } break; case 'q': @@ -726,26 +706,6 @@ done: if (kind == -2) kind = gfc_default_real_kind; - if (kind == 4) - { - if (flag_real4_kind == 8) - kind = 8; - if (flag_real4_kind == 10) - kind = 10; - if (flag_real4_kind == 16) - kind = 16; - } - - if (kind == 8) - { - if (flag_real8_kind == 4) - kind = 4; - if (flag_real8_kind == 10) - kind = 10; - if (flag_real8_kind == 16) - kind = 16; - } - if (gfc_validate_kind (BT_REAL, kind, true) < 0) { gfc_error ("Invalid real kind %d at %C", kind); diff --git a/gcc/testsuite/gfortran.dg/real4-10-real8-10.f90 b/gcc/testsuite/gfortran.dg/real4-10-real8-10.f90 new file mode 100644 index 0000000..af4f1b2 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real4-10-real8-10.f90 @@ -0,0 +1,23 @@ +! { dg-do run { target i?86-*-* x86_64-*-* } } +! { dg-additional-options "-w -freal-4-real-10 -freal-8-real-10" } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 + real(selected_real_kind(p=15)) :: d5 + + !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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real4-10-real8-16.f90 b/gcc/testsuite/gfortran.dg/real4-10-real8-16.f90 new file mode 100644 index 0000000..408d347 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real4-10-real8-16.f90 @@ -0,0 +1,24 @@ +! { dg-do run { target i?86-*-* x86_64-*-* } } +! { dg-additional-options "-w -freal-4-real-10 -freal-8-real-16" } +! { dg-require-effective-target fortran_real_16 } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 + real(selected_real_kind(p=15)) :: d5 + + !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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real4-10-real8-4.f90 b/gcc/testsuite/gfortran.dg/real4-10-real8-4.f90 new file mode 100644 index 0000000..7e52cdb --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real4-10-real8-4.f90 @@ -0,0 +1,23 @@ +! { dg-do run { target i?86-*-* x86_64-*-* } } +! { dg-additional-options "-w -freal-4-real-10 -freal-8-real-4" } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 ! << this is ambiguous: kind=8 → 4 → 10 or 8 → 4; thus,excluded below + real(selected_real_kind(p=15)) :: d5 + + !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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real4-10.f90 b/gcc/testsuite/gfortran.dg/real4-10.f90 new file mode 100644 index 0000000..44fcd83 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real4-10.f90 @@ -0,0 +1,23 @@ +! { dg-do run { target i?86-*-* x86_64-*-* } } +! { dg-additional-options "-w -freal-4-real-10" } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 + real(selected_real_kind(p=15)) :: d5 + + !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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real4-16-real8-10.f90 b/gcc/testsuite/gfortran.dg/real4-16-real8-10.f90 new file mode 100644 index 0000000..d080a10 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real4-16-real8-10.f90 @@ -0,0 +1,24 @@ +! { dg-do run { target i?86-*-* x86_64-*-* } } +! { dg-additional-options "-w -freal-4-real-16 -freal-8-real-10" } +! { dg-require-effective-target fortran_real_16 } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 + real(selected_real_kind(p=15)) :: d5 + + !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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real4-16-real8-16.f90 b/gcc/testsuite/gfortran.dg/real4-16-real8-16.f90 new file mode 100644 index 0000000..d525c60 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real4-16-real8-16.f90 @@ -0,0 +1,24 @@ +! { dg-do run } +! { dg-additional-options "-w -freal-4-real-16 -freal-8-real-16" } +! { dg-require-effective-target fortran_real_16 } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 + real(selected_real_kind(p=15)) :: d5 + + !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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real4-16-real8-4.f90 b/gcc/testsuite/gfortran.dg/real4-16-real8-4.f90 new file mode 100644 index 0000000..e508819 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real4-16-real8-4.f90 @@ -0,0 +1,24 @@ +! { dg-do run } +! { dg-additional-options "-w -freal-4-real-16 -freal-8-real-4" } +! { dg-require-effective-target fortran_real_16 } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 ! << this is ambiguous: kind=8 → 4 → 16 or 8 → 4; thus,excluded below + real(selected_real_kind(p=15)) :: d5 + + !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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real4-16.f90 b/gcc/testsuite/gfortran.dg/real4-16.f90 new file mode 100644 index 0000000..5cd2f1f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real4-16.f90 @@ -0,0 +1,24 @@ +! { dg-do run } +! { dg-additional-options "-w -freal-4-real-16" } +! { dg-require-effective-target fortran_real_16 } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 + real(selected_real_kind(p=15)) :: d5 + + !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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real4-8-real8-10.f90 b/gcc/testsuite/gfortran.dg/real4-8-real8-10.f90 new file mode 100644 index 0000000..742d352 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real4-8-real8-10.f90 @@ -0,0 +1,23 @@ +! { dg-do run { target i?86-*-* x86_64-*-* } } +! { dg-additional-options "-w -freal-4-real-8 -freal-8-real-10" } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 + real(selected_real_kind(p=15)) :: d5 + + 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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real4-8-real8-16.f90 b/gcc/testsuite/gfortran.dg/real4-8-real8-16.f90 new file mode 100644 index 0000000..3733c34 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real4-8-real8-16.f90 @@ -0,0 +1,24 @@ +! { dg-do run } +! { dg-additional-options "-w -freal-4-real-8 -freal-8-real-16" } +! { dg-require-effective-target fortran_real_16 } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 + real(selected_real_kind(p=15)) :: d5 + + !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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real4-8-real8-4.f90 b/gcc/testsuite/gfortran.dg/real4-8-real8-4.f90 new file mode 100644 index 0000000..b83b243 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real4-8-real8-4.f90 @@ -0,0 +1,23 @@ +! { dg-do run } +! { dg-additional-options "-w -freal-4-real-8 -freal-8-real-4" } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 ! << this is ambiguous: kind=8 → 4 → 8 or 8 → 4; thus,excluded below + real(selected_real_kind(p=15)) :: d5 + + 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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real4-8.f90 b/gcc/testsuite/gfortran.dg/real4-8.f90 new file mode 100644 index 0000000..50577dd --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real4-8.f90 @@ -0,0 +1,23 @@ +! { dg-do run } +! { dg-additional-options "-w -freal-4-real-8" } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 + real(selected_real_kind(p=15)) :: d5 + + !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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real8-10.f90 b/gcc/testsuite/gfortran.dg/real8-10.f90 new file mode 100644 index 0000000..68f6bc4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real8-10.f90 @@ -0,0 +1,23 @@ +! { dg-do run { target i?86-*-* x86_64-*-* } } +! { dg-additional-options "-w -freal-8-real-10" } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 + real(selected_real_kind(p=15)) :: d5 + + !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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real8-16.f90 b/gcc/testsuite/gfortran.dg/real8-16.f90 new file mode 100644 index 0000000..5ddd9e1 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real8-16.f90 @@ -0,0 +1,24 @@ +! { dg-do run } +! { dg-additional-options "-w -freal-8-real-16" } +! { dg-require-effective-target fortran_real_16 } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 + real(selected_real_kind(p=15)) :: d5 + + !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 +end program test diff --git a/gcc/testsuite/gfortran.dg/real8-4.f90 b/gcc/testsuite/gfortran.dg/real8-4.f90 new file mode 100644 index 0000000..a68559a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/real8-4.f90 @@ -0,0 +1,23 @@ +! { dg-do run } +! { dg-additional-options "-w -freal-8-real-4" } +! +! PR fortran/99355 +! + +program test + real :: r1 + real*4:: r2 + real(4) :: r3 + real(selected_real_kind(p=6)) :: r4 + + double precision :: d1 + real*8 :: d2 + real(8) :: d3 + real(kind(1.d0)) :: d4 + real(selected_real_kind(p=15)) :: d5 + + !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 +end program test