From patchwork Sun Jan 29 04:17:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry DeLisle X-Patchwork-Id: 49940 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1605012wrn; Sat, 28 Jan 2023 20:18:23 -0800 (PST) X-Google-Smtp-Source: AK7set+KsysqK0RNPap7xlWOBKZzPqb3uQmlaZW/22bg2sxk3bE/SjfNa7YQDQPMLeYRdtd36c02 X-Received: by 2002:a17:907:c282:b0:878:509f:798c with SMTP id tk2-20020a170907c28200b00878509f798cmr15536457ejc.4.1674965903671; Sat, 28 Jan 2023 20:18:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674965903; cv=none; d=google.com; s=arc-20160816; b=ks/eybW6QzIzPi049bnCwxV2kmvaDbaGuq16oQfq2nfyLXT680Wvaivi3BMWnGqqz9 QNFaYiU+I0nhUEXP1lkd1h3oh/0HTMGy1xX9ev6+1jnWwUBLsN5+shiwpKRbt5QEyH0Y KHE/nHGCG7/eTi8ZrQ3/106taX3OsU67kAK2TicKFBq6S8qZ3pzPMCEjGx+cYEDh2Kbm 99QFdGVbvrn42wj2dORA6qKtU/9b4/GAMTxRsLFVwr9m5Gv/PPVTXUTHVjmKdS9n6OJ+ WFy7EPBwUcA/MSFJqNtaUFqETZ4TsuGS9hwPtoAJaYlni/5+9qHXIsDJ3l9NNeUd2NZT ep/w== 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:mime-version :feedback-id:message-id:subject:cc:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=ITip0ECUziMCcMeElZjO/7Zt8aL+uK0v1h2NlmUpSR0=; b=YLjonKYnkRM4T+hs3iSkmzPIC6dRP07wmv16sKdHkh8EZRgX6RlYIdIVU+Y1n4Hbyq G3+bKKZMK27XMcbQK2TT1GuHp6rKOgwB4QQCkPquFbAxAEfdzcZZh/hh7Vwzig5z6VK+ iRbyal5NgjOM7nm764NsXxfeyYcnjTU59xYI3Vm0iszt4Kjcx4VWYjx0TPYiv5F6DmSG 2ZVyLFKCORheD24i6L/6BiOMsUPBtYFixjmKUDaJ6kRoZM4JTTugA8h0Hauri/i03NHc bo753PK288Zzxifjjx0xmTI85ihQvhz83xIUOhgBpT+2pY5mD7UaEGz86JGRuEpiAhU9 ez0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SFfwksal; 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=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j13-20020a170906104d00b008697a71e4e9si11158951ejj.941.2023.01.28.20.18.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 20:18:23 -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=@gcc.gnu.org header.s=default header.b=SFfwksal; 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=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 778463858C83 for ; Sun, 29 Jan 2023 04:18:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 778463858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674965902; bh=ITip0ECUziMCcMeElZjO/7Zt8aL+uK0v1h2NlmUpSR0=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=SFfwksalZL55KasPwCz1w9o/yb9rupQ+xa64qiAc5Q4bowlDhgTRjErXRGssKLLLw KqFXLISg2tOQwI8xG0JHlzuq41zndLR61ihu8KbVTOsXuFlOuQM0D3rkUTDK5YRewS fMDaMXfl0X33bCb2CKFe7GHGH0d84ZDy1KjUZB3Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by sourceware.org (Postfix) with ESMTPS id 0605C3858D20 for ; Sun, 29 Jan 2023 04:17:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0605C3858D20 Date: Sun, 29 Jan 2023 04:17:30 +0000 To: gfortran Cc: gcc-patches Subject: [patch, fortran] PR103506 [10/11/12/13 Regression] ICE in gfc_free_namespace, at fortran/symbol.c Message-ID: <56d431f3-a8d5-a122-41e6-df472c41b326@protonmail.com> Feedback-ID: 34907122:user:proton MIME-Version: 1.0 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_STOCKGEN, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jerry DeLisle via Gcc-patches From: Jerry DeLisle Reply-To: Jerry DeLisle 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?1756329047608654670?= X-GMAIL-MSGID: =?utf-8?q?1756329047608654670?= Attached patch fixes this problem by allowing the namespace pointer to be set correctly regardless of error condition. Regression tested on x86_64_linux_gnu. OK for trunk and backports? Regards, Jerry Author: Jerry DeLisle Date: Sat Jan 28 20:00:34 2023 -0800 ICE in gfc_free_namespace. ice-on-invalid. PR fortran/103506 gcc/fortran/ChangeLog: * parse.cc (parse_module): Remove use of a bool error value that prevented proper setting of the namespace pointer. gcc/testsuite/ChangeLog: * gfortran.dg/pr103506_1.f90: New test. diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc index 0fb19cc9f0f..039e7e7da53 100644 --- a/gcc/fortran/parse.cc +++ b/gcc/fortran/parse.cc @@ -6502,7 +6502,6 @@ parse_module (void) { gfc_statement st; gfc_gsymbol *s; - bool error; s = gfc_get_gsymbol (gfc_new_block->name, false); if (s->defined || (s->type != GSYM_UNKNOWN && s->type != GSYM_MODULE)) @@ -6525,7 +6524,6 @@ parse_module (void) st = parse_spec (ST_NONE); - error = false; loop: switch (st) { @@ -6544,16 +6542,11 @@ loop: default: gfc_error ("Unexpected %s statement in MODULE at %C", gfc_ascii_statement (st)); - - error = true; reject_statement (); st = next_statement (); goto loop; } - - /* Make sure not to free the namespace twice on error. */ - if (!error) - s->ns = gfc_current_ns; + s->ns = gfc_current_ns; } diff --git a/gcc/testsuite/gfortran.dg/pr103506_1.f90 b/gcc/testsuite/gfortran.dg/pr103506_1.f90 new file mode 100644 index 00000000000..3f57809e099 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr103506_1.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR103506 ICE in gfc_free_namespace. ice-on-invalid +! Test case from the PR. +module m ! { dg-error "is already being used as a MODULE" } +stop ! { dg-error "Unexpected STOP statement in MODULE" } +end +program p +call m ! { dg-error "is already being used as a MODULE" } +end