From patchwork Mon Apr 8 09:53:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 88159 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 AF3C6385829B for ; Mon, 8 Apr 2024 09:54:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id A3E503858408 for ; Mon, 8 Apr 2024 09:53:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A3E503858408 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=baylibre.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A3E503858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712570035; cv=none; b=nbuJUEew7OzJbRLcbNPncS7K2AtvRyKwOl6ajWNx4+dL7EMeD4kgaWUxSm0SHPynBwKy2qrGRA5uVLM50wV8Om0QYiufBxFMVDxugGeSM+eHb27O5zm1KRCPzUxfFesDAKVdy3xJ88cPvX/ZknllCVJacc0zMp995HKkZySe5xU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712570035; c=relaxed/simple; bh=kSeRI8mo/qPGbme/FFgGsl0rFF+L4SCl4FhU4ZsvQ1Y=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=DmBudOfbHPhNKzKqfdfacu7bQm5AqgL5EJqx3nO92Mvia8cVlL8C3lzXZ+XGMkrsAJbYI16e6EOIA5dKqKxomr42LWsylZPrCtT/c7trcz1WP+z5zogeop3piFWtvuUdy5/G5RdNUJkB+QAPzOFvCZzdTL4hIVEaVdn97IdwuNQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-56e449187fcso1767086a12.3 for ; Mon, 08 Apr 2024 02:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1712570031; x=1713174831; darn=gcc.gnu.org; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=A81I6O06Kb9w03x7xklY/rmac/DwiBpRTN9Q4j5D4zE=; b=Vwl4k5D0Le2LlxhA+dntXXlEQoHM2rk2psXOJPguWEOT+E70+aG0y5xoLlJooPRwUd 10g6egRhaH11tsT7ZBJuLBWpcvN3o6te7zlTUWxhzOF0Z/hSqD4+rO3+r+miuj1DL3qN rqxkKbH6TNWApwfZpu1CMGnqrk8ym+4xFVXp5U8a97FSXNjQDNOcGJNFy0jlZxYrgap2 pQoo+rMtYu2qNIBwluxAdGCCq8JLBNNfRqFoVJq2gE/DbZOTalYKAhDF0msfFxTQhoj6 +uYpE6WWYuZZ8pckxlEqwEwjmvh7e09fZ5tzMYRvN7mKsy39tmjoR0ssiWDX8TubM9Zs HnCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712570031; x=1713174831; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=A81I6O06Kb9w03x7xklY/rmac/DwiBpRTN9Q4j5D4zE=; b=F7oBJphJNmicXcMvxj18N0da5O93XAtZ9c3Is5oFpXkPEuQEoQtkiUMcpLxiTU8a1L vVV6KjlFYyniOuq3v2PsgXVYGtKNtOgdc9v0NlxPqA2yRe6u5UDldJd0nJ+9+7tsOAut dyaI62mNS1nn2iqFhDN79rZRqGnOXbJ2P+tai1BoDETLGBGDSkWPHQo68S4FYu1kaF0T 8Dzt2NUq1DjmBH5xdM+VijFtbDzV455iZ4nRacKKOmPQtKWpUBIjdXNE1yB3HIZ8tkTi fKsrbg9D8UvTaWx35+51XguXzPwMf+y5Vk585IRZ3SFmPnxb6Qu3Of5ZPtPOVT6akS3n 6csQ== X-Gm-Message-State: AOJu0YwCP9GdPs5BeaIo4bMUwbpezbVRsYZwuBIMYzVO0IL7GpOIEFMt xvC/m0GYC3N0Sf+BOkD+LWzLm7WY8DUWsXZMv18pBsNWYAzzblYG9V3j1JD828I= X-Google-Smtp-Source: AGHT+IF7QZmdnd2K0vkmgJumngvod4dqiuWbzMF1FeY+tklgn0hfxyI+JfVFfdiqS/mCIjMnuZmbpg== X-Received: by 2002:a17:907:7d90:b0:a51:cdfd:9095 with SMTP id oz16-20020a1709077d9000b00a51cdfd9095mr2761435ejc.57.1712570031204; Mon, 08 Apr 2024 02:53:51 -0700 (PDT) Received: from ?IPV6:2001:16b8:2a21:dd00:9a6e:8a9a:eb5:f51b? (200116b82a21dd009a6e8a9a0eb5f51b.dip.versatel-1u1.de. [2001:16b8:2a21:dd00:9a6e:8a9a:eb5:f51b]) by smtp.gmail.com with ESMTPSA id en1-20020a17090728c100b00a51adace6ebsm3630541ejc.79.2024.04.08.02.53.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Apr 2024 02:53:49 -0700 (PDT) Message-ID: <529f47ca-c398-4e20-a0ef-507842f989d4@baylibre.com> Date: Mon, 8 Apr 2024 11:53:48 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: =?utf-8?q?=5BPatch=5D_Fortran=3A_List-directed_read_-_accept_again_?= =?utf-8?q?tab_as_alternative_to_space_as_separator_=5BPR114304=5D_=28was=3A?= =?utf-8?q?_=5Bpatch=2C_libgfortran=5D_PR114304_-_=5B13/14_Regression=5D_lib?= =?utf-8?q?gfortran_I/O_=E2=80=93_bogus_=22Semicolon_not_allowed_as_separato?= =?utf-8?q?r_with_DECIMAL=3D=27point=27=22=29?= To: Jerry D , gfortran Cc: gcc-patches References: <9a848b89-ee95-44f7-8491-cbe22804edf4@gmail.com> <15a39ada-c7fc-433d-ab39-19b897a8a3e8@baylibre.com> <6a742cef-5321-4b34-a2f0-870abd1ba82a@gmail.com> Content-Language: en-US From: Tobias Burnus In-Reply-To: X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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 Jerry D wrote: > See attached updated patch. It turned rather quickly out that this patch – committed as r14-9822-g93adf88cc6744a – caused regressions. Namely, real-world code use tab(s) as separator instead of spaces. [For instance, PR114304 which contains a named-list input file from SPEC CPU 2017; that example uses tabs before the '=' sign, but the issue is more generic.] I think the ISO Fortran standard only permits spaces, but as it feels natural and is widely supported, tabs are used and should remain supported. It is not quite clear how '\r' are or should be handled, but as eat_spaces did use it, I thought I would add one testcase using them as well. That test is not affected by my change; it did work before with GCC and still does – but it does fail with ifort/ifx/flang. I have not thought deeply whether it should be supported or not – and looking at the libgfortran source file, it often but (→ testcase) not consistently requires that an \n follows the \r. OK for mainline? [And: When the previous patch gets backported, this surely needs to be included as well.] Tobias Fortran: Accept again tab as alternative to space as separator [PR114304] This fixes a side-effect of/regression caused by r14-9822-g93adf88cc6744a, which was for the same PR. PR libfortran/114304 libgfortran/ChangeLog: * io/list_read.c (eat_separator): Accept tab as alternative to space. gcc/testsuite/ChangeLog: * gfortran.dg/pr114304-2.f90: New test. gcc/testsuite/gfortran.dg/pr114304-2.f90 | 82 ++++++++++++++++++++++++++++++++ libgfortran/io/list_read.c | 2 +- 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gfortran.dg/pr114304-2.f90 b/gcc/testsuite/gfortran.dg/pr114304-2.f90 new file mode 100644 index 00000000000..5ef5874f528 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr114304-2.f90 @@ -0,0 +1,82 @@ +! { dg-do run } +! +! PR fortran/114304 +! +! Ensure that '\t' (tab) is supported as separator in list-directed input +! While not really standard conform, this is widely used in user input and +! widely supported. +! + +use iso_c_binding +implicit none +character(len=*,kind=c_char), parameter :: tab = C_HORIZONTAL_TAB + +! Accept '' as variant to ' ' as separator +! Check that and are handled + +character(len=*,kind=c_char), parameter :: nml_str & + = '&inparm'//C_CARRIAGE_RETURN // C_NEW_LINE // & + 'first'//tab//'='//tab//' .true.'// C_NEW_LINE // & + ' , other'//tab//' ='//tab//'3'//tab//', 2'//tab//'/' + +! Check that is handled, + +! Note: For new line, Unix uses \n, Windows \r\n but old Apple systems used '\r' +! +! Gfortran does not seem to support all \r, but the following is supported +! since ages, ! which seems to be a gfortran extension as ifort and flang don't like it. + +character(len=*,kind=c_char), parameter :: nml_str2 & + = '&inparm'//C_CARRIAGE_RETURN // C_NEW_LINE // & + 'first'//C_NEW_LINE//'='//tab//' .true.'// C_CARRIAGE_RETURN // & + ' , other'//tab//' ='//tab//'3'//tab//', 2'//tab//'/' + +character(len=*,kind=c_char), parameter :: str & + = tab//'1'//tab//'2,'//tab//'3'//tab//',4'//tab//','//tab//'5'//tab//'/' +character(len=*,kind=c_char), parameter :: str2 & + = tab//'1'//tab//'2;'//tab//'3'//tab//';4'//tab//';'//tab//'5'//tab//'/' +logical :: first +integer :: other(4) +integer :: ints(6) +namelist /inparm/ first , other + +other = 1 + +open(99, file="test.inp") +write(99, '(a)') nml_str +rewind(99) +read(99,nml=inparm) +close(99, status="delete") + +if (.not.first .or. any (other /= [3,2,1,1])) stop 1 + +other = 9 + +open(99, file="test.inp") +write(99, '(a)') nml_str2 +rewind(99) +read(99,nml=inparm) +close(99, status="delete") + +if (.not.first .or. any (other /= [3,2,9,9])) stop 2 + +ints = 66 + +open(99, file="test.inp", decimal='point') +write(99, '(a)') str +rewind(99) +read(99,*) ints +close(99, status="delete") + +if (any (ints /= [1,2,3,4,5,66])) stop 3 + +ints = 77 + +open(99, file="test.inp", decimal='comma') +write(99, '(a)') str2 +rewind(99) +read(99,*) ints +close(99, status="delete") + +if (any (ints /= [1,2,3,4,5,77])) stop 4 +end diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c index b56f2a4e6d6..5bbbef26c26 100644 --- a/libgfortran/io/list_read.c +++ b/libgfortran/io/list_read.c @@ -463,7 +463,7 @@ eat_separator (st_parameter_dt *dtp) dtp->u.p.comma_flag = 0; c = next_char (dtp); - if (c == ' ') + if (c == ' ' || c == '\t') { eat_spaces (dtp); c = next_char (dtp);