From patchwork Mon Feb 26 20:15:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 878069 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-473890-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=troutmask.apl.washington.edu Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="r7rszyrH"; 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 3zqtPn6LT1z9s1j for ; Tue, 27 Feb 2018 07:16:11 +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:date :from:to:subject:message-id:reply-to:mime-version:content-type; q=dns; s=default; b=goHCCQwsB+AVIUdu/Q0YRs96kzm6NCpPB1rf7VdcwR2 E/DMNvOLoPgrhpNMrwqI6f8AOgQNZBfMTFry9qI4YH0vblezi9+ZfjtmR7TPTYd3 6sITmItttzkWJ9kRgNxxcVEO5kHyWlI3qV25ncxfbTppZeFLztm3gcMwgp4M/yBk = 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:date :from:to:subject:message-id:reply-to:mime-version:content-type; s=default; bh=xiR7iho96CbWgnZcrCjvxmsbNGM=; b=r7rszyrHcdQ6YjQO8 9ZWXFI3pr1lEFBxQcudIvXI4zvfRHBVuJdj2ttPPMlvwDDu6Y0eY+v6Lg9JDGDha zfXUsW58BzduWSOfXo9XY2zb0o+J96cJbcsdeeH8Mgf7OTtGWJWYfpBcdgP+O7cr HmqaKaTUfsLOHIAp++iCUTLyrM= Received: (qmail 25239 invoked by alias); 26 Feb 2018 20:15:44 -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 25125 invoked by uid 89); 26 Feb 2018 20:15:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=death, transfer, mold X-Spam-User: qpsmtpd, 2 recipients X-HELO: troutmask.apl.washington.edu Received: from troutmask.apl.washington.edu (HELO troutmask.apl.washington.edu) (128.95.76.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Feb 2018 20:15:35 +0000 Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.15.2/8.15.2) with ESMTPS id w1QKFXjT095839 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 26 Feb 2018 12:15:33 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id w1QKFXUv095838; Mon, 26 Feb 2018 12:15:33 -0800 (PST) (envelope-from sgk) Date: Mon, 26 Feb 2018 12:15:33 -0800 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR fortran/51434 -- ICE in gfc_simplify_transfer Message-ID: <20180226201533.GA95814@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) All, The attached patch fixes an ICE that occurs in gfc_simplify_tranfer. The code that causes the problem is if (!gfc_is_constant_expr (source) || (gfc_init_expr_flag && !gfc_is_constant_expr (mold)) || !gfc_is_constant_expr (size)) return NULL; in particular gfc_is_constant_expr (mold) leads to segfault. Removing the 2nd line allows the testcase to compile, but leads to several regressions. I went down the rabbit with gdb-8.0.1 to see why this was dying a horrible death, and came away with a large headache. After conferring with F95 and F2018, I concluded (and I coudl be wrong) that mold simply needs to available as a scalar or an array and it's actual value was not needed. So, I decided to use gfc_reduce_expr (mold) to see if this would fix up some rogue pointer, and well it worked. So, OK to commit? 2018-02-26 Steven G. Kargl PF fortran/51434 * simplify.c (gfc_simplify_transfer): Reduce mold. 2018-02-26 Steven G. Kargl PF fortran/51434 * gfortran.dg/pr51434.f90: New test. Index: gcc/fortran/simplify.c =================================================================== --- gcc/fortran/simplify.c (revision 258006) +++ gcc/fortran/simplify.c (working copy) @@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "gfortran.h" #include "arith.h" #include "intrinsic.h" +#include "match.h" #include "target-memory.h" #include "constructor.h" #include "version.h" /* For version_string. */ @@ -7370,10 +7371,12 @@ gfc_simplify_transfer (gfc_expr *source, gfc_expr *mol unsigned char *buffer; size_t result_length; + if (!gfc_is_constant_expr (source) || !gfc_is_constant_expr (size)) + return NULL; - if (!gfc_is_constant_expr (source) - || (gfc_init_expr_flag && !gfc_is_constant_expr (mold)) - || !gfc_is_constant_expr (size)) + if (!gfc_resolve_expr (mold)) + return NULL; + if (gfc_init_expr_flag && !gfc_is_constant_expr (mold)) return NULL; if (!gfc_calculate_transfer_sizes (source, mold, size, &source_size, Index: gcc/testsuite/gfortran.dg/pr51434.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr51434.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr51434.f90 (working copy) @@ -0,0 +1,19 @@ +! { dg-do run } +! PR fortran/51434 +module foo + implicit none + integer, parameter :: n = 5 + character(len=1), parameter :: s(n) = 'a' + type :: a + integer :: m = n + character(len=1):: t(n) = transfer('abcde ', s) + end type a +end module foo + +program bar + use foo + implicit none + type(a) c + if (c%m /= n) stop 1 + if (any(c%t /= ['a', 'b', 'c', 'd', 'e'])) stop 2 +end program bar