re PR libfortran/33055 (Runtime error in INQUIRE unit existance with -fdefault-integer-8)
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Mon, 15 Oct 2007 13:55:47 +0000 (13:55 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Mon, 15 Oct 2007 13:55:47 +0000 (13:55 +0000)
2007-10-15  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR fortran/33055
* trans-io.c (create_dummy_iostat): New function to create a unique
dummy variable expression to use with IOSTAT.
(gfc_trans_inquire): Use the new function to pass unit number error info
to run-time library if a regular IOSTAT variable was not given.

From-SVN: r129328

gcc/fortran/ChangeLog
gcc/fortran/trans-io.c

index 717053a..7ee3b07 100644 (file)
@@ -1,3 +1,11 @@
+2007-10-15  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR fortran/33055
+       * trans-io.c (create_dummy_iostat): New function to create a unique
+       dummy variable expression to use with IOSTAT.
+       (gfc_trans_inquire): Use the new function to pass unit number error info
+       to run-time library if a regular IOSTAT variable was not given.
+
 2007-10-14  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/33745
index 72875f1..6c43849 100644 (file)
@@ -1083,6 +1083,32 @@ gfc_trans_flush (gfc_code * code)
 }
 
 
+/* Create a dummy iostat variable to catch any error due to bad unit.  */
+
+static gfc_expr *
+create_dummy_iostat (void)
+{
+  gfc_symtree *st;
+  gfc_expr *e;
+
+  gfc_get_ha_sym_tree ("@iostat", &st);
+  st->n.sym->ts.type = BT_INTEGER;
+  st->n.sym->ts.kind = gfc_default_integer_kind;
+  gfc_set_sym_referenced (st->n.sym);
+  st->n.sym->backend_decl
+       = gfc_create_var (gfc_get_int_type (st->n.sym->ts.kind),
+                         st->n.sym->name);
+
+  e = gfc_get_expr ();
+  e->expr_type = EXPR_VARIABLE;
+  e->symtree = st;
+  e->ts.type = BT_INTEGER;
+  e->ts.kind = st->n.sym->ts.kind;
+
+  return e;
+}
+
+
 /* Translate the non-IOLENGTH form of an INQUIRE statement.  */
 
 tree
@@ -1122,8 +1148,17 @@ gfc_trans_inquire (gfc_code * code)
                        p->file);
 
   if (p->exist)
-    mask |= set_parameter_ref (&block, &post_block, var, IOPARM_inquire_exist,
-                              p->exist);
+    {
+      mask |= set_parameter_ref (&block, &post_block, var, IOPARM_inquire_exist,
+                                p->exist);
+    
+      if (p->unit && !p->iostat)
+       {
+         p->iostat = create_dummy_iostat ();
+         mask |= set_parameter_ref (&block, &post_block, var,
+                                    IOPARM_common_iostat, p->iostat);
+       }
+    }
 
   if (p->opened)
     mask |= set_parameter_ref (&block, &post_block, var, IOPARM_inquire_opened,