From patchwork Thu Jun 20 22:20:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 1119845 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-503407-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=troutmask.apl.washington.edu 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 45VGVz2BRrz9s3C for ; Fri, 21 Jun 2019 08:21:06 +1000 (AEST) 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=yfdxkroNadI4HITWbwYMZlfbkN9rGZjzROM6pm5thGT hjLUZ54ivKMAz3NZzFABbeExP02yPv62pyQ4ozXXxJZzTpHvubnN8CA8qoF/kJX6 713KO9YqxI7Hr1OgjQMJyqzDKT+URqowjXmt0vDmQhrrhAtA9ZaUVtvAg3/HQ4Ns = 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=pcl6QFYd6Qjntrp5l2Ka+ivb6c8=; b=PclC/HGw2SNCYwxxI 8WP49KQKjaxoYAl6dlb1pnJoPKOLlUZsiahu3VSeIBH9anFe4XWiwaLlfvYbUjuB F3HSwlJj45wqkEl/8r/QGDiYYlS7mRudM22NBcYfArt4bPY796hcij2/G0iZPLCv Cn8y0kwh8npDZnfBfyF9r08qPI= Received: (qmail 105199 invoked by alias); 20 Jun 2019 22:20:55 -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 105183 invoked by uid 89); 20 Jun 2019 22:20:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy=stumbled 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; Thu, 20 Jun 2019 22:20:54 +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 x5KMKqd8050152 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 20 Jun 2019 15:20:52 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id x5KMKqeW050151; Thu, 20 Jun 2019 15:20:52 -0700 (PDT) (envelope-from sgk) Date: Thu, 20 Jun 2019 15:20:52 -0700 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [Committed] A target in pointer initialization requires SAVE Message-ID: <20190620222052.GA49955@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.4 (2019-03-13) In taking a look at PR fortran/77632, I stumbled acrossed the testcase in the attached patch cause an ICE. I originally thought that it was realated to the topic of the PR, but is in fact an unrelated bug. If a variable is a target in a pointer initialization, then it must have the SAVE attribute. A variable in PROGRAM, MODULE, or SUBMODULE scope is implicitly SAVEd. So, the patch explicitly sets the save attribute to SAVE_IMPLICIT. 2019-06-20 Steven G. Kargl PR fortran/77632 * /decl.c (variable_decl): Mark a variable that is a target in pointer initialization when in PROGRAM, MODULE, or SUBMODULE scope with an implicit save. 2019-06-20 Steven G. Kargl PR fortran/77632 * gfortran.dg/pr77632_1.f90: New test. Index: gcc/fortran/decl.c =================================================================== --- gcc/fortran/decl.c (revision 272523) +++ gcc/fortran/decl.c (working copy) @@ -2779,6 +2779,16 @@ variable_decl (int elem) m = match_pointer_init (&initializer, 0); if (m != MATCH_YES) goto cleanup; + + /* The target of a pointer initialization must have the SAVE + attribute. A variable in PROGRAM, MODULE, or SUBMODULE scope + is implicit SAVEd. Explicitly, set the SAVE_IMPLICIT value. */ + if (initializer->expr_type == EXPR_VARIABLE + && initializer->symtree->n.sym->attr.save == SAVE_NONE + && (gfc_current_state () == COMP_PROGRAM + || gfc_current_state () == COMP_MODULE + || gfc_current_state () == COMP_SUBMODULE)) + initializer->symtree->n.sym->attr.save = SAVE_IMPLICIT; } else if (gfc_match_char ('=') == MATCH_YES) { Index: gcc/testsuite/gfortran.dg/pr77632_1.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr77632_1.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr77632_1.f90 (working copy) @@ -0,0 +1,7 @@ +! { dg-do run } +program foo + implicit none + real, target :: a + real, pointer :: b => a + if (associated(b, a) .eqv. .false.) stop 1 +end program foo