[gfortran,patch] PR 25716: Implicit kind conversions in in expressions written to *.mod-files
Erik Edelmann
erik.edelmann@iki.fi
Tue Jan 24 23:20:00 GMT 2006
:ADDPATCH fortran:
On Mon, Jan 23, 2006 at 10:01:34PM +0200, Erik Edelmann wrote:
> On Sun, Jan 15, 2006 at 10:24:48PM +0200, Erik Edelmann wrote:
> > 2) The expression node didn't get a symtree, which caused
> > problems in module.c (mio_expr) for function nodes when we call
> > mio_symtree_ref(). To fix this I inserted code to add a symtree
> > in intrinsic.c (gfc_convert_type_warn). To make this work I had
> > to fix two other things as well:
> >
> > a) Remove a symbol from the 'changed_syms' list when we
> > free it in symbol.c (gfc_free_symbol)
>
> When looking at it again, I realize that this is wrong (or at
> least not needed). The _real_ problem is that sym->refs of the
> newly created symbol is too low.
Or not. Right now :-) I belive that the _really_ real problem is
that the symbol we create is added to changed_syms to begin with.
The attached patch differ from my original patch on two points:
1) The new symbol we create in intrinsic.c
(gfc_convert_type_warn) (when creating the symtree) is committed
(i.e. removed from changed_syms) shortly after its creation,
rather than waiting until it's freed. This is done using the new
function gfc_symbol_commit() (like gfc_commit_symbols(), but it
commits only one symbol).
2) I found one place (symbol.c (gfc_use_derived)) where a symbol
was removed from changed_syms by 'inline' code. To reduce the
duplicated code, I replaced the inline code by a call to the new
function gfc_commit_symbol.
Tested on Linux/x86, on mainline and 4.1. Ok to commit?
Erik
2005-01-25 Erik Edelmann <eedelman@gcc.gnu.org>
PR fortran/25716
* symbol.c (gfc_commit_symbol): New function.
(gfc_use_derived): Use it.
* gfortran.h: Add prototype for it.
* intrinsic.c (gfc_find_function): Search in 'conversion'
if not found in 'functions'.
(gfc_convert_type_warn): Add a symtree to the new
expression node, and commit the new symtree->n.sym.
* resolve.c (gfc_resolve_index): Make sure typespec is
properly initialized.
2005-01-25 Erik Edelmann <eedelman@gcc.gnu.org>
PR fortran/25716
* gfortran.dg/char_result_11.f90: Make it sensitive to PR
25716 on 32-bit systems too.
-------------- next part --------------
Index: gcc/testsuite/gfortran.dg/char_result_11.f90
===================================================================
--- gcc/testsuite/gfortran.dg/char_result_11.f90 (revision 110142)
+++ gcc/testsuite/gfortran.dg/char_result_11.f90 (working copy)
@@ -1,5 +1,6 @@
-! { dg-do compile }
-! PR 23675: Character function of module variable length
+! { dg-do link }
+! PR 23675: Character function of module-variable length
+! PR 25716: Implicit kind conversions in in expressions written to *.mod-files.
module cutils
implicit none
@@ -11,7 +12,8 @@ module cutils
end type t
integer :: m1 = 25, m2 = 25, m3 = 25, m4 = 25, m5 = 25
- integer :: n1 = 3, n2 = 3, n3 = 3, n4 = 3, n5 = 3, n6 = 3, n7 = 3, n8 = 3, n9 = 3
+ integer :: n5 = 3, n7 = 3, n9 = 3
+ integer(1) :: n1 = 3, n2 = 3, n3 = 3, n4 = 3, n6 = 3, n8 = 3
character(10) :: s = "abcdefghij"
integer :: x(4) = (/ 30, 40, 50, 60 /)
type(t) :: tt1(5), tt2(5)
Index: gcc/fortran/intrinsic.c
===================================================================
--- gcc/fortran/intrinsic.c (revision 110142)
+++ gcc/fortran/intrinsic.c (working copy)
@@ -711,8 +711,13 @@ find_sym (gfc_intrinsic_sym * start, int
gfc_intrinsic_sym *
gfc_find_function (const char *name)
{
+ gfc_intrinsic_sym *sym;
+
+ sym = find_sym (functions, nfunc, name);
+ if (!sym)
+ sym = find_sym (conversion, nconv, name);
- return find_sym (functions, nfunc, name);
+ return sym;
}
@@ -3415,6 +3420,16 @@ gfc_convert_type_warn (gfc_expr * expr,
new->rank = rank;
new->shape = gfc_copy_shape (shape, rank);
+ gfc_get_ha_sym_tree (sym->name, &new->symtree);
+ new->symtree->n.sym->ts = *ts;
+ new->symtree->n.sym->attr.flavor = FL_PROCEDURE;
+ new->symtree->n.sym->attr.function = 1;
+ new->symtree->n.sym->attr.intrinsic = 1;
+ new->symtree->n.sym->attr.elemental = 1;
+ new->symtree->n.sym->attr.pure = 1;
+ new->symtree->n.sym->attr.referenced = 1;
+ gfc_commit_symbol (new->symtree->n.sym);
+
*expr = *new;
gfc_free (new);
Index: gcc/fortran/symbol.c
===================================================================
--- gcc/fortran/symbol.c (revision 110142)
+++ gcc/fortran/symbol.c (working copy)
@@ -1345,7 +1345,7 @@ switch_types (gfc_symtree * st, gfc_symb
gfc_symbol *
gfc_use_derived (gfc_symbol * sym)
{
- gfc_symbol *s, *p;
+ gfc_symbol *s;
gfc_typespec *t;
gfc_symtree *st;
int i;
@@ -1379,15 +1379,7 @@ gfc_use_derived (gfc_symbol * sym)
s->refs++;
/* Unlink from list of modified symbols. */
- if (changed_syms == sym)
- changed_syms = sym->tlink;
- else
- for (p = changed_syms; p; p = p->tlink)
- if (p->tlink == sym)
- {
- p->tlink = sym->tlink;
- break;
- }
+ gfc_commit_symbol (sym);
switch_types (sym->ns->sym_root, sym, s);
@@ -2264,6 +2256,38 @@ gfc_commit_symbols (void)
}
+/* Makes the changes made in one symbol permanent -- gets rid of undo
+ information. */
+
+void
+gfc_commit_symbol (gfc_symbol * sym)
+{
+ gfc_symbol *p;
+
+ if (changed_syms == sym)
+ changed_syms = sym->tlink;
+ else
+ {
+ for (p = changed_syms; p; p = p->tlink)
+ if (p->tlink == sym)
+ {
+ p->tlink = sym->tlink;
+ break;
+ }
+ }
+
+ sym->tlink = NULL;
+ sym->mark = 0;
+ sym->new = 0;
+
+ if (sym->old_symbol != NULL)
+ {
+ gfc_free (sym->old_symbol);
+ sym->old_symbol = NULL;
+ }
+}
+
+
/* Recursive function that deletes an entire tree and all the common
head structures it points to. */
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h (revision 110142)
+++ gcc/fortran/gfortran.h (working copy)
@@ -1771,6 +1771,7 @@ int gfc_symbols_could_alias (gfc_symbol
void gfc_undo_symbols (void);
void gfc_commit_symbols (void);
+void gfc_commit_symbol (gfc_symbol * sym);
void gfc_free_namespace (gfc_namespace *);
void gfc_symbol_init_2 (void);
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (revision 110142)
+++ gcc/fortran/resolve.c (working copy)
@@ -2088,6 +2088,7 @@ gfc_resolve_index (gfc_expr * index, int
if (index->ts.kind != gfc_index_integer_kind
|| index->ts.type != BT_INTEGER)
{
+ gfc_clear_ts (&ts);
ts.type = BT_INTEGER;
ts.kind = gfc_index_integer_kind;
More information about the Gcc-patches
mailing list