From patchwork Wed Dec 19 23:10:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Fortran, committed] Fix -fno-automatic string length static regression Date: Wed, 19 Dec 2012 13:10:32 -0000 From: Tobias Burnus X-Patchwork-Id: 207539 Message-Id: <50D24968.4040507@net-b.de> To: gcc patches , gfortran The check whether the string length should be static or not with -fno-automatic failed to take automatic arrays into account. There are three possibilities for string lengths: a) They can be constant b) They can be based on a nonconstant expression c) They can be deferred (b) is an automatic variable; (a) and (c) might be static, but for (a) it doesn't matter whether the variable is static or not. Hence, only deferred-length variables have to be considered. Approved by Paul on IRC and committed as Rev. 194621 after a successful bootstrap plus regtesting. A test case is, e.g., gfortran.dg/pr26246_2.f90. Tobias Index: gcc/fortran/ChangeLog =================================================================== --- gcc/fortran/ChangeLog (Revision 194620) +++ gcc/fortran/ChangeLog (Arbeitskopie) @@ -1,4 +1,10 @@ 2012-12-19 Tobias Burnus + + PR fortran/55733 + * trans-decl.c (gfc_create_string_length): Avoid setting + TREE_STATIC for automatic variables with -fno-automatic. + +2012-12-19 Tobias Burnus Jakub Jelinek Janus Weil Index: gcc/fortran/trans-decl.c =================================================================== --- gcc/fortran/trans-decl.c (Revision 194620) +++ gcc/fortran/trans-decl.c (Arbeitskopie) @@ -1089,9 +1089,15 @@ gfc_create_string_length (gfc_symbol * sym) tree length; const char *name; + /* The string length variable shall be in static memory if it is either + explicitly SAVED, a module variable or with -fno-automatic. Only + relevant is "len=:" - otherwise, it is either a constant length or + it is an automatic variable. */ bool static_length = sym->attr.save || sym->ns->proc_name->attr.flavor == FL_MODULE - || gfc_option.flag_max_stack_var_size == 0; + || (gfc_option.flag_max_stack_var_size == 0 + && sym->ts.deferred && !sym->attr.dummy + && !sym->attr.result && !sym->attr.function); /* Also prefix the mangled name. We need to call GFC_PREFIX for static variables as some systems do not support the "." in the assembler name.