From patchwork Sat Nov 11 10:15:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Richard Thomas X-Patchwork-Id: 164110 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp150214vqg; Sat, 11 Nov 2023 02:16:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6JgaQX6yM4hgz3ZFi6TU6Os44DHRqp8IbAguIhMgqIxvZQNvpRPZ6EzUPiLWCx0BYIgf9 X-Received: by 2002:a0d:ca11:0:b0:5a7:aa7b:cb9f with SMTP id m17-20020a0dca11000000b005a7aa7bcb9fmr1883352ywd.14.1699697796156; Sat, 11 Nov 2023 02:16:36 -0800 (PST) Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b5-20020a0cfb45000000b00670b0ffe6fasi1211494qvq.492.2023.11.11.02.16.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Nov 2023 02:16:36 -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=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=cX8C9aYg; arc=fail (body hash mismatch); 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E0D713858C01 for ; Sat, 11 Nov 2023 10:16:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 5435E3858D35; Sat, 11 Nov 2023 10:15:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5435E3858D35 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 5435E3858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699697761; cv=none; b=NLt9vVteC7axe5PvCg2zOen9obwLF9I3nJzdMzY/qjbvMEz3XHZngJgWg9IY+8W7T7qVMlqjnly8v8V2TyFozBz6DAB6z6RxkzWh4RU3k3gTKhuwGOGFeksFXOFlyZeyYwAK7iSNE6qJZ8D67/IH8if22IevTC0ZTUZ6cpkm82U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699697761; c=relaxed/simple; bh=CYRRX9geHyRqXFUHcMZAgKVfQap/XodeVPb9mnW+oiI=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=vDhs2ECw590AyPq1xQfcL2keET0GLe9NHEkh8Gi2ouZh4OZcodYZ7seK62ZgrjzKPg/v0uJISsUQ13crsv0Ld9ukYM7LHg+me8LKW4i1gT8YIczwguuQqoWh3ty83SHzQNLSNixXIbTfVz6WJqq+rUxv7Gjh8Sg7ldEyQt8QXZA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-692c02adeefso2642573b3a.3; Sat, 11 Nov 2023 02:15:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699697757; x=1700302557; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=1zAD78TACrgf3iuq+GDUXShypl9hJj+BYtzMxZiNdKU=; b=cX8C9aYgiiwH8q9A0I6nvi0otx0Kdy0pAUEJjgGb70Bq67FtmXZuDdeRZGEHlsKnXc VY5ApAwk8aAcqpK+PYQHgBYbUdHeS7mEQz9vLvHZDE5PmHLWAWhMw/fJroDMTW+EGtt2 2GneKc0O54CMWdKUvbZ2IHHDjskw1c5WCsgUZm2zNk1Bxq0rxCW9U3A1juJSMB/+APSS wb60NuHeaU0di2MoDqU4ijH2ThQ+CIUM4uGbBldTFE1/KjIzRRm6YqgW+CSUyPe4xB/d k5cQwuQ+0xwlhL+q7vzCgy629FplPlWj4DF95BCpbn3mW2jPblme1y+Qw7cxrP+HKHxk adLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699697757; x=1700302557; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1zAD78TACrgf3iuq+GDUXShypl9hJj+BYtzMxZiNdKU=; b=Qzn1zHsAtzoQx7+TfnqIbDxAX6PeDh3sZDOuUEjMXEDR1sUP+cymKbrVF302pNQHmY DxbqTlmgJkfca9jVLmZvO0t6HN4lX78B4g+KoMxJRtyncnkQyBsjxi7XFrADMewuXxGg 1pECNPIftdnZIdUwlwCxlF1/u0Bw2mAsPMbL187aX05WiQ6SWR9wvrVkS+razlQxjmHp Xj75PM5A+M1yrFXCGw5ApR2cVsQ6Mf9NC14xozs2FRgjnhCnaxhYlZHfnReDOGav+Q1x vRO8bvqFb/nESpcvEYBDLl2MMz+5LpFLMkImF6ySBE4mM6ykeBVkCClBQ08oytZWdee1 Geow== X-Gm-Message-State: AOJu0Yy/0DAAMCuZIjfmqSv+xq7fnY3Fh+8W9EBY72JVmfiOSYQBmWDW 4VhKZo+qrMJ/Pg+rJgMl7EhPAcBQcWdr62RBNt5d5Ogh9HU= X-Received: by 2002:a05:6a21:19d:b0:15a:bf8:7dfc with SMTP id le29-20020a056a21019d00b0015a0bf87dfcmr1276411pzb.15.1699697757393; Sat, 11 Nov 2023 02:15:57 -0800 (PST) MIME-Version: 1.0 From: Paul Richard Thomas Date: Sat, 11 Nov 2023 10:15:45 +0000 Message-ID: Subject: [Patch, fortran] PR112459 - gfortran -w option causes derived-type finalization at creation time To: "fortran@gcc.gnu.org" , gcc-patches X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, 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.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: 1782262316553665779 X-GMAIL-MSGID: 1782262316553665779 Hi All, Evidently -w causes gfc_option.allow_std to be set to default, which allows anything and everything to happen, including these f2003/8 finalizations. The fix is trivial. Regtests fine - OK for mainline and -13 branch? Paul Fortran: Prevent unwanted finalization with -w option [PR112459] 2023-11-11 Paul Thomas gcc/fortran PR fortran/112459 * trans-array.cc (gfc_trans_array_constructor_value): Replace gfc_notification_std with explicit logical expression that selects F2003/2008 and excludes -std=default/gnu. *trans-array.cc (gfc_conv_expr): Ditto. gcc/testsuite/ PR fortran/112459 * gfortran.dg/pr112459.f90: New test. diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index bbb81f40aa9..ef54a20dafd 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -2311,7 +2311,9 @@ gfc_trans_array_constructor_value (stmtblock_t * pblock, Corrigenda 1 TO 4 for fortran 2008 (f08/0011). Transmit finalization of this constructor through 'finalblock'. */ - if (!gfc_notification_std (GFC_STD_F2018_DEL) && finalblock != NULL + if ((gfc_option.allow_std & (GFC_STD_F2008 | GFC_STD_F2003)) + && !(gfc_option.allow_std & GFC_STD_GNU) + && finalblock != NULL && gfc_may_be_finalized (ts) && ctr > 0 && desc != NULL_TREE && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc))) diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 1b8be081a17..a69d7c7114d 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -9698,7 +9698,9 @@ gfc_conv_expr (gfc_se * se, gfc_expr * expr) executable construct containing the reference. This, in fact, was later deleted by the Combined Techical Corrigenda 1 TO 4 for fortran 2008 (f08/0011). */ - if (!gfc_notification_std (GFC_STD_F2018_DEL) && expr->must_finalize + if ((gfc_option.allow_std & (GFC_STD_F2008 | GFC_STD_F2003)) + && !(gfc_option.allow_std & GFC_STD_GNU) + && expr->must_finalize && gfc_may_be_finalized (expr->ts)) { gfc_warning (0, "The structure constructor at %C has been"