From patchwork Tue Dec 10 10:35:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1207004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515588-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="dog5KBqB"; 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 47XGgh4rG6z9sR8 for ; Tue, 10 Dec 2019 21:36:15 +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=B6BKHUhUNW2MCpnlLS8uiQFgnBJP83tze8/b5W2lDM9KWFaWK0 fns9+qR2Ku3jfFvBPDaeaeMlX6CHO9s4ywAldYl9gxfUzKqiN5t3XcurDoQvdsDY VxWQl9q15xcGtoQrUQ/kkPfXycBB+Wf8uzwKjhC4KbQi1w4vXrrqGshf4= 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=E10mgL/Yytx14SsK8xDyD4ERlbI=; b=dog5KBqBwn0WWOE0ZfAY 96q8zEG+eJDuhX+QrqMz+YSLDm7OrGS+yHromoItRroml5rnLVPJu1UWIq4Jnzdt HAoD3zhWhccN/k2F+faUPUukngMYkont1nVhw+ZOmDgnIF8eUcUDDp/BCFAVyuOE imsGlwfFLqG4qRSbSZD7A9c= Received: (qmail 82157 invoked by alias); 10 Dec 2019 10:36:07 -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 82141 invoked by uid 89); 10 Dec 2019 10:36:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.9 required=5.0 tests=AWL, BAYES_00, GARBLED_SUBJECT, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: esa2.mentor.iphmx.com Received: from esa2.mentor.iphmx.com (HELO esa2.mentor.iphmx.com) (68.232.141.98) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Dec 2019 10:36:05 +0000 IronPort-SDR: SJmrotnqsYbLzx3yxIOVVDNOboDG1AyczKwXjr2255E47a+qPYuG+y/pVVm45nNUOFOnPZMJN4 UD5oPowq4fp9v/+J5X9uorDgCE24HbUcxNGfvqqYRWRvZ6k2E6Z4CoVojjZi/8KChsOTiaq9CB qju2qh9uWwi42Nne6Asy5rxz26e3HfWVqxoJ29CJeblJ4A0hayikQVubA0C56TUoRxNUkqEXMb so8Yujboly8jWZLi2vBKDE7rSMwZls5r+RFbLUbipOP1nOYcKj7jt80D+fDHi3uu3Qc8o+AhCr jog= Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 10 Dec 2019 02:35:51 -0800 IronPort-SDR: cAOEUFYfp5cI4MpnS/FvXaP0xfyddGjJnglm/vElg2irlV3rOw/sIXMeI2q1b7GUG1TtbHWIxZ S2+t000/bQdgN1ULr8zIuspDO4fJyLlEsXgTHHQwGfwMXbzq0d0iSXd8RVc+IOiS32TphFWPW+ YKOp7nHwFrMI5/bnQ3U+0e0ss+ZwFVTIgY45KHeQ284SfUFa5UMjnPtoRN7GVtqjoZf0WQyjHe FiLDEDsbZfQwueBYa3PkyEsu1PVHtiIKFbFyG8ya+YgvaEXCuI6aE/1AKasbfindxmYFyz/B1M K3Y= To: gcc-patches , fortran From: Tobias Burnus Subject: =?utf-8?q?=5Bpatch=2C_committed=2C_Fortran=5D_PR_92872_=E2=80=93?= =?utf-8?q?_Fix_get=5FCFI=5Fdesc?= Message-ID: <1be00e2c-9714-9eaa-8700-2d80d28081ad@codesourcery.com> Date: Tue, 10 Dec 2019 11:35:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 X-IsSubscribed: yes Fix the condition; the DECL_LANG_SPECIFIC can be used for much more than just to save the decl. Committed as Rev. 279160. Tobias 2019-12-10 Tobias Burnus PR fortran/92872 * trans-array.c (get_CFI_desc): Fix cond whether saved desc exists. PR fortran/92872 * gfortran.dg/bind_c_optional-1.f90: New. diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 5c27c065ff0..1b779988616 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -882,7 +882,7 @@ get_CFI_desc (gfc_symbol *sym, gfc_expr *expr, else tmp = sym->backend_decl; - if (tmp && DECL_LANG_SPECIFIC (tmp)) + if (tmp && DECL_LANG_SPECIFIC (tmp) && GFC_DECL_SAVED_DESCRIPTOR (tmp)) tmp = GFC_DECL_SAVED_DESCRIPTOR (tmp); *desc = tmp; diff --git a/gcc/testsuite/gfortran.dg/bind_c_optional-1.f90 b/gcc/testsuite/gfortran.dg/bind_c_optional-1.f90 new file mode 100644 index 00000000000..99409205b6f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bind_c_optional-1.f90 @@ -0,0 +1,22 @@ +! { dg-do run } +! +! PR fortran/92872 +! +! Contributed by G. Steinmetz +! +module m +contains +subroutine s(x) bind(c) + integer, allocatable, optional :: x(:) + x = [1, 2, 3] +end +end + +use m +integer, allocatable :: y(:) +! NOTE: starting at 0, otherwise it will fail due to PR 92189 +allocate(y(0:2)) +y = [9, 8, 7] +call s(y) +if (any (y /= [1, 2, 3])) stop 1 +end