From patchwork Sun Apr 28 21:37:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Richard Thomas X-Patchwork-Id: 1928700 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=MXYR+8wH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VSKZC2TQyz1ymX for ; Mon, 29 Apr 2024 07:37:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5CE7A3858420 for ; Sun, 28 Apr 2024 21:37:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id E74FE3858D35; Sun, 28 Apr 2024 21:37:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E74FE3858D35 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 E74FE3858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714340250; cv=none; b=NaOBe5XfG2VATBdswy3JcsMroQSYE3ZKybOUoOUHKzYd7X94DiOJ5sJgb9HJrhntC0Jr6LQDEtr1k7XMjlejPnH/7f5mIAlXMJj2R79dS5I2qowPk9oecj+fFh3ZFBBQXA+dLJ2Wm1ycsK8y0QPADMUxATYRd+Nr8A57nQIvVqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714340250; c=relaxed/simple; bh=U1LL5CWPxXzn9iraiyZnvLaYiVo/WdZzXdMLu3Ztgb8=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=KMM01tyCHnraWvgj9NMTIZ8lUvAQwr328yjIkdSvng3oaRv6bSHlLazR6lJarVfxVHLSEnUiDR31mZWooD8Ok4TDAO1BLLqTDa++8iuGsHH4HLGiS1YF1QmYofp2Hyft7wbYwgN1W+9IhaxQXWuo/PeI3WnpARDiR60FlweSz3Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2a559928f46so2547258a91.0; Sun, 28 Apr 2024 14:37:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714340238; x=1714945038; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=S75h/FykE0olPn3YK3w8TsOZbOIUV2VjYz5COfXF1DU=; b=MXYR+8wHxBQlzFE8Ioz6Tskdk/y8rLsytpao7UJ6SuB8ygxddQT3jlVwXiLxNvQv3k Nr9kBPQQYCSVPH2DkrMSksRspryDInRa9iG2TAyBSGK/NvlzxfTIGHmzqpR/BKqanY8V zpXaO8ZPr7QN4NQwNC1rY9n3foojzRwngDbC3OsF4hp/ExYG5+w6eyb10vC7CTQ462Vh sDe4SOQib6qFFaQyEQcdzQfbvnQs7gUsewQXYd6qHXgt90P37yzHERKOJR5qXpzefnlH gF7iWcLOevqsUuh54ryhvbBGYDcBLVjNb2yAKZkPSB4r7yf89Mj30u1dXCM7o9og4kgu 0awA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714340238; x=1714945038; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=S75h/FykE0olPn3YK3w8TsOZbOIUV2VjYz5COfXF1DU=; b=Cfo/70vd1wRQ5fqaynlexUf98Xx22C674amDFAk2PY2xbSKvA4mDfXpHAN008z48lO QQf1xuiuNh/IurOCoN/+EnWXyuy3vCsfMPNSFUbNdq0HgE+uHw0MjTovp+D5VNo842+M kbIviIdnNxeTfSrzzwgeXHvg3+vHr0AlFSxoUEsuruwMyStqwg3aU9d/SyMeVMNHgdyS u1QZv5N/anTel3hGRYlHA2FEgoJf3xl6wGeZGt5y+3GDbBq52fWL9n8HdXfxJSAWBwcV jr9kiYuGqHrG5t16YpiiVRxNewJos+s1CA5BVCd49Sg0Ex2NYpz1PK0OTEcJy19F55+3 VZHA== X-Forwarded-Encrypted: i=1; AJvYcCWPrDoGC7yOFddlRNPlHIY2WiI1IoatSzlv0qos7JC0bXoAixNvkU/818t43zjj+EqHr9nXSj9KJ1XZcRGh0Indn6pZCiUWJw== X-Gm-Message-State: AOJu0YxPo4qrlfIk1WCBgADK9UEpBc1XjSueMH4r1andzFBUATO6faMZ VCvgg1c43I0WwnZxyFjJ7SsBbKgjaUbEHoKDteY+c8VHAZDti3778muGuuFCkvjqg1OsviLg2FL c8Lz23o4Qv96M/Skso9D/JCWFMWQyx+XL X-Google-Smtp-Source: AGHT+IEcxD87Vx3ETnmOhp3HeU1RpdwG4XWYF4etUuLf7rukXn1lnxfNG2iz595nbWFcNT2py8TEcfQjWS7aCnNAK/M= X-Received: by 2002:a17:90a:d152:b0:2b1:1c9d:fa8d with SMTP id t18-20020a17090ad15200b002b11c9dfa8dmr2915114pjw.28.1714340238296; Sun, 28 Apr 2024 14:37:18 -0700 (PDT) MIME-Version: 1.0 From: Paul Richard Thomas Date: Sun, 28 Apr 2024 22:37:06 +0100 Message-ID: Subject: [Patch, fortran] PR114859 - [14/15 Regression] Seeing new segmentation fault in same_type_as since r14-9752 To: "fortran@gcc.gnu.org" , gcc-patches X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, KAM_NUMSUBJECT, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi All, Could this be looked at quickly? The timing of this regression is more than a little embarrassing on the eve of the 14.1 release. The testcase and the comment in gfc_trans_class_init_assign explain what this problem is all about and how the patch fixes it. OK for 15-branch and backporting to 14-branch (hopefully to the RC as well)? Paul Fortran: Fix regression caused by r14-9752 [PR114959] 2024-04-28 Paul Thomas gcc/fortran PR fortran/114959 * trans-expr.cc (gfc_trans_class_init_assign): Return NULL_TREE if the default initializer has all NULL fields. Guard this by a requirement that the code be EXEC_INIT_ASSIGN and that the object be an INTENT_IN dummy. * trans-stmt.cc (gfc_trans_allocate): Change the initializer code for allocate with mold to EXEC_ASSIGN to allow initializer with all NULL fields.. gcc/testsuite/ PR fortran/114959 * gfortran.dg/pr114959.f90: New test. diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 072adf3fe77..0280c441ced 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -1720,6 +1720,7 @@ gfc_trans_class_init_assign (gfc_code *code) gfc_se dst,src,memsz; gfc_expr *lhs, *rhs, *sz; gfc_component *cmp; + gfc_symbol *sym; gfc_start_block (&block); @@ -1736,18 +1737,25 @@ gfc_trans_class_init_assign (gfc_code *code) /* The _def_init is always scalar. */ rhs->rank = 0; - /* Check def_init for initializers. If this is a dummy with all default - initializer components NULL, return NULL_TREE and use the passed value as - required by F2018(8.5.10). */ - if (!lhs->ref && lhs->symtree->n.sym->attr.dummy) + /* Check def_init for initializers. If this is an INTENT(OUT) dummy with all + default initializer components NULL, return NULL_TREE and use the passed + value as required by F2018(8.5.10). */ + sym = code->expr1->expr_type == EXPR_VARIABLE ? code->expr1->symtree->n.sym + : NULL; + if (code->op != EXEC_ALLOCATE + && sym && sym->attr.dummy + && sym->attr.intent == INTENT_OUT) { - cmp = rhs->ref->next->u.c.component->ts.u.derived->components; - for (; cmp; cmp = cmp->next) + if (!lhs->ref && lhs->symtree->n.sym->attr.dummy) { - if (cmp->initializer) - break; - else if (!cmp->next) - return build_empty_stmt (input_location); + cmp = rhs->ref->next->u.c.component->ts.u.derived->components; + for (; cmp; cmp = cmp->next) + { + if (cmp->initializer) + break; + else if (!cmp->next) + return NULL_TREE; + } } } diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc index c34e0b4c0cd..d355009fa5e 100644 --- a/gcc/fortran/trans-stmt.cc +++ b/gcc/fortran/trans-stmt.cc @@ -7262,11 +7262,12 @@ gfc_trans_allocate (gfc_code * code, gfc_omp_namelist *omp_allocate) { /* Use class_init_assign to initialize expr. */ gfc_code *ini; - ini = gfc_get_code (EXEC_INIT_ASSIGN); + ini = gfc_get_code (EXEC_ALLOCATE); ini->expr1 = gfc_find_and_cut_at_last_class_ref (expr, true); tmp = gfc_trans_class_init_assign (ini); gfc_free_statements (ini); - gfc_add_expr_to_block (&block, tmp); + if (tmp != NULL_TREE) + gfc_add_expr_to_block (&block, tmp); } else if ((init_expr = allocate_get_initializer (code, expr))) { diff --git a/gcc/testsuite/gfortran.dg/pr114959.f90 b/gcc/testsuite/gfortran.dg/pr114959.f90 new file mode 100644 index 00000000000..5cc3c052c1d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr114959.f90 @@ -0,0 +1,33 @@ +! { dg-do compile } +! { dg-options "-fdump-tree-original" } +! +! Fix the regression caused by r14-9752 (fix for PR112407) +! Contributed by Orion Poplawski +! Problem isolated by Jakub Jelinek and further +! reduced here. +! +module m + type :: smoother_type + integer :: i + end type + type :: onelev_type + class(smoother_type), allocatable :: sm + class(smoother_type), allocatable :: sm2a + end type +contains + subroutine save_smoothers(level,save1, save2) + Implicit None + type(onelev_type), intent(inout) :: level + class(smoother_type), allocatable , intent(inout) :: save1, save2 + integer(4) :: info + + info = 0 +! r14-9752 causes the 'stat' declaration from the first ALLOCATE statement +! to disappear, which triggers an ICE in gimplify_var_or_parm_decl. The +! second ALLOCATE statement has to be present for the ICE to occur. + allocate(save1, mold=level%sm,stat=info) + allocate(save2, mold=level%sm2a,stat=info) + end subroutine save_smoothers +end module m +! Two 'stat's from the allocate statements and two from the final wrapper. +! { dg-final { scan-tree-dump-times "integer\\(kind..\\) stat" 4 "original" } }