https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99355

--- Comment #11 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to Dominique d'Humieres from comment #8)
> r11-7501 changed the output of the test in comment O, is this expected?

(In reply to Dominique d'Humieres from comment #10)
> % gfc pr57871.f90

I am slightly confused. Do you mean the output for this PR's comment 0 has
changed – or the result for the testcase in PR 57871 comment 0?

> % ./a.out
>  kind(1.0_p1)           4 precision(1.0_p1)           6
>  kind(1.0_dp)           8 precision(1.0_dp)          15

Using PR 57871 comment 0, I get exactly the same output as you have with both
gfortran and ifort.

 * * *

> So without option kind(1.0_p1) is 4, should not it be converted to 16 with
> -freal-4-real-16?

Currently, the code handles:
  1.0  = default-kind real
  1.0d0 = default-double-precision-kind real
→ promote

And
  real :: A  → default-kind real
  double precision :: B → default-double-precision real
  real*<kind>      :: C → convert <kind>
  real(kind=<kind> :: D → convert <kind>

The question is what to do about:
  1.0_<kind>

  * * *

However, we cannot completely avoid ambiguity as for
-freal-4-real-8 freal-8-real-16

  integer, parameter :: k1 = kind(1.0) → 8
  real(kind=k1) :: var → kind(8) → 16
  real(kind=4)  :: var → kind(4) → 8

But some issues are unavoidable and all -freal-*-real-* flags should be
avoided, if possible.

 * * *

Seems as if we need to handle in match_real_constant the case default-real-kind
separately from _kind value specified.

Untested:

--- a/gcc/fortran/primary.c
+++ b/gcc/fortran/primary.c
@@ -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':

Reply via email to