From patchwork Sat Jul 8 14:23:31 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: 117440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp3953794vqx; Sat, 8 Jul 2023 07:24:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlFbpt0k7IE6XMEAwqicCuJ01GekZMcS34N1iqTYRG4BSU9/ALvcceGNIQFMR2vKslnEph2d X-Received: by 2002:a19:2d0c:0:b0:4f9:6581:8b4c with SMTP id k12-20020a192d0c000000b004f965818b4cmr5397254lfj.44.1688826274556; Sat, 08 Jul 2023 07:24:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688826274; cv=none; d=google.com; s=arc-20160816; b=RteRaGR4TEy/uco/Lm1puCVy51Aa+T8//IFJcSvcqG3ypJEweAt8lwdsVb8Dm81wvF AKEmZ0ymBRI3EBMg1vreL/cy7LkxZTHKOLhXn44b+hsKYz1LdvF4I6oLQ6yliOsxjngm 7vlzSbZHJZjGeP5Q1azBKIv+66lyqY04wXqZWp+voJAwE5BtQ3/oS+5Goc3IBiAMI8nD gcdL/Xl0z5GejxMOvLpOM18iqPUgIPTo3bjn+0LuxhJ5quzh2BC05LHTgZL+Onh0e0z0 u3fa5laPcftX6RQuufttWz7udth60vVax4K8/JzLnCeCGJffju4NPsP6NiDjVioPT+VV DrmQ== 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:cc:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=UApFTYnxWybHYY8bDY3Lzlck805czFindpRhaek7vgo=; fh=GsmimM5Gbyr/9Pu67Ts725bGe9DnqIf/O/8h39Cej3o=; b=pH3rAendRXXarC/GO/MzadXX8pW1SMr16o62Ccfn3EuEpQZgnG+9UPc4xY5zWJ/PVt pv5oIKInZw5tYXTvTwVCHkyVOd9/oHa2bWvikpHmo62PpnWWXiJY8UfpLdT86htZ+OLj S0nMDf4nb5V6EQ/MUfIBMh6HpW9NyVXOIYWHIni7juX9gRgTxey/Xr+xXXcd2RyZAW3D HrU95Yo1choIXKTA4S77ADzTmH/HN313owM1BMSDePuiC446fBch1Vjh3fX6NJOklxRl XKR+f8fO68kuNLb354l1+32DxyYv3mxibYUAbqL9KyLF0dLecGyNMzL4PA5hKmTeZlW7 CujA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pAnkv9Oo; 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g18-20020a056402181200b0051de2ee33f7si3004138edy.514.2023.07.08.07.24.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jul 2023 07:24:34 -0700 (PDT) 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=pAnkv9Oo; 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 DCBEF385AFA5 for ; Sat, 8 Jul 2023 14:24:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DCBEF385AFA5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688826267; bh=UApFTYnxWybHYY8bDY3Lzlck805czFindpRhaek7vgo=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=pAnkv9OonuJkNG7BuY9iYQPJDSNLj7xYX2XFcuheBuEGYg1xy+1YhcvUIb0In/LGz MeUGgX1dNt288Rh+L2CPauAEAsVSUn9vgyuowGad52AQ2Swkknj+ORdMm0qhx/g+2H 9ydi1ayo+rkszGA2FVAusqhXg3pIKxKwg7dASKJw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by sourceware.org (Postfix) with ESMTPS id 165923857707; Sat, 8 Jul 2023 14:23:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 165923857707 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-263036d4bc3so2108895a91.2; Sat, 08 Jul 2023 07:23:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688826222; x=1691418222; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=UApFTYnxWybHYY8bDY3Lzlck805czFindpRhaek7vgo=; b=XTnblaPNwfoRHzQ5s3jHEJeUy6QtPsxGy+7xO8YEpf0eWfW+ziidgB+P1qk28FqkRg 4uqQOvuBZJ8XP/VYblYDV2y5+l6grXVYE2nzAkACdQ4GAsHcXzAmynushQXNFlcJ622h rLXvvW89kHWGNJGOzcCIVzJUnwMtHbWlcoN9GujQoGNMoEzFvUZFJfcTYTn7dzn1TcxK zHJiN/0jQ7O5rIOooNFFv5Sx1Ke/xWpWYtsRxGku4R6ehNrirkTrfrsdsj/PjYH5zhnp XCH+2EjZdJKKbECk1spn6YPw48yZ/XrbrhMh/0exQkIL0hDmCHsieXd5xTU6YrPlRA9Z XZEg== X-Gm-Message-State: ABy/qLajjaINz9EpydM/rNbi+MMaBdQpV41bh1Bute4QW+2z3J9KulQH gpkWG80RdCRUXDoZnEvxqUSnlGNTBobHsu0K2Z0qgGc4QcE= X-Received: by 2002:a17:90a:bd0d:b0:263:ff36:3aa0 with SMTP id y13-20020a17090abd0d00b00263ff363aa0mr7811365pjr.41.1688826222243; Sat, 08 Jul 2023 07:23:42 -0700 (PDT) MIME-Version: 1.0 Date: Sat, 8 Jul 2023 15:23:31 +0100 Message-ID: Subject: [Patch, fortran] Fix default type bugs in gfortran [PR99139, PR99368] To: "fortran@gcc.gnu.org" , gcc-patches Cc: Steve Kargl X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Paul Richard Thomas via Gcc-patches From: Paul Richard Thomas Reply-To: Paul Richard Thomas 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?1770862699610353901?= X-GMAIL-MSGID: =?utf-8?q?1770862699610353901?= The attached patch incorporates two of Steve's "Orphaned Patches" - https://gcc.gnu.org/pipermail/fortran/2023-June/059423.html They have in common that they both involve faults in use of default type and that I was the ultimate cause of the bugs. The patch regtests with the attached testcases. I will commit in the next 24 hours unless there are any objections. Paul Fortran: Fix default type bugs in gfortran [PR99139, PR99368] 2023-07-08 Steve Kargl gcc/fortran PR fortran/99139 PR fortran/99368 * match.cc (gfc_match_namelist): Check for host associated or defined types before applying default type. (gfc_match_select_rank): Apply default type to selector of unlnown type if possible. * resolve.cc (resolve_fl_variable): Do not apply local default initialization to assumed rank entities. gcc/testsuite/ PR fortran/999139 * gfortran.dg/pr99139.f90 : New test PR fortran/99368 * gfortran.dg/pr99368.f90 : New test Fortran: Fix default type bugs in gfortran [PR99139, PR99368] 2023-07-08 Steve Kargl gcc/fortran PR fortran/99139 PR fortran/99368 * match.cc (gfc_match_namelist): Check for host associated or defined types before applying default type. (gfc_match_select_rank): Apply default type to selector of unlnown type if possible. * resolve.cc (resolve_fl_variable): Do not apply local default initialization to assumed rank entities. gcc/testsuite/ PR fortran/999139 * gfortran.dg/pr99139.f90 : New test PR fortran/99368 * gfortran.dg/pr99368.f90 : New test diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc index ca64e59029e..a778bae0b9f 100644 --- a/gcc/fortran/match.cc +++ b/gcc/fortran/match.cc @@ -5622,10 +5622,32 @@ gfc_match_namelist (void) gfc_error_check (); } else - /* If the type is not set already, we set it here to the - implicit default type. It is not allowed to set it - later to any other type. */ - gfc_set_default_type (sym, 0, gfc_current_ns); + { + /* Before the symbol is given an implicit type, check to + see if the symbol is already available in the namespace, + possibly through host association. Importantly, the + symbol may be a user defined type. */ + + gfc_symbol *tmp; + + gfc_find_symbol (sym->name, NULL, 1, &tmp); + if (tmp + && tmp->attr.generic + && (tmp = gfc_find_dt_in_generic (tmp))) + { + if (tmp->attr.flavor == FL_DERIVED) + { + gfc_error ("Derived type %qs at %L conflicts with " + "namelist object %qs at %C", + tmp->name, &tmp->declared_at, sym->name); + goto error; + } + } + + /* Set type of the symbol to its implicit default type. It is + not allowed to set it later to any other type. */ + gfc_set_default_type (sym, 0, gfc_current_ns); + } } if (sym->attr.in_namelist == 0 && !gfc_add_in_namelist (&sym->attr, sym->name, NULL)) @@ -6805,8 +6827,20 @@ gfc_match_select_rank (void) gfc_current_ns = gfc_build_block_ns (ns); m = gfc_match (" %n => %e", name, &expr2); + if (m == MATCH_YES) { + /* If expr2 corresponds to an implicitly typed variable, then the + actual type of the variable may not have been set. Set it here. */ + if (!gfc_current_ns->seen_implicit_none + && expr2->expr_type == EXPR_VARIABLE + && expr2->ts.type == BT_UNKNOWN + && expr2->symtree && expr2->symtree->n.sym) + { + gfc_set_default_type (expr2->symtree->n.sym, 0, gfc_current_ns); + expr2->ts.type = expr2->symtree->n.sym->ts.type; + } + expr1 = gfc_get_expr (); expr1->expr_type = EXPR_VARIABLE; expr1->where = expr2->where; diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 8e018b6e7e8..f7cfdfc133f 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -13510,7 +13510,8 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag) } } - if (sym->value == NULL && sym->attr.referenced) + if (sym->value == NULL && sym->attr.referenced + && !(sym->as && sym->as->type == AS_ASSUMED_RANK)) apply_default_init_local (sym); /* Try to apply a default initialization. */ /* Determine if the symbol may not have an initializer. */