From patchwork Wed Feb 6 20:27:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 1037758 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-495411-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="ozvfW7tH"; dkim=pass (2048-bit key; unprotected) header.d=netcologne.de header.i=@netcologne.de header.b="Zj30iZFO"; 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 43vtLG1nYjz9sN6 for ; Thu, 7 Feb 2019 07:28:04 +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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=Q9Iz922CbRGsxWlU7XyuuwldroNvN8OURvHyqpVeS8ENNHughO csO8lD5gBuovD5upAYq5mlga4AUEQD4kh/ThDn8A6YEeMQbNCoyBstjmn21PSqxw NigjWUMuCC8MrDBfhV26Wkc3ogJYQwtyGKYuNQSUtMnWhwcVCOvFl0qw0= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=F8XoZ+rVvOZSJw0YYRzWQhyCzy8=; b=ozvfW7tHCw7KLhTo1Th+ LA4SNaXVKU6mON6v5vsaxLDo0Bv8VJkATOtS/DRG9H5SairLbdttSNCRLVRUWDpZ /O07s8jFg9IOsTUjV0D+30RahYzRK4u9FsymDgDAi++b3WTWvKuU3MdvumSAVrRA KhHdKCEvVjz9NNBRR/o/Uhk= Received: (qmail 92617 invoked by alias); 6 Feb 2019 20:27:51 -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 92599 invoked by uid 89); 6 Feb 2019 20:27:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=Different, tkoeniggccgnuorg, sk:tkoenig X-HELO: cc-smtpout2.netcologne.de Received: from cc-smtpout2.netcologne.de (HELO cc-smtpout2.netcologne.de) (89.1.8.212) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 06 Feb 2019 20:27:48 +0000 Received: from cc-smtpin3.netcologne.de (cc-smtpin3.netcologne.de [89.1.8.203]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id AD28B12616; Wed, 6 Feb 2019 21:27:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=netcologne.de; s=nc1116a; t=1549484864; bh=57baNpZxpcZHaA6W2xV6WAZm6pXTlIfGKTtfh0E5ZvI=; h=To:From:Subject:Message-ID:Date:From; b=Zj30iZFOCnsBMgaQlC9Oymq79JcV7LyymIdGyUIr8tI4MxNf3odMsQGVK5UzhhVye 9HwFMZ3Cuilx1BEQ6l5hGmBb1nUVIplbE9hQiDEjcQ4V/iqJj77/qiWkI4I8eH1Dzt jKXMqdKoEzym64t5KEKhN+CawYSlLWZRhAiPxFDZSTBA67qhCWVVIdCMES9Y4iPXaZ AngbmhU5tjXPNWdqR+4ogPSByt/E49b4kQSLW4ACC10IOzGhRFAHsc0gYIaKXjLI9F n9QY5i1UYII328ZdgbGMHNjFuKdQ8l9U4xi7nKUKrs8JIMFgRxuUlv1SW5PYnO5Xzy q8a5YXgX99QtQ== Received: from localhost (localhost [127.0.0.1]) by cc-smtpin3.netcologne.de (Postfix) with ESMTP id 9F10111EC9; Wed, 6 Feb 2019 21:27:44 +0100 (CET) Received: from [2001:4dd7:27e8:0:7285:c2ff:fe6c:992d] (helo=cc-smtpin3.netcologne.de) by localhost with ESMTP (eXpurgate 4.6.0) (envelope-from ) id 5c5b4340-0bea-7f0000012729-7f00000195de-1 for ; Wed, 06 Feb 2019 21:27:44 +0100 Received: from [IPv6:2001:4dd7:27e8:0:7285:c2ff:fe6c:992d] (2001-4dd7-27e8-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de [IPv6:2001:4dd7:27e8: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; Wed, 6 Feb 2019 21:27:43 +0100 (CET) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, fortran] Fix PR 71237 Message-ID: Date: Wed, 6 Feb 2019 21:27:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 Hello world, this patch fixes a 7/8/9 regression where we tried to accept invalid code, which led to an ICE later on. The patch is rather straightforward. The reason why I could not use gfc_expr_attr is that it does not actually return the flags the way they can be found in the original attributes; for example, an expression containing a pointer attribute is shown as having the target attribute, for reasons I cannot fathom. Regression-tested. OK for trunk and other open branches? Regards Thomas 2019-02-06 Thomas Koenig PR fortran/71237 * expr.c (gfc_check_assign): Add argument is_init_expr. If we are looking at an init expression, issue error if the target is not a TARGET and we are not looking at a procedure pointer. * gfortran.h (gfc_check_assign): Add optional argument is_init_expr. 2019-02-06 Thomas Koenig PR fortran/71237 * gfortran.dg/pointer_init_2.f90: Adjust error messages. * gfortran.dg/pointer_init_6.f90: Likewise. * gfortran.dg/pointer_init_9.f90: New test. Index: fortran/ChangeLog =================================================================== --- fortran/ChangeLog (Revision 268501) +++ fortran/ChangeLog (Arbeitskopie) @@ -1,3 +1,11 @@ +2019-02-05 Thomas Koenig + + PR fortran/67679 + Backport from trunk + * trans-array.c (gfc_array_allocate): For setting the bounds on + the new array, add a condition for a not previously allocated + variable. + 2019-02-02 Dominique d'Humieres PR fortran/81344 Index: fortran/expr.c =================================================================== --- fortran/expr.c (Revision 268432) +++ fortran/expr.c (Arbeitskopie) @@ -3682,7 +3682,7 @@ gfc_check_assign (gfc_expr *lvalue, gfc_expr *rval bool gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue, - bool suppress_type_test) + bool suppress_type_test, bool is_init_expr) { symbol_attribute attr, lhs_attr; gfc_ref *ref; @@ -4124,12 +4124,36 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_ex return false; } - if (!attr.target && !attr.pointer) + if (is_init_expr) { - gfc_error ("Pointer assignment target is neither TARGET " - "nor POINTER at %L", &rvalue->where); - return false; + gfc_symbol *sym; + bool target; + + gcc_assert (rvalue->symtree); + sym = rvalue->symtree->n.sym; + + if (sym->ts.type == BT_CLASS && sym->attr.class_ok) + target = CLASS_DATA (sym)->attr.target; + else + target = sym->attr.target; + + if (!target && !proc_pointer) + { + gfc_error ("Pointer assignment target in initialization expression " + "does not have the TARGET attribute at %L", + &rvalue->where); + return false; + } } + else + { + if (!attr.target && !attr.pointer) + { + gfc_error ("Pointer assignment target is neither TARGET " + "nor POINTER at %L", &rvalue->where); + return false; + } + } if (is_pure && gfc_impure_variable (rvalue->symtree->n.sym)) { @@ -4262,7 +4286,7 @@ gfc_check_assign_symbol (gfc_symbol *sym, gfc_comp } if (pointer || proc_pointer) - r = gfc_check_pointer_assign (&lvalue, rvalue); + r = gfc_check_pointer_assign (&lvalue, rvalue, false, true); else { /* If a conversion function, e.g., __convert_i8_i4, was inserted Index: fortran/gfortran.h =================================================================== --- fortran/gfortran.h (Revision 268475) +++ fortran/gfortran.h (Arbeitskopie) @@ -3247,7 +3247,8 @@ int gfc_kind_max (gfc_expr *, gfc_expr *); bool gfc_check_conformance (gfc_expr *, gfc_expr *, const char *, ...) ATTRIBUTE_PRINTF_3; bool gfc_check_assign (gfc_expr *, gfc_expr *, int, bool c = true); bool gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue, - bool suppres_type_test = false); + bool suppres_type_test = false, + bool is_init_expr = false); bool gfc_check_assign_symbol (gfc_symbol *, gfc_component *, gfc_expr *); gfc_expr *gfc_build_default_init_expr (gfc_typespec *, locus *); Index: testsuite/gfortran.dg/pointer_init_2.f90 =================================================================== --- testsuite/gfortran.dg/pointer_init_2.f90 (Revision 268432) +++ testsuite/gfortran.dg/pointer_init_2.f90 (Arbeitskopie) @@ -18,7 +18,7 @@ subroutine sub integer, pointer :: dp0 => 13 ! { dg-error "Error in pointer initialization" } integer, pointer :: dp1 => r ! { dg-error "Different types in pointer assignment" } integer, pointer :: dp2 => v ! { dg-error "Different ranks in pointer assignment" } - integer, pointer :: dp3 => i ! { dg-error "is neither TARGET nor POINTER" } + integer, pointer :: dp3 => i ! { dg-error "Pointer assignment target in initialization expression does not have the TARGET attribute" } integer, pointer :: dp4 => j ! { dg-error "must have the SAVE attribute" } integer, pointer :: dp5 => a ! { dg-error "must not be ALLOCATABLE" } @@ -35,7 +35,7 @@ subroutine sub end type t3 type t4 - integer, pointer :: dpc3 => i ! { dg-error "Pointer assignment target is neither TARGET nor POINTER" } + integer, pointer :: dpc3 => i ! { dg-error "Pointer assignment target in initialization expression does not have the TARGET attribute" } end type t4 type t5 Index: testsuite/gfortran.dg/pointer_init_6.f90 =================================================================== --- testsuite/gfortran.dg/pointer_init_6.f90 (Revision 268432) +++ testsuite/gfortran.dg/pointer_init_6.f90 (Arbeitskopie) @@ -13,7 +13,7 @@ module m1 integer, target :: i type(t), target :: x integer, pointer :: p1 => i - integer, pointer :: p2 => p1 ! { dg-error "must have the TARGET attribute" } + integer, pointer :: p2 => p1 ! { dg-error "Pointer assignment target in initialization expression does not have the TARGET attribute at" } integer, pointer :: p3 => x%p ! { dg-error "must have the TARGET attribute" } integer, pointer :: p4 => x%i integer, pointer :: p5 => u ! { dg-error "has no IMPLICIT type" }