From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 67119 invoked by alias); 9 Sep 2015 07:25:52 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 67091 invoked by uid 89); 9 Sep 2015 07:25:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=3.3 required=5.0 tests=AWL,BAYES_50,FOREIGN_BODY1,FREEMAIL_FROM,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,SPF_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: sender153-mail.zoho.com Received: from sender153-mail.zoho.com (HELO sender153-mail.zoho.com) (74.201.84.153) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 09 Sep 2015 07:25:49 +0000 Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1441783545429554.6030975115483; Wed, 9 Sep 2015 00:25:45 -0700 (PDT) Received: from [209.169.24.247] by mail.zoho.com with HTTP;Wed, 9 Sep 2015 00:25:45 -0700 (PDT) Date: Wed, 09 Sep 2015 07:37:00 -0000 From: Louis Krupp To: "gcc-patches" , "fortran" Message-ID: <14fb0fefe25.1083784a532578.5562174689543109473@zoho.com> Subject: Possible patch for pr62242 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_26840_136896050.1441783545377" User-Agent: Zoho Mail X-Zoho-Virus-Status: 1 X-SW-Source: 2015-09/txt/msg00564.txt.bz2 ------=_Part_26840_136896050.1441783545377 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Content-length: 3755 This was ... interesting. There were a couple of problems that triggered ICEs. This patch fixes the reported file (I made sure this time) and causes no regressions as far as I can tell. Dominique ... merci de votre patience. Louis Index: gcc/fortran/ChangeLog =================================================================== --- gcc/fortran/ChangeLog (revision 227571) +++ gcc/fortran/ChangeLog (working copy) @@ -1,3 +1,12 @@ +2015-09-08 Louis Krupp + + PR fortran/62242 + * trans-array.c (get_array_ctor_all_strlen): Don't store length + tree pointer unless we know it's necessary + (trans_array_constructor): Create new gfc_charlen instance so + context-specific length expression isn't shared + (gfc_add_loop_ss_code): Don't try to convert non-constant length + 2015-09-04 Francois-Xavier Coudert * intrinsic.h (gfc_simplify_mvbits): Remove. Index: gcc/fortran/trans-array.c =================================================================== --- gcc/fortran/trans-array.c (revision 227571) +++ gcc/fortran/trans-array.c (working copy) @@ -1836,7 +1836,9 @@ get_array_ctor_all_strlen (stmtblock_t *block, gfc gfc_add_block_to_block (block, &se.pre); gfc_add_block_to_block (block, &se.post); - e->ts.u.cl->backend_decl = *len; + /* TODO: No test cases failed when the "if (0)" was added. + Is there a reason to put this back the way it was? */ + if (0) e->ts.u.cl->backend_decl = *len; } } @@ -2226,6 +2228,7 @@ trans_array_constructor (gfc_ss * ss, locus * wher if (expr->ts.type == BT_CHARACTER) { bool const_string; + gfc_charlen *new_cl; /* get_array_ctor_strlen walks the elements of the constructor, if a typespec was given, we already know the string length and want the one @@ -2251,8 +2254,36 @@ trans_array_constructor (gfc_ss * ss, locus * wher and not end up here. */ gcc_assert (ss_info->string_length); - expr->ts.u.cl->backend_decl = ss_info->string_length; + /* get_array_ctor_strlen can create a temporary variable in the + current context which will be part of string_length. If we share + the resulting gfc_charlen structure with a variable in a different + declaration context, we could trip the assertion in + expand_expr_real_1 when it sees that the temporary has been + created in one context and referenced in another: + if (exp) + context = decl_function_context (exp); + gcc_assert (!exp + || SCOPE_FILE_SCOPE_P (context) + || context == current_function_decl + || TREE_STATIC (exp) + || DECL_EXTERNAL (exp) + // ??? C++ creates functions that are not TREE_STATIC. + || TREE_CODE (exp) == FUNCTION_DECL); + + So we create a new gfc_charlen structure and link it into what + looks like the current namespace. + + TODO: Can we do this only when get_array_ctor_strlen has been + called? Does it matter? Are we using the right namespace (and + does it matter, as long as the gfc_charlen structure is cleaned + up)? + */ + + new_cl = gfc_new_charlen (gfc_current_ns, expr->ts.u.cl); + new_cl->backend_decl = ss_info->string_length; + expr->ts.u.cl = new_cl; + type = gfc_get_character_type_len (expr->ts.kind, ss_info->string_length); if (const_string) type = build_pointer_type (type); @@ -2589,7 +2620,8 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss if (expr->ts.type == BT_CHARACTER && ss_info->string_length == NULL && expr->ts.u.cl - && expr->ts.u.cl->length) + && expr->ts.u.cl->length + && expr->ts.u.cl->length->expr_type == EXPR_CONSTANT) { gfc_init_se (&se, NULL); gfc_conv_expr_type (&se, expr->ts.u.cl->length, ------=_Part_26840_136896050.1441783545377 Content-Type: application/octet-stream; name=string_array_constructor_1.f90 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=string_array_constructor_1.f90 Content-length: 763 ! { dg-do compile } ! PR 62242 ! Array constructor with an array element whose value is a ! character function that is described in an interface block and which ! has an assumed-length result module gfbug implicit none INTERFACE function UpperCase(string) result(upper) character(*), intent(IN) :: string character(LEN(string)) :: upper end function function f2(string) result(upper) character(*), intent(IN) :: string character(5) :: upper end function END INTERFACE contains subroutine s1 character(5) c character(5), dimension(1) :: ca ca = (/f2(c)/) ! This compiles ca = (/Uppercase(c)/) ! This gets an ICE end subroutine end module gfbug ------=_Part_26840_136896050.1441783545377 Content-Type: application/octet-stream; name=string_array_constructor_2.f90 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=string_array_constructor_2.f90 Content-length: 1272 ! { dg-do run } ! PR 62242 ! Array constructor with an array element whose value is a ! character function that is described in an interface block and which ! has an assumed-length result module gfbug implicit none INTERFACE function UpperCase(string) result(upper) character(*), intent(IN) :: string character(LEN(string)) :: upper end function function f2(string) result(upper) character(*), intent(IN) :: string character(5) :: upper end function END INTERFACE contains subroutine s1 character(5) c character(5), dimension(1) :: ca character(5), dimension(1) :: cb c = "12345" ca = (/f2(c)/) ! This works !print *, ca(1) cb = (/Uppercase(c)/) ! This gets an ICE if (ca(1) .ne. cb(1)) then call abort() end if !print *, ca(1) end subroutine end module gfbug function UpperCase(string) result(upper) character(*), intent(IN) :: string character(LEN(string)) :: upper upper = string end function function f2(string) result(upper) character(*), intent(IN) :: string character(5) :: upper upper = string end function program main use gfbug call s1 end program ------=_Part_26840_136896050.1441783545377 Content-Type: application/octet-stream; name=string_array_constructor_3.f90 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=string_array_constructor_3.f90 Content-length: 614 ! { dg-do compile } ! PR 62242 ! A subprogram calling an array constructor with an array element whose ! value is the result of calling a character function with both an ! assumed-length argument and an assumed-length result module gfbug implicit none contains function inner(inner_str) result(upper) character(*), intent(IN) :: inner_str character(LEN(inner_str)) :: upper upper = '123' end function subroutine outer(outer_str) character(*), intent(IN) :: outer_str character(5) :: z(1) z = [inner(outer_str)] end subroutine end module gfbug ------=_Part_26840_136896050.1441783545377--