re PR fortran/36214 (Wrong simplification of BOZ constants)
authorDaniel Kraft <d@domob.eu>
Thu, 11 Sep 2008 07:28:18 +0000 (09:28 +0200)
committerDaniel Kraft <domob@gcc.gnu.org>
Thu, 11 Sep 2008 07:28:18 +0000 (09:28 +0200)
2008-09-11  Daniel Kraft  <d@domob.eu>

PR fortran/36214
* simplify.c (simplify_cmplx): Added linebreak to long line.
* target-memory.c (gfc_convert_boz): Fix indentation.
(gfc_interpret_float): Set mpfr precision to right value before
calling mpfr_init.

2008-09-11  Daniel Kraft  <d@domob.eu>

PR fortran/36214
* gfortran.dg/boz_9.f90: Corrected test.
* gfortran.dg/boz_13.f90: New test.
* gfortran.dg/boz_14.f90: New test.

From-SVN: r140264

gcc/fortran/ChangeLog
gcc/fortran/simplify.c
gcc/fortran/target-memory.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/boz_13.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/boz_14.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/boz_9.f90

index d7361e0..954d5cd 100644 (file)
@@ -1,3 +1,11 @@
+2008-09-11  Daniel Kraft  <d@domob.eu>
+
+       PR fortran/36214
+       * simplify.c (simplify_cmplx): Added linebreak to long line.
+       * target-memory.c (gfc_convert_boz): Fix indentation.
+       (gfc_interpret_float): Set mpfr precision to right value before
+       calling mpfr_init.
+
 2008-09-10  H.J. Lu  <hongjiu.lu@intel.com>
 
        * expr.c (find_array_element): Reformat comment.
index 64d2be1..c0ac026 100644 (file)
@@ -884,7 +884,8 @@ simplify_cmplx (const char *name, gfc_expr *x, gfc_expr *y, int kind)
        {
        case BT_INTEGER:
          if (!y->is_boz)
-           mpfr_set_z (result->value.complex.i, y->value.integer, GFC_RND_MODE);
+           mpfr_set_z (result->value.complex.i, y->value.integer,
+                       GFC_RND_MODE);
          break;
 
        case BT_REAL:
index b1029df..72bd6ef 100644 (file)
@@ -349,8 +349,9 @@ gfc_interpret_integer (int kind, unsigned char *buffer, size_t buffer_size,
 
 int
 gfc_interpret_float (int kind, unsigned char *buffer, size_t buffer_size,
-                mpfr_t real)
+                    mpfr_t real)
 {
+  gfc_set_model_kind (kind);
   mpfr_init (real);
   gfc_conv_tree_to_mpfr (real,
                         native_interpret_expr (gfc_get_real_type (kind),
@@ -699,10 +700,8 @@ gfc_convert_boz (gfc_expr *expr, gfc_typespec *ts)
     }
 
   for (index = 0; gfc_integer_kinds[index].kind != 0; ++index)
-    {
-       if ((unsigned) gfc_integer_kinds[index].bit_size >= ts_bit_size)
-         break;
-    }
+    if ((unsigned) gfc_integer_kinds[index].bit_size >= ts_bit_size)
+      break;
 
   expr->ts.kind = gfc_integer_kinds[index].kind;
   buffer_size = MAX (buffer_size, size_integer (expr->ts.kind));
index 88463e9..b42b5df 100644 (file)
@@ -1,3 +1,10 @@
+2008-09-11  Daniel Kraft  <d@domob.eu>
+
+       PR fortran/36214
+       * gfortran.dg/boz_9.f90: Corrected test.
+       * gfortran.dg/boz_13.f90: New test.
+       * gfortran.dg/boz_14.f90: New test.
+
 2008-09-10  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/36904
diff --git a/gcc/testsuite/gfortran.dg/boz_13.f90 b/gcc/testsuite/gfortran.dg/boz_13.f90
new file mode 100644 (file)
index 0000000..a522f82
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do run }
+
+! PR fortran/36214
+! For BOZ-initialization of floats, the precision used to be wrong sometimes.
+
+implicit none
+   real, parameter :: r = 0.0
+   real(kind=8), parameter :: rd = real (z'00000000&
+                                          &402953FD', 8)
+
+   if (real (z'00000000&
+              &402953FD', 8) /= rd) call abort
+end
diff --git a/gcc/testsuite/gfortran.dg/boz_14.f90 b/gcc/testsuite/gfortran.dg/boz_14.f90
new file mode 100644 (file)
index 0000000..a6690ce
--- /dev/null
@@ -0,0 +1,18 @@
+! { dg-do run }
+
+! PR fortran/36214
+! For BOZ-initialization of floats, the precision used to be wrong sometimes.
+
+   implicit none
+   real(4) r
+   real(8) rd
+   complex(8) z
+   rd = &
+    real (b'00000000000000000000000000000000&
+           &01000000001010010101001111111101',8)
+   z  = &
+    cmplx(b'00000000000000000000000000000000&
+           &01000000001010010101001111111101',0,8)
+   r = 0.
+   if (z /= rd) call abort
+   end
index e1b0592..1488c6d 100644 (file)
@@ -22,13 +22,13 @@ complex          :: z2 = cmplx(5.0, o'01245')
 
 if (r2c /= 13107.0) call abort()
 if (rc  /= 1.83668190E-41) call abort()
-if (dc /= 0.30102999566398120) call abort()
+if (dc /= 0.30102999566398120d0) call abort()
 if (real(z1c) /= 2.94272678E-44 .or. aimag(z1c) /= -4.0) call abort()
 if (real(z2c) /= 5.0 .or. aimag(z2c) /= 9.48679060E-43) call abort()
 
 if (r2 /= 13107.0) call abort()
 if (r  /= 1.83668190E-41) call abort()
-if (d /= 0.30102999566398120) call abort()
+if (d /= 0.30102999566398120d0) call abort()
 if (real(z1) /= 2.94272678E-44 .or. aimag(z1) /= -4.0) call abort()
 if (real(z2) /= 5.0 .or. aimag(z2) /= 9.48679060E-43) call abort()
 
@@ -40,7 +40,7 @@ z2 = cmplx(5.0, o'01245')
 
 if (r2 /= 13107.0) call abort()
 if (r  /= 1.83668190E-41) call abort()
-if (d /= 0.30102999566398120) call abort()
+if (d /= 0.30102999566398120d0) call abort()
 if (real(z1) /= 2.94272678E-44 .or. aimag(z1) /= -4.0) call abort()
 if (real(z2) /= 5.0 .or. aimag(z2) /= 9.48679060E-43) call abort()