From patchwork Tue Feb 13 22:55:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry DeLisle X-Patchwork-Id: 200721 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp853765dyb; Tue, 13 Feb 2024 14:56:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVAqhR4rtcR3UO5D1eXVWYYKT8vKppr7QFO8TLE8P6jDcK5dms1yt3zY4/Jg/wYl6WtR1NeP/um3rZalYA0efadEysGIA== X-Google-Smtp-Source: AGHT+IHYcG3sRVEf91U6MBeprPX3nUZav9vDrSpiDtVXc80/gjYctybQv9Hk/5OBCXhrVboSL0qQ X-Received: by 2002:a05:6214:1c08:b0:68c:4a73:a82b with SMTP id u8-20020a0562141c0800b0068c4a73a82bmr1095613qvc.43.1707865011378; Tue, 13 Feb 2024 14:56:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707865011; cv=pass; d=google.com; s=arc-20160816; b=iMHHJYcR36au132pgOV+RWB4Ngc2HrSC/lXkkeMEEkEkIvolYw6Igd6geyUzCO6WkH HjkkRqxdy1bkMzfhdJnj9JhRBAYzv0r3sX/4Bn0kZuuD1Kvi9aZ4nFsaodatQiXbt08i v9xxyloqG5+Z0WGzwOd78eZFQPxDURZ51iqyvcJdy5LDQmMxvTi9ftxlYElmVlXRP04j 3ghXNZzfxfmziYkJPM7yLA0WZURb4AqdPRlETOypeP7f/zF9bHDcfRpjFIW2XU/WHRug kYtK6ql+/9jOW/DLB6UNyicq2xj5R1tqOR35e4rV8+Gl4KbilTNPJd3O5+IQYrU/9cBS WhtQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:feedback-id :message-id:subject:cc:from:to:date:dkim-signature:arc-filter :dmarc-filter:delivered-to; bh=XZptzOhMKjbAEqA0Wd8Qi/H5v6ytGF8labvbVlRdIfw=; fh=iOfCkOGS08Ou1lXgQRftb9llCH2lAnDQgjbgfiPkRBk=; b=JZVm3e++5HcwdiIriJvlQnMlanpBoom5nCFJmtDNHwLtg0hT3l89oD1veWBDuoPlnu wx8WTzDjaR7guiUQQTZcC3i/2Fb8Nvp8JVPfFJUCloVo2Kz9gcLvR36qoZjlx/yEiRcE sgz0+W+ZEUTawH1x9nfqEcSY2NntZJ80VvE+K3jojlsJ+yqCDEMVLntupNjzwGp0khia 9KN/lvgrk9fZ0WwzHcEynnbTN0TTHDHl4HEr9k0OJbBeaJZT22X974MszKyTJLzyy/zb l/pVjiHREyAWp1WQ9SM3mgrpFheerzK0d1Bs3ZdTCIpII0GclSuOIVGytLwd+lkH+EJO VNMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=Ow2E7mUt; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com X-Forwarded-Encrypted: i=2; AJvYcCXRnGjFXQiLBYwW78A3wWD6kJYB65qaUiXAs0tW/kOn9YTFUOJf8QQ53W2TjZBKCg+L/lV45SNBuGpHESA7s8Xu/T1apQ== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dv5-20020ad44ee5000000b0068cb0a77fb2si781916qvb.342.2024.02.13.14.56.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:56:51 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=Ow2E7mUt; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 109953857BBC for ; Tue, 13 Feb 2024 22:56:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by sourceware.org (Postfix) with ESMTPS id 321F63857C66 for ; Tue, 13 Feb 2024 22:56:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 321F63857C66 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=protonmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 321F63857C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=185.70.43.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707864967; cv=none; b=FoKtZ5jfSR1zaGe4ylesbwCVMErwsWsF9VBHJ06xPjI879mE4KYniWDgtFtI14YY7P+BnK3CZE020uhPtypLsU2sKWwkAwbKfyHNr5WFRFRGkkIF5Gj8SP718Q6hf4jWXNOAGALJHDaMsT28RP+ehoBfQPQaCRLS0uCUcuS2ZUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707864967; c=relaxed/simple; bh=XZptzOhMKjbAEqA0Wd8Qi/H5v6ytGF8labvbVlRdIfw=; h=DKIM-Signature:Date:To:From:Subject:Message-ID:MIME-Version; b=aBbm13KN3dtTZEfNNYqt8h3ZyhVsMfQw+qFBWe5vQEugq5eJiOArRhGUT1+BRT4RC66NlTo4p8zabmB7B76UYCAMjmczkMFd42TBmV4ikKWAcz8HBPFzW/UE2MT4O6mOZMhe6HSaR/grGCD2ACgk1YDNbRHm/VQj9+RNgMVomfY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1707864963; x=1708124163; bh=XZptzOhMKjbAEqA0Wd8Qi/H5v6ytGF8labvbVlRdIfw=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=Ow2E7mUtEIF/fzdxbOfplyBN4WbZ/SzGRVBR+aZ4YBSi6/WgjCo0w1xxU/JJd7kP/ hD1Qn6lMDanzcKj++gKEb0SAkQ57YZu4297O9EutHwinCe/mfXv3gj8r9gNjx6V2GE UJyh7f+GW2sdoFewAaKd16/s2ekLSbNJdSWkOp3AaSIUgM/ujPGgbC5kiGjVALPiQo 7y4zsP2njv4lpRuhPG1Qh22c3GPhZP+/fXrd8mQg8ELsyuGe/JSQ/TyFzhVFKRm1q2 XhWipPt3d4FIQMa1exakuuVCbZLlSMmOtqo0qYFIL2JE3LMeKUjEvQo/nw1bi/RjAj Odq3DquOUGBUw== Date: Tue, 13 Feb 2024 22:55:41 +0000 To: gfortran From: Jerry DeLisle Cc: gcc-patches Subject: [patch, libgfortran] PR99210 X editing for reading file with encoding='utf-8' Message-ID: Feedback-ID: 34907122:user:proton MIME-Version: 1.0 X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790826261997501122 X-GMAIL-MSGID: 1790826261997501122 The attached patch fixes the X editing. Fairly self explanatory. I created the patch a few years back. Regression tested on x86_64 and new test case. OK for trunk? Regards, Jerry diff --git a/gcc/testsuite/gfortran.dg/pr99210.f90 b/gcc/testsuite/gfortran.dg/pr99210.f90 new file mode 100644 index 00000000000..9fd2fb468df --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr99210.f90 @@ -0,0 +1,29 @@ +! { dg-do run } +! PR99210 X editing for reading file with encoding='utf-8' +program test_bug_format_x + use iso_fortran_env + integer, parameter :: u = selected_char_kind('ISO_10646') + + character(kind=u, len=1) a, b, a1, b1, b2 + + open(unit=10, file='test_bug_format_x.tmp', encoding='UTF-8') + + a = char(int(z'03B1'), u) + b = char(int(z'03B2'), u) + write(10, '(a1, a1)') a, b + + rewind(10) + read(10, '(a1, a1)') a1, b1 + + rewind(10) + read(10, '(1x, a1)') b2 + + close (10, status="delete") + if(a /= a1 .or. b /= b1) then + error stop 1 + end if + + if(b /= b2) then + error stop 2 + end if +end program test_bug_format_x diff --git a/libgfortran/io/read.c b/libgfortran/io/read.c index 0ffcf76fd38..e2d2f8be806 100644 --- a/libgfortran/io/read.c +++ b/libgfortran/io/read.c @@ -1307,6 +1307,23 @@ read_x (st_parameter_dt *dtp, size_t n) if (n == 0) return; + + if (dtp->u.p.current_unit->flags.encoding == ENCODING_UTF8) + { + gfc_char4_t c; + size_t nbytes, j; + + /* Proceed with decoding one character at a time. */ + for (j = 0; j < n; j++) + { + c = read_utf8 (dtp, &nbytes); + + /* Check for a short read and if so, break out. */ + if (nbytes == 0 || c == (gfc_char4_t)0) + break; + } + return; + } length = n;