]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/35983 (C_LOC in derived type constructor gives weird result)
authorMikael Morin <mikael.morin@tele2.fr>
Tue, 9 Dec 2008 19:12:27 +0000 (20:12 +0100)
committerMikael Morin <mikael@gcc.gnu.org>
Tue, 9 Dec 2008 19:12:27 +0000 (19:12 +0000)
2008-12-09  Mikael Morin  <mikael.morin@tele2.fr>

PR fortran/35983
* trans-expr.c (gfc_trans_subcomponent_assign):
Add se's pre and post blocks to current block.
(gfc_trans_structure_assign): Remove specific handling
of C_NULL_PTR and C_NULL_FUNPTR.

2008-12-09  Mikael Morin  <mikael.morin@tele2.fr>

PR fortran/35983
* gfortran.dg/pr35983.f90: New test.

From-SVN: r142605

gcc/fortran/ChangeLog
gcc/fortran/trans-expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr35983.f90 [new file with mode: 0644]

index 7f53a8ee1d01dda9e4d8efb55dec875d4f54089f..a46e79adeb1fc79cb956208297e6a7c05d8530c9 100644 (file)
@@ -1,3 +1,11 @@
+2008-12-09  Mikael Morin  <mikael.morin@tele2.fr>
+
+       PR fortran/35983
+       * trans-expr.c (gfc_trans_subcomponent_assign):
+       Add se's pre and post blocks to current block.
+       (gfc_trans_structure_assign): Remove specific handling
+       of C_NULL_PTR and C_NULL_FUNPTR.
+
 2008-12-06  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR fortran/38425
index 5d3894c825d748904ebeef6780d48f6b59b71766..4ecfa0839d0da9b2301d0c4bd6b36b9892fcf72e 100644 (file)
@@ -3670,8 +3670,10 @@ gfc_trans_subcomponent_assign (tree dest, gfc_component * cm, gfc_expr * expr)
        {
          gfc_init_se (&se, NULL);
          gfc_conv_expr (&se, expr);
+         gfc_add_block_to_block (&block, &se.pre);
          gfc_add_modify (&block, dest,
                               fold_convert (TREE_TYPE (dest), se.expr));
+         gfc_add_block_to_block (&block, &se.post);
        }
       else
        {
@@ -3713,21 +3715,8 @@ gfc_trans_structure_assign (tree dest, gfc_expr * expr)
     {
       /* Skip absent members in default initializers.  */
       if (!c->expr)
-        continue;
+       continue;
 
-      /* Update the type/kind of the expression if it represents either
-        C_NULL_PTR or C_NULL_FUNPTR.  This is done here because this may
-        be the first place reached for initializing output variables that
-        have components of type C_PTR/C_FUNPTR that are initialized.  */
-      if (c->expr->ts.type == BT_DERIVED && c->expr->ts.derived
-         && c->expr->ts.derived->attr.is_iso_c)
-        {
-         c->expr->expr_type = EXPR_NULL;
-         c->expr->ts.type = c->expr->ts.derived->ts.type;
-         c->expr->ts.f90_type = c->expr->ts.derived->ts.f90_type;
-         c->expr->ts.kind = c->expr->ts.derived->ts.kind;
-       }
-      
       field = cm->backend_decl;
       tmp = fold_build3 (COMPONENT_REF, TREE_TYPE (field),
                         dest, field, NULL_TREE);
index 94caabad5948ab6e0f4c9f79ab2c9151afd4aa27..bcee032920385c92235fc3f17cd28b01621160c4 100644 (file)
@@ -1,3 +1,8 @@
+2008-12-09  Mikael Morin  <mikael.morin@tele2.fr>
+
+       PR fortran/35983
+       * gfortran.dg/pr35983.f90: New test.
+
 2008-12-09  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR testsuite/38420
diff --git a/gcc/testsuite/gfortran.dg/pr35983.f90 b/gcc/testsuite/gfortran.dg/pr35983.f90
new file mode 100644 (file)
index 0000000..5cc3855
--- /dev/null
@@ -0,0 +1,24 @@
+! { dg-do run }
+!
+! PR fortran/35983
+! C_LOC expanded to a NULL_PTR expr if called from a structure constructor
+!
+! Contributed by François-Xavier Coudert
+
+program main
+   use ISO_C_BINDING
+   implicit none
+   type, bind(C) :: descr
+      type(C_PTR) :: address
+   end type descr
+   type(descr) :: DD
+   double precision, target :: buf(1)
+   integer (C_INTPTR_T) :: i, j
+
+   buf = (/ 0 /)
+   DD = descr(c_loc(buf))
+   i = transfer (DD%address, 0_c_intptr_t)
+   j = transfer (c_loc(buf), 0_c_intptr_t)
+   if (any((/ i,j /) == 0_c_intptr_t)) call abort
+   if (i /= j) call abort
+end program main