From patchwork Sun Feb 24 13:54:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 1047502 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-496953-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=netcologne.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LaI9YbNk"; dkim=pass (2048-bit key; unprotected) header.d=netcologne.de header.i=@netcologne.de header.b="DVWvthb4"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 446mm15fSbz9s9T for ; Mon, 25 Feb 2019 00:54:37 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=Lg6OXiEpZJ5ILjTRVataHFd3c38dB5i6aSDty1rSKW8PjlcEs9PRl JQsLrt4HW3YKkrKEHL4KkQai3YEUKL2nIqbl13CA3dYyYSWJghtSRxxUhqI9Nh0d LRxIZ5zFhnbYlV9DAHGdXcyT2TN25YPjSiynXFm6cgnByuGF4ONtNw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=pqpmPziRKQBrNZW4P2Ku1uRTfrE=; b=LaI9YbNkn71ce0yHZuBc 2kifMODVwRtpuVulUePo8rWQfKzBDAnfZyC2ykT0QckYm/Q8QMrunzjTmwlWVneU ajoErmLREBENJdHJ0cRfMGDu5mapeUHDty+pAhxsGD4pcLXOlItEbXONgJk/T8u9 af2PG9/LLOwfPuxhqBKItb4= Received: (qmail 109363 invoked by alias); 24 Feb 2019 13:54:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 109342 invoked by uid 89); 24 Feb 2019 13:54:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: cc-smtpout1.netcologne.de Received: from cc-smtpout1.netcologne.de (HELO cc-smtpout1.netcologne.de) (89.1.8.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 24 Feb 2019 13:54:22 +0000 Received: from cc-smtpin3.netcologne.de (cc-smtpin3.netcologne.de [89.1.8.203]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id 1655312E6C; Sun, 24 Feb 2019 14:54:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=netcologne.de; s=nc1116a; t=1551016459; bh=3lmNIIQs+m6f6mAXfOvGjTZ12oj6YFrk4IIkNTeKrSo=; h=From:Subject:To:Message-ID:Date:From; b=DVWvthb4ECG3IS8y5wyyDdKVeFXSdtHeXwwZtJXiEdLsa4ToBFL/xiznNTZWklOhZ c2BTwUTzd+Yju/8k6YuPAschWIxn99A3MDJa063RyQb1Vu5JaNUoSpICP4HVOXFgb7 aQ1fhfHpVLqpBCPTG8gyd8bCc6YzHDSwoapNXbCq19yGIasleOGC9ncPpjzdSI89// TdAOMlnASzWzAeAbW/bPc9EOV90Llm7bZbwkBLtGIBVhjPfQH3sjGOEFZP2gCeBFfG noR4ajABUSTHTA0lYHqId/KFJgHO3weGLvk03FhBuYwkztY178KA7L92XPgCq3dcHr CnhAMxEPm9ICw== Received: from localhost (localhost [127.0.0.1]) by cc-smtpin3.netcologne.de (Postfix) with ESMTP id 0879411EE8; Sun, 24 Feb 2019 14:54:19 +0100 (CET) Received: from [2001:4dd6:12f5:0:7285:c2ff:fe6c:992d] (helo=cc-smtpin3.netcologne.de) by localhost with ESMTP (eXpurgate 4.6.0) (envelope-from ) id 5c72a20b-0bea-7f0000012729-7f0000019e06-1 for ; Sun, 24 Feb 2019 14:54:19 +0100 Received: from [IPv6:2001:4dd6:12f5:0:7285:c2ff:fe6c:992d] (2001-4dd6-12f5-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de [IPv6:2001:4dd6:12f5:0:7285:c2ff:fe6c:992d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin3.netcologne.de (Postfix) with ESMTPSA; Sun, 24 Feb 2019 14:54:17 +0100 (CET) From: Thomas Koenig Subject: [patch, fortran] Fix PR 89174, segfault on allocate with MOLD To: "fortran@gcc.gnu.org" , gcc-patches Message-ID: Date: Sun, 24 Feb 2019 14:54:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 Hello world, the attached patch fixes a regression where a segfault occured at runtime for the attached test case. The regression made it out into the wild with the 8.3 release. Unfortunately, it was discovered too late before release to do anything about it. In effect, this patch reverts a part of r265171 for one special case: If the argument to gfc_find_and_cut_at_last_class_ref is the MOLD argument to allocate. Of course, there could also be a more profound way of fixing this bug :-) Regression-tested on x86_64-pc-linux-gnu. OK for trunk and gcc-8? Regards Thomas 2019-02-24 Thomas Koenig PR fortran/89174 * trans-expr.c (gfc_find_and_cut_at_last_class_ref): Add is_mold to garguments. If we are dealing with a MOLD, call gfc_expr_to_initialize(). * trans-stmt.c (gfc_trans_allocate): For MOLD, pass is_mold=true to gfc_find_and_cut_at_last_class_ref. * trans.h (gfc_find_and_cut_at_last_class_ref): Add optional argument is_mold with default false. 2019-02-24 Thomas Koenig PR fortran/89174 * gfortran.dg/allocate_with_mold_3.f90: New test. Index: trans-expr.c =================================================================== --- trans-expr.c (Revision 269161) +++ trans-expr.c (Arbeitskopie) @@ -352,7 +352,7 @@ gfc_vptr_size_get (tree vptr) of refs following. */ gfc_expr * -gfc_find_and_cut_at_last_class_ref (gfc_expr *e) +gfc_find_and_cut_at_last_class_ref (gfc_expr *e, bool is_mold) { gfc_expr *base_expr; gfc_ref *ref, *class_ref, *tail = NULL, *array_ref; @@ -394,7 +394,10 @@ gfc_expr * e->ref = NULL; } - base_expr = gfc_copy_expr (e); + if (is_mold) + base_expr = gfc_expr_to_initialize (e); + else + base_expr = gfc_copy_expr (e); /* Restore the original tail expression. */ if (class_ref) Index: trans-stmt.c =================================================================== --- trans-stmt.c (Revision 269161) +++ trans-stmt.c (Arbeitskopie) @@ -6641,7 +6641,7 @@ gfc_trans_allocate (gfc_code * code) /* Use class_init_assign to initialize expr. */ gfc_code *ini; ini = gfc_get_code (EXEC_INIT_ASSIGN); - ini->expr1 = gfc_find_and_cut_at_last_class_ref (expr); + 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); Index: trans.h =================================================================== --- trans.h (Revision 269161) +++ trans.h (Arbeitskopie) @@ -412,7 +412,7 @@ tree gfc_class_data_get (tree); tree gfc_class_vptr_get (tree); tree gfc_class_len_get (tree); tree gfc_class_len_or_zero_get (tree); -gfc_expr * gfc_find_and_cut_at_last_class_ref (gfc_expr *); +gfc_expr * gfc_find_and_cut_at_last_class_ref (gfc_expr *, bool is_mold = false); /* Get an accessor to the class' vtab's * field, when a class handle is available. */ tree gfc_class_vtab_hash_get (tree);