From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16583 invoked by alias); 21 Mar 2018 08:39:19 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 16561 invoked by uid 89); 21 Mar 2018 08:39:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=txt X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-lf0-f48.google.com Received: from mail-lf0-f48.google.com (HELO mail-lf0-f48.google.com) (209.85.215.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 21 Mar 2018 08:39:17 +0000 Received: by mail-lf0-f48.google.com with SMTP id v207-v6so6593737lfa.10; Wed, 21 Mar 2018 01:39:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=i+hqVvEJ6wYglkxw7bse+t2NihADNWGGRzMkV1Wax4U=; b=PFmtFsRVkInT4PIjZjwY6UwNZYYaesDe9MMltSS++AiLv68wtJ4xz7MOWEjt0JJxmB KtmaPt8m1su6ViWclu80sFpM9hw9WjHeZEd3hBBzgW1WcFWPUaX2UrCae1etwsnDHJJH 7up3o47MXlZQPlB3XeYW+q+SeUUlDmq4TMfz5t2EnXij7G9xzMM8eYxQZFdfBZDlFInD /V+MGLJrlANib7h75BFEJ6PmVwv+F65cAYEADUbaJAT8pR9JAXrLc9gDdL268jdZYuTZ 5nxCfpe73iZNhQY1Q7VUWMkHsVnz/OaJoG1yozgMGQi21gjYaQx1HFbAwGbWVrB6spaM eChA== X-Gm-Message-State: AElRT7FWdq7zU1TPo+i+Pcgn6kKkHsdbXM0qxHPTMj9Q6ONWHI6DIpI/ Hxg3bo1zjFvm/6QEamPAy2+6bQ== X-Google-Smtp-Source: AG47ELuYPZgFsyoyxaWPx5kTwyaxC4e3Kk5JFQmyjZH97fcURROzIlm65LbHYeKUvldgfJMHc+t6XA== X-Received: by 2002:a19:b516:: with SMTP id e22-v6mr13885047lff.47.1521621554983; Wed, 21 Mar 2018 01:39:14 -0700 (PDT) Received: from dt.lan (88-114-247-254.elisa-laajakaista.fi. [88.114.247.254]) by smtp.gmail.com with ESMTPSA id l66-v6sm892996lfe.74.2018.03.21.01.39.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Mar 2018 01:39:14 -0700 (PDT) From: Janne Blomqvist To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Janne Blomqvist Subject: [PATCH] PR 84615 Regressions due to type mismatch with character functions Date: Wed, 21 Mar 2018 08:39:00 -0000 Message-Id: <1521621546-21072-1-git-send-email-blomqvist.janne@gmail.com> X-IsSubscribed: yes X-SW-Source: 2018-03/txt/msg00109.txt.bz2 Since the kind of the hidden character length variable is not part of the character variable definition, we must ensure that character lengths are always of the same kind in interfaces, regardless of how they were declared in the source. This patch ensures this when calling a procedure. Regtested on x86_64-pc-linux-gnu and i686-pc-linux-gnu, Ok for trunk? gcc/fortran/ChangeLog: 2018-03-21 Janne Blomqvist PR fortra/84615 * trans-expr.c (gfc_conv_procedure_call): Convert charlen to gfc_charlen_type_node when calling procedure. gcc/testsuite/ChangeLog: 2018-03-21 Janne Blomqvist PR fortran/84615 * gfortran.dg/char_result_17.f90: New test. --- gcc/fortran/trans-expr.c | 8 ++++++-- gcc/testsuite/gfortran.dg/char_result_17.f90 | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/char_result_17.f90 diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 54bda1d..8bf5504 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -5973,9 +5973,13 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, gfc_add_block_to_block (&se->pre, &parmse.pre); gfc_add_block_to_block (&se->post, &parmse.post); tmp = parmse.expr; + /* TODO: It would be better to have the charlens as + gfc_charlen_type_node already when the interface is + created instead of converting it here (see PR 84615). */ tmp = fold_build2_loc (input_location, MAX_EXPR, - TREE_TYPE (tmp), tmp, - build_zero_cst (TREE_TYPE (tmp))); + gfc_charlen_type_node, + fold_convert (gfc_charlen_type_node, tmp), + build_zero_cst (gfc_charlen_type_node)); cl.backend_decl = tmp; } diff --git a/gcc/testsuite/gfortran.dg/char_result_17.f90 b/gcc/testsuite/gfortran.dg/char_result_17.f90 new file mode 100644 index 0000000..05ab72d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/char_result_17.f90 @@ -0,0 +1,20 @@ +! { dg-do run } +! PR fortran/84615 +! Charlen should always be the ABI defined character length type +! regardless of which kind it is declared as in the source. +program TestStringTools + character(len=52) :: txt + character(len=1), dimension(52) :: chararr = & + (/(char(i+64),char(i+96), i = 1,26)/) + txt = chararray2string(chararr) + if (txt .ne. "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz") & + STOP 1 +contains + function chararray2string(chararray) result(text) + character(len=1), dimension(:) :: chararray ! input + character(len=int(size(chararray, 1), kind=8)) :: text ! output + do i = 1,size(chararray,1) + text(i:i) = chararray (i) + end do + end function chararray2string +end program TestStringTools -- 2.7.4