This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [Patch, fortran] PR34813 and PR33295
- From: "Paul Richard Thomas" <paul dot richard dot thomas at gmail dot com>
- To: "Fortran List" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 23 Mar 2008 08:22:47 +0100
- Subject: Re: [Patch, fortran] PR34813 and PR33295
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=a87XXfpdIDQKiYcBvLgZgjWHkBecPxBSGGGROMb75LM=; b=bkhRGsAWWPcE1by8aoujUvHNEidV6jmcHSsapcESp8nM7k6IvffOArqV8nj/luLVofuWpP5pVWEhsyPDxYWCHWkf/qQZTAYwPaJCpOGhvf0S1OLIHPqK51KWPIemVT3pPNiZAlu1jP0zia/r9Z1NZg57hSdb81m7P8Zz926vl7U=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=Z945Wuogz/TpTTtkwG2kB+HRnJuB0lbFV6+XGSNUrZq0pHyA3y54vaQ+z4Qo1VA73x+W+6oOq/ilS7s4XRaBaMVibD9pn2ZS9GtEE8613XReQw1ilbOtdWpgm/4nZm2Q44pW6tDkvlixiMW/15+M+7CNBEIopkxVUHZAbBMAZOA=
- References: <339c37f20803211351m5e8bb759k6551420f2a1ad073@mail.gmail.com> <339c37f20803220042k2244e44g9b74a42e63d7b31f@mail.gmail.com>
The attached cures the problem that Dominique found by being much more
restrictive on what gets a new symtree and looking after the reference
count.
Bootstraps and regtests on x86_ia64/FC8 - OK for trunk?
Paul
Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c (revision 133208)
--- gcc/fortran/resolve.c (working copy)
*************** resolve_structure_cons (gfc_expr *expr)
*** 827,832 ****
--- 827,842 ----
t = gfc_convert_type (cons->expr, &comp->ts, 1);
}
+ if (cons->expr->expr_type == EXPR_NULL
+ && !(comp->pointer || comp->allocatable))
+ {
+ t = FAILURE;
+ gfc_error ("The NULL in the derived type constructor at %L is "
+ "being applied to component '%s', which is neither "
+ "a POINTER nor ALLOCATABLE", &cons->expr->where,
+ comp->name);
+ }
+
if (!comp->pointer || cons->expr->expr_type == EXPR_NULL)
continue;
*************** resolve_symbol (gfc_symbol *sym)
*** 7974,7979 ****
--- 7984,8012 ----
return;
}
+ /* Make sure that the derived type has been resolved and that the
+ derived type is visible in the symbol's namespace, if it is a
+ module function and is not PRIVATE. */
+ if (sym->ts.type == BT_DERIVED
+ && sym->ts.derived->attr.use_assoc
+ && sym->ns->proc_name->attr.flavor == FL_MODULE)
+ {
+ gfc_symbol *ds;
+
+ if (resolve_fl_derived (sym->ts.derived) == FAILURE)
+ return;
+
+ gfc_find_symbol (sym->ts.derived->name, sym->ns, 1, &ds);
+ if (!ds && sym->attr.function
+ && gfc_check_access (sym->attr.access, sym->ns->default_access))
+ {
+ symtree = gfc_new_symtree (&sym->ns->sym_root,
+ sym->ts.derived->name);
+ symtree->n.sym = sym->ts.derived;
+ sym->ts.derived->refs++;
+ }
+ }
+
/* Unless the derived-type declaration is use associated, Fortran 95
does not allow public entries of private derived types.
See 4.4.1 (F95) and 4.5.1.1 (F2003); and related interpretation
Index: gcc/testsuite/gfortran.dg/null_3.f90
===================================================================
*** gcc/testsuite/gfortran.dg/null_3.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/null_3.f90 (revision 0)
***************
*** 0 ****
--- 1,18 ----
+ ! { dg-do compile }
+ ! This checks the fix for PR34813 in which the error at line 17
+ ! was not detected.
+ !
+ ! Contributed by Daniel Franke <dfranke@gcc.gnu.org>
+ !
+ SUBROUTINE kd_tree_init_default()
+ TYPE :: kd_tree_node
+ INTEGER :: dummy
+ END TYPE
+
+ TYPE :: kd_tree
+ TYPE(kd_tree_node) :: root
+ END TYPE
+
+ TYPE(kd_tree) :: tree
+ tree = kd_tree(null()) ! { dg-error "neither a POINTER nor ALLOCATABLE" }
+ END SUBROUTINE
Index: gcc/testsuite/gfortran.dg/module_function_type_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/module_function_type_1.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/module_function_type_1.f90 (revision 0)
***************
*** 0 ****
--- 1,33 ----
+ ! { dg-do compile }
+ ! This checks the fix for PR33295 in which the A_type in initA was
+ ! not promoted to module level and so not recognised as being the
+ ! same as that emanating directly from module a.
+ !
+ ! Contributed by Janus Weil <jaydub66@gmail.com>
+ !
+ module A
+ type A_type
+ real comp
+ end type
+ end module A
+
+ module B
+ contains
+ function initA()
+ use A
+ implicit none
+ type(A_type):: initA
+ initA%comp=1.0
+ end function
+ end module B
+
+ program C
+ use B
+ use A
+ implicit none
+ type(A_type):: A_var
+ A_var = initA()
+ end program C
+
+ ! { dg-final { cleanup-modules "A B" } }
+