Bug 45066 - [4.6 Regression] ICE in namelist read in snapshot of 7/24/2010
Summary: [4.6 Regression] ICE in namelist read in snapshot of 7/24/2010
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Tobias Burnus
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2010-07-25 11:05 UTC by Michael Richmond
Modified: 2010-07-26 10:32 UTC (History)
2 users (show)

See Also:
Host: all
Target: all
Build: all
Known to work:
Known to fail:
Last reconfirmed: 2010-07-26 09:42:10


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Richmond 2010-07-25 11:05:39 UTC
When I compile the following file with the snapshot of July 24, 2010:

MODULE GA_commons
INTEGER :: nichflg(2)
END MODULE GA_commons
PROGRAM gafortran
USE GA_commons
NAMELIST /ga/ nichflg
READ (23, nml=ga)
END PROGRAM gafortran

I get the following message:

g.f90: In function gafortran:
g.f90:7:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Jerry DeLisle 2010-07-25 14:26:17 UTC
Confirmed. Works with -fno-whole-file.
Comment 2 Jerry DeLisle 2010-07-25 15:04:21 UTC
This patchlet at least works for the reduce test case. Assuming there is nothing left to translate.  I am not sure this is the right approach, bu the -fdump-tree-original matches for with and without -fno-whole-file. 

Index: trans-io.c
===================================================================
--- trans-io.c	(revision 162507)
+++ trans-io.c	(working copy)
@@ -1499,6 +1499,9 @@
 
   gcc_assert (sym || c);
 
+  if (base_addr == NULL)
+    return;
+
   /* Build the namelist object name.  */
 
   string = gfc_build_cstring_const (var_name);
Comment 3 Michael Richmond 2010-07-25 16:12:28 UTC
The patchlet also works for the full-size problem (Ga170.f90 from Alan Miller's ga.zip)
Comment 4 Jerry DeLisle 2010-07-25 16:21:46 UTC
Naturally the patch in #2 breaks everything else for namelists at run time unless I messed up something else here.
Comment 5 Michael Richmond 2010-07-25 16:25:40 UTC
At runtime it produces the message:

At line 1200 of file ga170.f90 (unit = 23, file = 'ga.inp')
Fortran runtime error: Missing format for FORMATTED data transfer
Comment 6 Jerry DeLisle 2010-07-25 17:37:26 UTC
Here is another possibility.  Only one namelist regression with this on.

Index: trans-io.c
===================================================================
--- trans-io.c	(revision 162507)
+++ trans-io.c	(working copy)
@@ -1759,8 +1759,11 @@ build_dt (tree function, gfc_code * code)
 	  dt_parm = var;
 
 	  for (nml = dt->namelist->namelist; nml; nml = nml->next)
-	    transfer_namelist_element (&block, nml->sym->name, nml->sym,
-				       NULL, NULL);
+	    {
+	      if (nml->sym->backend_decl)
+		transfer_namelist_element (&block, nml->sym->name, nml->sym,
+					   NULL, NULL);
+	    }
 	}
       else
 	set_parameter_const (&block, var, IOPARM_common_flags, mask);
Comment 7 Michael Richmond 2010-07-25 18:01:20 UTC
It compiles but doesn't run, as with your Comment #2 patch
Comment 8 Tobias Burnus 2010-07-26 09:42:10 UTC
(In reply to comment #2)
> --- trans-io.c  (revision 162507)
> +++ trans-io.c  (working copy)
> +  if (base_addr == NULL)
> +    return;
> +

This does not make sense if you call transfer_namelist_element in build_dt with the arguments:
            transfer_namelist_element (&block, nml->sym->name, nml->sym,
                                       NULL, NULL);
The last argument is "tree base_addr". (By the way, I think that should be NULL_TREE and not NULL.)

Besides, the issue seems to be rather:
      dt =  TREE_TYPE ((sym) ? sym->backend_decl : c->backend_decl);
      dtype = gfc_get_dtype (dt);
which makes more sense in terms of fwhole-file; the problem is that sym->backend_decl = NULL.

It seems as if the following patch fixes this. With -fno-whole-file the sym->backend_decl is set and one returns the decl. With -fwhole-file only the decl was returned.

I wonder how many other issues this patch fixes.

Note: I tested it for the example in comment 0, but I have not yet tested it against gfortran's test suite.


Index: trans-io.c
===================================================================
--- trans-io.c  (revision 162526)
+++ trans-io.c  (working copy)
@@ -1760,7 +1760,7 @@ build_dt (tree function, gfc_code * code

          for (nml = dt->namelist->namelist; nml; nml = nml->next)
            transfer_namelist_element (&block, nml->sym->name, nml->sym,
-                                      NULL, NULL);
+                                      NULL, NULL_TREE);
        }
       else
        set_parameter_const (&block, var, IOPARM_common_flags, mask);
Index: trans-decl.c
===================================================================
--- trans-decl.c        (revision 162526)
+++ trans-decl.c        (working copy)
@@ -1150,7 +1150,8 @@ gfc_get_symbol_decl (gfc_symbol * sym)
                                           true);
              if (sym->ts.type == BT_CHARACTER)
                sym->ts.u.cl->backend_decl = s->ts.u.cl->backend_decl;
-             return s->backend_decl;
+             sym->backend_decl = s->backend_decl;
+             return sym->backend_decl;
            }
        }
     }
Comment 9 Tobias Burnus 2010-07-26 10:31:09 UTC
Subject: Bug 45066

Author: burnus
Date: Mon Jul 26 10:30:45 2010
New Revision: 162532

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162532
Log:
2010-07-26  Tobias Burnus  <burnus@net-b.de>

        PR fortran/45066
        * trans-io.c (build_dt): Use NULL_TREE rather than NULL
        for call to transfer_namelist_element.
        * trans-decl.c (gfc_get_symbol_decl): Also set sym->backend_decl
        for -fwhole-file.

2010-07-26  Tobias Burnus  <burnus@net-b.de>

        PR fortran/45066
        * gfortran.dg/namelist_62.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/namelist_62.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans-io.c
    trunk/gcc/testsuite/ChangeLog

Comment 10 Tobias Burnus 2010-07-26 10:32:31 UTC
(In reply to comment #8)
> I wonder how many other issues this patch fixes.

Seemingly none of those -fwhole-file/-fwhole-program issues which I wanted to see fixed :-(

Well, at least this PR is now FIXED. Thanks for the bug report!

(As with all -fwhole-file patches: I think I won't backport them to 4.5. Howvever, if someone wants to do it, feel free to do so.)