From patchwork Thu Apr 4 01:33:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry D X-Patchwork-Id: 88002 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D6C93847725 for ; Thu, 4 Apr 2024 01:35:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id 253A63847718; Thu, 4 Apr 2024 01:34:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 253A63847718 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 253A63847718 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1036 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712194442; cv=none; b=rfmAPcN6242BXmmR2x90pW4CG2eP+0S2qVsx1qnGVEaTO3QdLjPiM7f6rC42dynM2umIb2HmfygC+xY1qflxP4DJkOTqR3/nsLWKW+uTLpiOtO1xOfrAkL2YVPNkf+OVM/Tf5o/Eo5jqbxxEZwSdAKbu7EG6ZfOwRQAgUqKEtJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712194442; c=relaxed/simple; bh=yfEsNTFuRxcCUr/UwuzJBU5DcXEt9+3rYgbB67mWO9I=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=aihzOl1sDoH/k6k1rmlIheCkNCQP1YQpIMQ6aahKPCNCTb5a1BrJtuJlC9fFXFYn3BcQweNe/InkqHKgSaETPlVbzBlQ3hHDLZbyScFeIsN1EbEoR52yCmZ8VrEhB83hfej0HIWoYcULLC8b1QcpOY2NEkMbd3uBgzbcAsM2CaY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2a2d37b8c4fso34871a91.1; Wed, 03 Apr 2024 18:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712194438; x=1712799238; darn=gcc.gnu.org; h=autocrypt:subject:from:cc:to:content-language:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=rnDksEDYKo3PIZQHCywJTZI//nMoPMaRZL7TXAO7DLo=; b=UNFwuyT2Mr25iuxECVdWnvBYeRGuVGDaxClKbFYhDpxcMWxotk5yCWNj/BR4hHf4QD AlmYC/Vuz3FHriVGfwHokiHazTjId8cJQGfdUG1Px3WABvWokV9PMxS7UTjjyu1SCrL2 eFIkdVl4M2TM33Orzn+AgErs/WjOvPXB50ebRB8mx6kdk+Y0d0JVU5kpxXv8OwXWaS8r 9QOyLSU9vROamW1r+alN1sLS9ROxQYFWqGkDHfOkvijnwOuFwAtxfYJLHILiFy1N/+fP BuFj1/n335A6UVBtUS4cP6a6KWXR6mndLgqNiIUKazwEyKnlMJAUYSHhEZqJjGytw85P BC+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712194438; x=1712799238; h=autocrypt:subject:from:cc:to:content-language:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=rnDksEDYKo3PIZQHCywJTZI//nMoPMaRZL7TXAO7DLo=; b=icC9NJRSuRFEqmXmZDR9S/I0ZxRcanKH2Gvbk4DBfOXwxEibU4jrUZK6ABQ5MWjqvv aVAEZ6WefOQfjzjDo+W+LxwuhL+AkrmfpNhmuO0NK613BtwZ54wSqPRj5TL3lLeOVOAv LfchOw4DelHq1KXx3AdX/y8LY4EeCC6UCpug6f/4HLU4iC6Mf1UgrJCHnw0dz26JWhMl MYicQsiUUVCdd3ADzVvLG4p/bVJfqyeoHjkHjVqfyud9RDGkIhoFu8FHI5HVS1vyKLZc z7RwDo2jk88uj/ORGyn4oZ8uWz9cKbXsRBzJwnpBK6Zu80suxv8pOmtK9HQwlFkUD4iD c+Fg== X-Gm-Message-State: AOJu0YxkwW+cjm5OrEKIvd+TDFTjC+AXl3fs/9/ABWkHAtgH0I8sT8Tp 57NwpTKV0a5sMq9k1CJcklEI/RS+tRiW+NyqgXFq4msijPyCtkw+BMvZC6VA X-Google-Smtp-Source: AGHT+IFgDAzMkle2r7GhsJhqpE4TDF5ZaOBrnpj9f/BIHRJ++O6ofbU6wNkN5HtkYkQmY3akYl/tQg== X-Received: by 2002:a17:90a:f40e:b0:2a2:386e:3921 with SMTP id ch14-20020a17090af40e00b002a2386e3921mr1147402pjb.3.1712194437879; Wed, 03 Apr 2024 18:33:57 -0700 (PDT) Received: from [192.168.1.20] ([50.37.177.113]) by smtp.gmail.com with ESMTPSA id o10-20020a17090ac08a00b0029bb433dc8asm357096pjs.15.2024.04.03.18.33.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Apr 2024 18:33:57 -0700 (PDT) Message-ID: <9a848b89-ee95-44f7-8491-cbe22804edf4@gmail.com> Date: Wed, 3 Apr 2024 18:33:56 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gfortran Cc: gcc-patches From: Jerry D Subject: =?utf-8?q?=5Bpatch=2C_libgfortran=5D_PR114304_-_=5B13/14_Regression?= =?utf-8?q?=5D_libgfortran_I/O_=E2=80=93_bogus_=22Semicolon_not_allowed_as_s?= =?utf-8?q?eparator_with_DECIMAL=3D=27point=27=22?= Autocrypt: addr=jvdelisle2@gmail.com; keydata= xjMEY5TlkxYJKwYBBAHaRw8BAQdAyrkRDhmJhSTTlV/50gJLlvliU6/Lm5C9ViKV8T9y1GnN HkplcnJ5IEQgPGp2ZGVsaXNsZTJAZ21haWwuY29tPsKJBBMWCAAxFiEEOFR0TS0390uh8dRV uWXAJaWpwWoFAmOU5ZMCGwMECwkIBwUVCAkKCwUWAgMBAAAKCRC5ZcAlpanBalsJAP4wdCiH 2Of9oZv1QWgZ/AVdbWFM3Fv47/WZQHOXfoZ9HgD6AkXrKeJ+6usST7PEaDJjptaViT1fLiYY V/6XaOKSsgLOOARjlOWTEgorBgEEAZdVAQUBAQdAdA7PczYnl07vnOT9oP/wvvMDd4HP09Zl g3LzwXQJWT8DAQgHwngEGBYIACAWIQQ4VHRNLTf3S6Hx1FW5ZcAlpanBagUCY5TlkwIbDAAK CRC5ZcAlpanBasF/AQCa5WjlsVpLsEiggZyT18MOJNAdeRd7wkGDUrwedHrvawD/cE1H+/Ms L1ZwvQiLfGdx8crigQqWTQyos4kH8Wx82wc= X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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+patchwork=sourceware.org@gcc.gnu.org Hi all, The attached log entry and patch (git show) fixes this issue by adding logic to handle spaces in eat_separators. One or more spaces by themselves are a valid separator. So in this case we look at the character following the spaces to see if it is a comma or semicolon. If so, I change it to the valid separator for the given decimal mode, point or comma. This allows the comma or semicolon to be interpreted as a null read on the next effective item in the formatted read. I chose a permissive approach here that allows reads to proceed when the input line is mal-formed with an incorrect separator as long as there is at least one space in front of it. New test case included. Regression tested on X86-64. OK for trunk? Backport to 13 after some time. Regards, Jerry commit 7d1a958d6b099ea88b6c51649baf5dbd5e598909 Author: Jerry DeLisle Date: Wed Apr 3 18:07:30 2024 -0700 libfortran: Fix handling of formatted separators. PR libfortran/114304 libgfortran/ChangeLog: * io/list_read.c (eat_separator): Add logic to handle spaces preceding a comma or semicolon such that that a 'null' read occurs without error at the end of comma or semicolon terminated input lines. gcc/testsuite/ChangeLog: * gfortran.dg/pr114304.f90: New test. diff --git a/gcc/testsuite/gfortran.dg/pr114304.f90 b/gcc/testsuite/gfortran.dg/pr114304.f90 new file mode 100644 index 00000000000..57af619246b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr114304.f90 @@ -0,0 +1,49 @@ +! { dg-do run } +! pr114304 +real :: x(3) +character(len=1) :: s +integer :: ios + +s = 'x' + +open(99, decimal="comma", status='scratch') +write(99, '(a)') '1,23435 1243,24 13,24 a' +rewind(99) +read(99, *, iostat=ios) x, s +if (ios /= 0 .or. s /= 'a') stop 1 + +rewind(99) +write(99, '(a)') '1,23435;1243,24;13,24;a' +rewind(99) +read(99, *, iostat=ios) x, s +if (ios /= 0 .or. s /= 'a') stop 2 + +! Note: not reading 's' +rewind(99) +write(99, '(a)') '1,23435 1243,24 13,24 ,' +rewind(99) +read(99, *) x +if (ios /= 0) stop 3 + +rewind(99) +write(99, '(a)') '1,23435;1243,24;13,24 ,' +rewind(99) +read(99, *, iostat=ios) x +if (ios /= 0) stop 4 + +! Now reading 's' +s = 'w' +rewind(99) +write(99, '(a)') '1,23435 1243,24 13,24 ,' +rewind(99) +read(99, *, iostat=ios) x, s +if (ios /= 0 .or. s /= 'w') stop 5 + +s = 'w' +rewind(99) +write(99, '(a)') '1,23435;1243,24;13,24 ,' +rewind(99) +read(99, *, iostat=ios) x, s +if (ios /= 0 .or. s /= 'w') stop 6 +close(99) +end diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c index fb3f7dbc34d..f6f169043bf 100644 --- a/libgfortran/io/list_read.c +++ b/libgfortran/io/list_read.c @@ -461,11 +461,30 @@ eat_separator (st_parameter_dt *dtp) int c, n; int err = 0; - eat_spaces (dtp); dtp->u.p.comma_flag = 0; + c = next_char (dtp); + if (c == ' ') + { + eat_spaces (dtp); + c = next_char (dtp); + if (c == ',') + { + if (dtp->u.p.current_unit->decimal_status == DECIMAL_COMMA) + unget_char (dtp, ';'); + dtp->u.p.comma_flag = 1; + eat_spaces (dtp); + return err; + } + if (c == ';') + { + if (dtp->u.p.current_unit->decimal_status == DECIMAL_POINT) + unget_char (dtp, ','); + dtp->u.p.comma_flag = 1; + eat_spaces (dtp); + return err; + } + } - if ((c = next_char (dtp)) == EOF) - return LIBERROR_END; switch (c) { case ',': @@ -476,7 +495,10 @@ eat_separator (st_parameter_dt *dtp) unget_char (dtp, c); break; } - /* Fall through. */ + dtp->u.p.comma_flag = 1; + eat_spaces (dtp); + break; + case ';': dtp->u.p.comma_flag = 1; eat_spaces (dtp);