From patchwork Wed Jun 28 20:44:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 114050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9198213vqr; Wed, 28 Jun 2023 13:45:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5p1mvPiw62GrOloOdcHsGZLBVwUeB1LT4s/xOinSnuTkWnoFECc0/R+bZF15J7Mf4Khf3k X-Received: by 2002:a19:2d54:0:b0:4f8:5e5f:b368 with SMTP id t20-20020a192d54000000b004f85e5fb368mr19072205lft.21.1687985131714; Wed, 28 Jun 2023 13:45:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687985131; cv=none; d=google.com; s=arc-20160816; b=XH9d9yLfwLsKOlBKhHKSOVW6BUE42A1CuZPvNlkQyg1kO0tK9PfGk8nfu7Wh2Ood4K NC49jRiK9KoO4H7f4ce/MLwM1H4lSGgTAz3prpKdgYOPLXM9jjM5FaolQ82aTWyyyXLi jo2MX80CGv0k0v5mY+DXE1MccCDEmvRibEi4gdro1IAWEDgf/3ZcycVAgqc3ztHzZV33 F1lOcEo/FGwVvddVJ9cEv+hC2u6dZeVidcQQ3bUQmFx9bQUBRwAIL4NjuUlvp6LtKiUW 5EKrDiHBlHHluk3ViMwFWddBgiyDza44YAdIdqvXv626Mfiz0+PU6MDdd5OtTB4JK95U lCHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=nEL+dJLPEONV4aO+/iPn0nRarrqlGA9tBHU7IZ8QCL4=; fh=+IEfvAe+9BRgPHWhQEl2uIBTtAiiGDh1ExRZeB5JJoc=; b=trXl/yDWiWz28rbEbXjCF9Ji6CQBueWmZSj7rYZpMKzf/H/09EvB+AGG3QJQzJ451H hFMsLStC1BNUyP7dtTPYxTkCHaMXus6BNne2Vw/Ytur7bLfEuMKsiRLz/BKlyuC/xr3F COcNAdBcm36ahmoF7e0TQjvygmVFh9MaihwaYckDpcZGyMDe4t7XrUQ7DijQNWfkrX3M i+qqph5jC4tE5BLfckXs6LMKRclvso8nS+Q1XyhQFRd9TCe+LYVQRhevpbRlkkpISCoI cvvNc2mT2cZdXv99SxWf3ZQZr0zzuqPhSyCNeoM66Hh+a5rTeZuJzU8RY9oD4VAeVm6G lU6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sQQWfbJf; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id a15-20020aa7d90f000000b0051a47011c0dsi5963753edr.112.2023.06.28.13.45.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 13:45:31 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sQQWfbJf; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C57C3858D3C for ; Wed, 28 Jun 2023 20:45:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C57C3858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687985130; bh=nEL+dJLPEONV4aO+/iPn0nRarrqlGA9tBHU7IZ8QCL4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=sQQWfbJfv3KZ+I3nUOAXZGbzIgfxyJa3wFRG5GS/qVXx+Mq2Yj9CzJ6ANSS0Xxvnx dDVX/KPpa4catzg1Z/4b85fg7J7IbhE5vECn7S+8CJ9MWfibODG9kD0viyq2fCHs1M SAFsBW65X/ZoJN49jko+dPNM7vFMVfwoGumlTLKs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by sourceware.org (Postfix) with ESMTPS id 669523858D35; Wed, 28 Jun 2023 20:44:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 669523858D35 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.80.85] ([93.207.80.85]) by web-mail.gmx.net (3c-app-gmx-bs03.server.lan [172.19.170.52]) (via HTTP); Wed, 28 Jun 2023 22:44:25 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH, part3, committed] Fortran: ABI for scalar CHARACTER(LEN=1),VALUE dummy argument [PR110360] Date: Wed, 28 Jun 2023 22:44:25 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:rEwBPH4SeErWzAFYd2aq2VAASDanOyess+8Y/QZUu9jMZg+e4RemU3V4ukLDuy0Mfn6EK u2zSnh3c9ETFKEe+JKi87PzuxksSXmxzwdcvhLvbWkXMRixBQYhT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-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769980697752707203?= X-GMAIL-MSGID: =?utf-8?q?1769980697752707203?= Dear all, the previous patches to this PR unfortunately caused a regression, seen on Power big-endian systems/-m32 (pr110419), and while trying to investigate on x86 also showed a regression (ICE) on cases that were not covered in the testsuite before. The original fix did not properly handle the dereferencing of string arguments that were not constant, and it was lacking the truncation of strings to length one that is needed when passing a character on the stack. This patch has been regtested on x86_64-pc-linux-gnu, and the extended testcase was scrutinized with -m64 and -m32. Pushed after discussion in the PR with Mikael as commit r14-2171-g8736d6b14a4dfdfb58c80ccd398981b0fb5d00aa https://gcc.gnu.org/g:8736d6b14a4dfdfb58c80ccd398981b0fb5d00aa Will keep the PR open as long as the issues on Power big-endian are not confirmed resolved. Thanks, Harald From 8736d6b14a4dfdfb58c80ccd398981b0fb5d00aa Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Wed, 28 Jun 2023 22:16:18 +0200 Subject: [PATCH] Fortran: ABI for scalar CHARACTER(LEN=1),VALUE dummy argument [PR110360] gcc/fortran/ChangeLog: PR fortran/110360 * trans-expr.cc (gfc_conv_procedure_call): For non-constant string argument passed to CHARACTER(LEN=1),VALUE dummy, ensure proper dereferencing and truncation of string to length 1. gcc/testsuite/ChangeLog: PR fortran/110360 * gfortran.dg/value_9.f90: Add tests for intermediate regression. --- gcc/fortran/trans-expr.cc | 15 ++++++++++----- gcc/testsuite/gfortran.dg/value_9.f90 | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index ad0cdf902ba..30946ba3f63 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6395,7 +6395,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, /* ABI: actual arguments to CHARACTER(len=1),VALUE dummy arguments are actually passed by value. - Constant strings are truncated to length 1. + Strings are truncated to length 1. The BIND(C) case is handled elsewhere. */ if (fsym->ts.type == BT_CHARACTER && !fsym->ts.is_c_interop @@ -6405,10 +6405,15 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, (fsym->ts.u.cl->length->value.integer, 1) == 0)) { if (e->expr_type != EXPR_CONSTANT) - parmse.expr = gfc_string_to_single_character - (build_int_cst (gfc_charlen_type_node, 1), - parmse.expr, - e->ts.kind); + { + tree slen1 = build_int_cst (gfc_charlen_type_node, 1); + gfc_conv_string_parameter (&parmse); + parmse.expr = gfc_string_to_single_character (slen1, + parmse.expr, + e->ts.kind); + /* Truncate resulting string to length 1. */ + parmse.string_length = slen1; + } else if (e->value.character.length > 1) { e->value.character.length = 1; diff --git a/gcc/testsuite/gfortran.dg/value_9.f90 b/gcc/testsuite/gfortran.dg/value_9.f90 index f6490645e27..1a2fa80ed0d 100644 --- a/gcc/testsuite/gfortran.dg/value_9.f90 +++ b/gcc/testsuite/gfortran.dg/value_9.f90 @@ -9,7 +9,12 @@ program p character (kind=4), allocatable :: ca4 character (kind=4), pointer :: cp4 character(len=:,kind=4), allocatable :: cd4 + character :: c = "1" + character (kind=4) :: c4 = 4_"4" + character(len=3) :: d = "210" + character(len=3,kind=4) :: d4 = 4_"321" integer :: a = 65 + integer :: l = 2 allocate (ca, cp, ca4, cp4) ! Check len=1 actual argument cases first @@ -20,15 +25,21 @@ program p call val ("A",char(a)) call val ("A",mychar(65)) call val ("A",mychar(a)) + call val ("1",c) + call val ("1",(c)) call val4 (4_"C",4_"C") call val4 (4_"A",char(65,kind=4)) call val4 (4_"A",char(a, kind=4)) + call val4 (4_"4",c4) + call val4 (4_"4",(c4)) call val (ca,ca) call val (cp,cp) call val (cd,cd) + call val (ca,(ca)) call val4 (ca4,ca4) call val4 (cp4,cp4) call val4 (cd4,cd4) + call val4 (cd4,(cd4)) call sub ("S") call sub4 (4_"T") @@ -37,6 +48,18 @@ program p call val4 (4_"V**",4_"V//") call sub ( "WTY") call sub4 (4_"ZXV") + call val ( "234", d ) + call val4 (4_"345", d4 ) + call val ( "234", (d) ) + call val4 (4_"345", (d4) ) + call val ( "234", d (1:2)) + call val4 (4_"345", d4(1:2)) + call val ( "234", d (1:l)) + call val4 (4_"345", d4(1:l)) + call val ("1",c // d) + call val ("1",trim (c // d)) + call val4 (4_"4",c4 // d4) + call val4 (4_"4",trim (c4 // d4)) cd = "gkl"; cd4 = 4_"hmn" call val (cd,cd) call val4 (cd4,cd4) -- 2.35.3