diff options
author | Daniel Kraft <d@domob.eu> | 2009-09-29 09:42:42 +0200 |
---|---|---|
committer | Daniel Kraft <domob@gcc.gnu.org> | 2009-09-29 09:42:42 +0200 |
commit | 9abe5e56e20294d899363abc8898d4fa6a72e2f7 (patch) | |
tree | 8bbc9942644ae27a9137a47480f2dfeeba5ab54c /gcc/fortran/resolve.c | |
parent | 9b13eb8457f5b02769cfd6762c8885d58be80f78 (diff) | |
download | gcc-9abe5e56e20294d899363abc8898d4fa6a72e2f7.zip gcc-9abe5e56e20294d899363abc8898d4fa6a72e2f7.tar.gz gcc-9abe5e56e20294d899363abc8898d4fa6a72e2f7.tar.bz2 |
re PR fortran/39626 (Correctly implement details of Fortran 2008 BLOCK construct)
2009-09-29 Daniel Kraft <d@domob.eu>
PR fortran/39626
* gfortran.h (enum gfc_statement): Add ST_BLOCK and ST_END_BLOCK.
(struct gfc_namespace): Convert flags to bit-fields and add flag
`construct_entities' for use with BLOCK constructs.
(enum gfc_exec_code): Add EXEC_BLOCK.
(struct gfc_code): Add namespace field to union for EXEC_BLOCK.
* match.h (gfc_match_block): New prototype.
* parse.h (enum gfc_compile_state): Add COMP_BLOCK.
* trans.h (gfc_process_block_locals): New prototype.
(gfc_trans_deferred_vars): Made public, new prototype.
* trans-stmt.h (gfc_trans_block_construct): New prototype.
* decl.c (gfc_match_end): Handle END BLOCK correctly.
(gfc_match_intent): Error if inside of BLOCK.
(gfc_match_optional), (gfc_match_value): Ditto.
* match.c (gfc_match_block): New routine.
* parse.c (decode_statement): Handle BLOCK statement.
(case_exec_markers): Add ST_BLOCK.
(case_end): Add ST_END_BLOCK.
(gfc_ascii_statement): Handle ST_BLOCK and ST_END_BLOCK.
(parse_spec): Check for statements not allowed inside of BLOCK.
(parse_block_construct): New routine.
(parse_executable): Parse BLOCKs.
(parse_progunit): Disallow CONTAINS in BLOCK constructs.
* resolve.c (is_illegal_recursion): Find real container procedure and
don't get confused by BLOCK constructs.
(resolve_block_construct): New routine.
(gfc_resolve_blocks), (resolve_code): Handle EXEC_BLOCK.
* st.c (gfc_free_statement): Handle EXEC_BLOCK statements.
* trans-decl.c (saved_local_decls): New static variable.
(add_decl_as_local): New routine.
(gfc_finish_var_decl): Add variable as local if inside BLOCK.
(gfc_trans_deferred_vars): Make public.
(gfc_process_block_locals): New routine.
* trans-stmt.c (gfc_trans_block_construct): New routine.
* trans.c (gfc_trans_code): Handle EXEC_BLOCK statements.
2009-09-29 Daniel Kraft <d@domob.eu>
PR fortran/39626
* gfortran.dg/block_1.f08: New test.
* gfortran.dg/block_2.f08: New test.
* gfortran.dg/block_3.f90: New test.
* gfortran.dg/block_4.f08: New test.
* gfortran.dg/block_5.f08: New test.
* gfortran.dg/block_6.f08: New test.
* gfortran.dg/block_7.f08: New test.
* gfortran.dg/block_8.f08: New test.
From-SVN: r152266
Diffstat (limited to 'gcc/fortran/resolve.c')
-rw-r--r-- | gcc/fortran/resolve.c | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index f208f40..3eec50e 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -1101,6 +1101,7 @@ is_illegal_recursion (gfc_symbol* sym, gfc_namespace* context) { gfc_symbol* proc_sym; gfc_symbol* context_proc; + gfc_namespace* real_context; gcc_assert (sym->attr.flavor == FL_PROCEDURE); @@ -1114,11 +1115,29 @@ is_illegal_recursion (gfc_symbol* sym, gfc_namespace* context) if (proc_sym->attr.recursive || gfc_option.flag_recursive) return false; - /* Find the context procdure's "real" symbol if it has entries. */ - context_proc = (context->entries ? context->entries->sym - : context->proc_name); - if (!context_proc) - return true; + /* Find the context procedure's "real" symbol if it has entries. + We look for a procedure symbol, so recurse on the parents if we don't + find one (like in case of a BLOCK construct). */ + for (real_context = context; ; real_context = real_context->parent) + { + /* We should find something, eventually! */ + gcc_assert (real_context); + + context_proc = (real_context->entries ? real_context->entries->sym + : real_context->proc_name); + + /* In some special cases, there may not be a proc_name, like for this + invalid code: + real(bad_kind()) function foo () ... + when checking the call to bad_kind (). + In these cases, we simply return here and assume that the + call is ok. */ + if (!context_proc) + return false; + + if (context_proc->attr.flavor != FL_LABEL) + break; + } /* A call from sym's body to itself is recursion, of course. */ if (context_proc == proc_sym) @@ -6838,7 +6857,19 @@ gfc_resolve_forall (gfc_code *code, gfc_namespace *ns, int forall_save) } -/* Resolve lists of blocks found in IF, SELECT CASE, WHERE, FORALL ,GOTO and +/* Resolve a BLOCK construct statement. */ + +static void +resolve_block_construct (gfc_code* code) +{ + /* Eventually, we may want to do some checks here or handle special stuff. + But so far the only thing we can do is resolving the local namespace. */ + + gfc_resolve (code->ext.ns); +} + + +/* Resolve lists of blocks found in IF, SELECT CASE, WHERE, FORALL, GOTO and DO code nodes. */ static void resolve_code (gfc_code *, gfc_namespace *); @@ -6875,6 +6906,10 @@ gfc_resolve_blocks (gfc_code *b, gfc_namespace *ns) resolve_branch (b->label1, b); break; + case EXEC_BLOCK: + resolve_block_construct (b); + break; + case EXEC_SELECT: case EXEC_FORALL: case EXEC_DO: @@ -6902,7 +6937,7 @@ gfc_resolve_blocks (gfc_code *b, gfc_namespace *ns) break; default: - gfc_internal_error ("resolve_block(): Bad block type"); + gfc_internal_error ("gfc_resolve_blocks(): Bad block type"); } resolve_code (b->next, ns); @@ -7066,6 +7101,7 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns) return false; } + /* Given a block of code, recursively resolve everything pointed to by this code block. */ @@ -7250,7 +7286,7 @@ resolve_code (gfc_code *code, gfc_namespace *ns) break; case EXEC_CALL_PPC: - resolve_ppc_call (code); + resolve_ppc_call (code); break; case EXEC_SELECT: @@ -7259,6 +7295,10 @@ resolve_code (gfc_code *code, gfc_namespace *ns) resolve_select (code); break; + case EXEC_BLOCK: + gfc_resolve (code->ext.ns); + break; + case EXEC_DO: if (code->ext.iterator != NULL) { |