diff options
author | Tobias Burnus <burnus@net-b.de> | 2010-01-04 08:30:49 +0100 |
---|---|---|
committer | Tobias Burnus <burnus@gcc.gnu.org> | 2010-01-04 08:30:49 +0100 |
commit | 5b13080782bb78ffcf0ac8150e379a30fbcef04a (patch) | |
tree | 8e4ad400c37fd8a181953cc2a8978ff5aaaeec7e /gcc/fortran | |
parent | f42621553669746ede1f161f110f78c7df817aa6 (diff) | |
download | gcc-5b13080782bb78ffcf0ac8150e379a30fbcef04a.zip gcc-5b13080782bb78ffcf0ac8150e379a30fbcef04a.tar.gz gcc-5b13080782bb78ffcf0ac8150e379a30fbcef04a.tar.bz2 |
re PR fortran/41872 (wrong-code: Issues with allocatable scalars)
2009-01-04 Tobias Burnus <burnus@net-b.de>
PR fortran/41872
* trans-expr.c (gfc_conv_procedure_call): Add indirect ref
for functions returning allocatable scalars.
* trans-stmt.c (gfc_trans_allocate): Emmit error when
reallocating an allocatable scalar.
* trans.c (gfc_allocate_with_status): Fix pseudocode syntax
in comment.
* trans-decl.c (gfc_trans_deferred_vars): Nullify local
allocatable scalars.
(gfc_generate_function_code): Nullify result variable for
allocatable scalars.
PR fortran/40849
* module.c (gfc_use_module): Fix warning string to allow
for translation.
PR fortran/42517
* invoke.texi (-fcheck=recursion): Mention that the checking
is also disabled for -frecursive.
* trans-decl.c (gfc_generate_function_code): Disable
-fcheck=recursion when -frecursive is used.
* intrinsic.texi (iso_c_binding): Improve wording.
2009-01-04 Tobias Burnus <burnus@net-b.de>
PR fortran/41872
* gfortran.dg/allocatable_scalar_5.f90: New test.
* gfortran.dg/allocatable_scalar_6.f90: New test.
From-SVN: r155606
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/ChangeLog | 25 | ||||
-rw-r--r-- | gcc/fortran/intrinsic.texi | 4 | ||||
-rw-r--r-- | gcc/fortran/invoke.texi | 2 | ||||
-rw-r--r-- | gcc/fortran/module.c | 6 | ||||
-rw-r--r-- | gcc/fortran/trans-decl.c | 26 | ||||
-rw-r--r-- | gcc/fortran/trans-expr.c | 3 | ||||
-rw-r--r-- | gcc/fortran/trans-stmt.c | 27 | ||||
-rw-r--r-- | gcc/fortran/trans.c | 1 |
8 files changed, 77 insertions, 17 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index af2d0c6d..c033b6e 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,28 @@ +2010-01-04 Tobias Burnus <burnus@net-b.de> + + PR fortran/41872 + * trans-expr.c (gfc_conv_procedure_call): Add indirect ref + for functions returning allocatable scalars. + * trans-stmt.c (gfc_trans_allocate): Emmit error when + reallocating an allocatable scalar. + * trans.c (gfc_allocate_with_status): Fix pseudocode syntax + in comment. + * trans-decl.c (gfc_trans_deferred_vars): Nullify local + allocatable scalars. + (gfc_generate_function_code): Nullify result variable for + allocatable scalars. + + PR fortran/40849 + * module.c (gfc_use_module): Fix warning string to allow + for translation. + + PR fortran/42517 + * invoke.texi (-fcheck=recursion): Mention that the checking + is also disabled for -frecursive. + * trans-decl.c (gfc_generate_function_code): Disable + -fcheck=recursion when -frecursive is used. + + * intrinsic.texi (iso_c_binding): Improve wording. Copyright (C) 2010 Free Software Foundation, Inc. diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi index 753e6e1..d37c807 100644 --- a/gcc/fortran/intrinsic.texi +++ b/gcc/fortran/intrinsic.texi @@ -11350,8 +11350,8 @@ C_INT_LEAST128_T, C_INT_FAST128_T}. @item @code{CHARACTER}@tab @code{C_CHAR} @tab @code{char} @end multitable -Additionally, the following @code{(CHARACTER(KIND=C_CHAR))} are -defined. +Additionally, the following parameters of type @code{CHARACTER(KIND=C_CHAR)} +are defined. @multitable @columnfractions .20 .45 .15 @item Name @tab C definition @tab Value diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index b9ad170..21db293 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -1258,7 +1258,7 @@ Enable generation of run-time checks for pointers and allocatables. Enable generation of run-time checks for recursively called subroutines and functions which are not marked as recursive. See also @option{-frecursive}. Note: This check does not work for OpenMP programs and is disabled if used -together with @option{-fopenmp}. +together with @option{-frecursive} and @option{-fopenmp}. @end table diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 81a2613..a07af9a 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -5491,9 +5491,9 @@ gfc_use_module (void) if (strcmp (atom_string, MOD_VERSION)) { - gfc_fatal_error ("Wrong module version '%s' (expected '" - MOD_VERSION "') for file '%s' opened" - " at %C", atom_string, filename); + gfc_fatal_error ("Wrong module version '%s' (expected '%s') " + "for file '%s' opened at %C", atom_string, + MOD_VERSION, filename); } } diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 9a01dba..f93cc9f 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -3188,7 +3188,7 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, tree fnbody) || (sym->ts.type == BT_CLASS && sym->ts.u.derived->components->attr.allocatable)) { - /* Automatic deallocatation of allocatable scalars. */ + /* Nullify and automatic deallocatation of allocatable scalars. */ tree tmp; gfc_expr *e; gfc_se se; @@ -3203,10 +3203,13 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, tree fnbody) gfc_conv_expr (&se, e); gfc_free_expr (e); + /* Nullify when entering the scope. */ gfc_start_block (&block); + gfc_add_modify (&block, se.expr, fold_convert (TREE_TYPE (se.expr), + null_pointer_node)); gfc_add_expr_to_block (&block, fnbody); - /* Note: Nullifying is not needed. */ + /* Deallocate when leaving the scope. Nullifying is not needed. */ tmp = gfc_deallocate_with_status (se.expr, NULL_TREE, true, NULL); gfc_add_expr_to_block (&block, tmp); fnbody = gfc_finish_block (&block); @@ -4319,7 +4322,7 @@ gfc_generate_function_code (gfc_namespace * ns) || (sym->attr.entry_master && sym->ns->entries->sym->attr.recursive); if ((gfc_option.rtcheck & GFC_RTCHECK_RECURSION) && !is_recursive - && !gfc_option.flag_openmp) + && !gfc_option.flag_recursive) { char * msg; @@ -4384,13 +4387,18 @@ gfc_generate_function_code (gfc_namespace * ns) result = sym->result->backend_decl; if (result != NULL_TREE && sym->attr.function - && sym->ts.type == BT_DERIVED - && sym->ts.u.derived->attr.alloc_comp - && !sym->attr.pointer) + && !sym->attr.pointer) { - rank = sym->as ? sym->as->rank : 0; - tmp2 = gfc_nullify_alloc_comp (sym->ts.u.derived, result, rank); - gfc_add_expr_to_block (&block, tmp2); + if (sym->ts.type == BT_DERIVED + && sym->ts.u.derived->attr.alloc_comp) + { + rank = sym->as ? sym->as->rank : 0; + tmp2 = gfc_nullify_alloc_comp (sym->ts.u.derived, result, rank); + gfc_add_expr_to_block (&block, tmp2); + } + else if (sym->attr.allocatable && sym->attr.dimension == 0) + gfc_add_modify (&block, result, fold_convert (TREE_TYPE (result), + null_pointer_node)); } gfc_add_expr_to_block (&block, tmp); diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index b0c19c9..84eb585 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -3413,7 +3413,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, something like x = f() where f is pointer valued, we have to dereference the result. */ - if (!se->want_pointer && !byref && sym->attr.pointer + if (!se->want_pointer && !byref + && (sym->attr.pointer || sym->attr.allocatable) && !gfc_is_proc_ptr_comp (expr, NULL)) se->expr = build_fold_indirect_ref_loc (input_location, se->expr); diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 32c6efc..5159f42 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -4059,7 +4059,32 @@ gfc_trans_allocate (gfc_code * code) if (expr->ts.type == BT_CHARACTER && memsz == NULL_TREE) memsz = se.string_length; - tmp = gfc_allocate_with_status (&se.pre, memsz, pstat); + /* Allocate - for non-pointers with re-alloc checking. */ + { + gfc_ref *ref; + bool allocatable; + + ref = expr->ref; + + /* Find the last reference in the chain. */ + while (ref && ref->next != NULL) + { + gcc_assert (ref->type != REF_ARRAY || ref->u.ar.type == AR_ELEMENT); + ref = ref->next; + } + + if (!ref) + allocatable = expr->symtree->n.sym->attr.allocatable; + else + allocatable = ref->u.c.component->attr.allocatable; + + if (allocatable) + tmp = gfc_allocate_array_with_status (&se.pre, se.expr, memsz, + pstat, expr); + else + tmp = gfc_allocate_with_status (&se.pre, memsz, pstat); + } + tmp = fold_build2 (MODIFY_EXPR, void_type_node, se.expr, fold_convert (TREE_TYPE (se.expr), tmp)); gfc_add_expr_to_block (&se.pre, tmp); diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c index 42d2238..a107392 100644 --- a/gcc/fortran/trans.c +++ b/gcc/fortran/trans.c @@ -711,6 +711,7 @@ gfc_allocate_with_status (stmtblock_t * block, tree size, tree status) } else runtime_error ("Attempting to allocate already allocated array"); + } } expr must be set to the original expression being allocated for its locus |