OSDN Git Service

PR fortran/38718
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 9 Nov 2011 09:41:17 +0000 (09:41 +0000)
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 9 Nov 2011 09:41:17 +0000 (09:41 +0000)
* intrinsic.c (add_functions): Add gfc_simplify_dreal.
* intrinsic.h (gfc_simplify_dreal): New proto.
* simplify.c (gfc_simplify_dreal): New function.

* gfortran.dg/initialization_29.f90: Expand test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181198 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/intrinsic.c
gcc/fortran/intrinsic.h
gcc/fortran/simplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/initialization_29.f90 [new file with mode: 0644]

index 96944e2..1fffbc6 100644 (file)
@@ -1,3 +1,10 @@
+2011-11-08  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+       PR fortran/38718
+       * intrinsic.c (add_functions): Allow dreal simplification.
+       * intrinsic.h (gfc_simplify_dreal): New prototype.
+       * simplify.c (gfc_simplify_dreal): New function.
+
 2011-11-09  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        PR fortran/21881
index 8f437cc..38bcb27 100644 (file)
@@ -1557,8 +1557,8 @@ add_functions (void)
 
   make_generic ("dprod", GFC_ISYM_DPROD, GFC_STD_F77);
 
-  add_sym_1 ("dreal", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dd, GFC_STD_GNU,
-            NULL, NULL, NULL,
+  add_sym_1 ("dreal", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO,
+            BT_REAL, dd, GFC_STD_GNU, NULL, gfc_simplify_dreal, NULL,
             a, BT_COMPLEX, dd, REQUIRED);
 
   make_generic ("dreal", GFC_ISYM_REAL, GFC_STD_GNU);
index e64325b..bfc2455 100644 (file)
@@ -262,6 +262,7 @@ gfc_expr *gfc_simplify_digits (gfc_expr *);
 gfc_expr *gfc_simplify_dim (gfc_expr *, gfc_expr *);
 gfc_expr *gfc_simplify_dprod (gfc_expr *, gfc_expr *);
 gfc_expr *gfc_simplify_dot_product (gfc_expr *, gfc_expr *);
+gfc_expr *gfc_simplify_dreal (gfc_expr *);
 gfc_expr *gfc_simplify_dshiftl (gfc_expr *, gfc_expr *, gfc_expr *);
 gfc_expr *gfc_simplify_dshiftr (gfc_expr *, gfc_expr *, gfc_expr *);
 gfc_expr *gfc_simplify_epsilon (gfc_expr *);
index 01071cf..4431826 100644 (file)
@@ -939,6 +939,21 @@ gfc_simplify_dint (gfc_expr *e)
 
 
 gfc_expr *
+gfc_simplify_dreal (gfc_expr *e)
+{
+  gfc_expr *result = NULL;
+
+  if (e->expr_type != EXPR_CONSTANT)
+    return NULL;
+
+  result = gfc_get_constant_expr (BT_REAL, e->ts.kind, &e->where);
+  mpc_real (result->value.real, e->value.complex, GFC_RND_MODE);
+
+  return range_check (result, "DREAL");
+}
+
+
+gfc_expr *
 gfc_simplify_anint (gfc_expr *e, gfc_expr *k)
 {
   gfc_expr *result;
index 7b59aeb..e6e9049 100644 (file)
@@ -1,3 +1,8 @@
+2011-11-09  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+       PR fortran/38718
+       * gfortran.dg/initialization_29.f90: Expand test.
+
 2011-11-09  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/51027
diff --git a/gcc/testsuite/gfortran.dg/initialization_29.f90 b/gcc/testsuite/gfortran.dg/initialization_29.f90
new file mode 100644 (file)
index 0000000..e3f2992
--- /dev/null
@@ -0,0 +1,15 @@
+! { dg-do compile }
+!
+! PR fortran/38718
+!
+  implicit none
+  real(kind=8), parameter :: r = kind(0) + 0.2
+  complex(kind=8), parameter :: c = (r, -9.3)
+  integer, parameter :: k = nint(dreal(c))
+  integer, parameter :: l = nint(realpart(c))
+  integer(kind=k) :: i
+  integer(kind=l) :: j
+  i = 42
+  j = 42
+  print *, k, i, j, r
+  end