From patchwork Tue Jun 5 13:53:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cesar Philippidis X-Patchwork-Id: 925480 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-479101-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="LHSdvJin"; 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 410YF70FkNz9s15 for ; Tue, 5 Jun 2018 23:54:01 +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:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=H/864GqKxm+zFtGO/alHmiEv/+fTRcDKj6uTRpALjV7CVEEi1RUpH X6lunigt8fjiI93/r4WmnF9MQFqpgrHXvboSX5NIy9iTC4K7DFf9esokM/w4LDIq iMNJJJJ2sxNxnLILE5Qdb8nbJEgO/HtUIAIRVh5RBFW4bWspseEMAY= 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=i44uK5wmkNcBXvToiWDGA6t3dU0=; b=LHSdvJinnvrnCZI9+Lv1 uEHBpCiYNPN90Ew1OX4+JjCDceQIFpje5FYAz0wY6F2m7sIjLKhMfKo0KUq1TaS7 2VTUrCu6yUkOI83AmrrHPZ839qQd9hPdi65Nd+jl3/GXMqEcxYi8aKRJ/v8hMUBe EOS2impkz4OIe/ksXWT91ts= Received: (qmail 102917 invoked by alias); 5 Jun 2018 13:53:54 -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 102903 invoked by uid 89); 5 Jun 2018 13:53:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=H*r:0700 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Jun 2018 13:53:51 +0000 Received: from svr-orw-mbx-04.mgc.mentorg.com ([147.34.90.204]) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1fQCPF-0002Ph-72 from Cesar_Philippidis@mentor.com ; Tue, 05 Jun 2018 06:53:49 -0700 Received: from [127.0.0.1] (147.34.91.1) by SVR-ORW-MBX-04.mgc.mentorg.com (147.34.90.204) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Tue, 5 Jun 2018 06:53:46 -0700 From: Cesar Philippidis Subject: [PATCH] Reject function and subroutine arguments in OpenACC declare data clauses (PR85701) To: "gcc-patches@gcc.gnu.org" , Jakub Jelinek Message-ID: Date: Tue, 5 Jun 2018 06:53:43 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-01.mgc.mentorg.com (147.34.90.201) To SVR-ORW-MBX-04.mgc.mentorg.com (147.34.90.204) OpenACC declare is implemented somewhat special in the Fortran FE in that it preforms its own data clause error handling. As PR85701 demonstrated, one situation that lacked test coverage was passing in function and subroutine identifiers as data clause arguments to acc declare. This patch rectifies that issue by checking for the function and subroutine symbol attribute and issuing an error when it detects such a symbol. The Fortran FE also has attributes for other types of functions, but gfc_match_omp_variable_list already handle those. However, as GCC gains support for derived-type objects, this may have to be revisited. I tested this patch on x86_64 with nvptx offloading. Is it OK for trunk and the stable branches? Thanks, Cesar 2018-06-05 Cesar Philippidis PR fortran/85701 gcc/fortran/ * openmp.c (gfc_resolve_oacc_declare): Error on functions and subroutine data clause arguments. gcc/testsuite/ * gfortran.dg/goacc/pr85701.f90: New test. diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c index be80f8dea24..5c13312585a 100644 --- a/gcc/fortran/openmp.c +++ b/gcc/fortran/openmp.c @@ -5994,6 +5994,12 @@ gfc_resolve_oacc_declare (gfc_namespace *ns) for (n = oc->clauses->lists[list]; n; n = n->next) { n->sym->mark = 0; + if (n->sym->attr.function || n->sym->attr.subroutine) + { + gfc_error ("Object %qs is not a variable at %L", + n->sym->name, &oc->loc); + continue; + } if (n->sym->attr.flavor == FL_PARAMETER) { gfc_error ("PARAMETER object %qs is not allowed at %L", diff --git a/gcc/testsuite/gfortran.dg/goacc/pr85701.f90 b/gcc/testsuite/gfortran.dg/goacc/pr85701.f90 new file mode 100644 index 00000000000..9c201b865b2 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc/pr85701.f90 @@ -0,0 +1,23 @@ +! PR fortran/85701 +! { dg-do compile } + +subroutine s1 + !$acc declare copy(s1) ! { dg-error "is not a variable" } +end + +subroutine s2 + !$acc declare present(s2) ! { dg-error "is not a variable" } +end + +function f1 () + !$acc declare copy(f1) ! { dg-error "is not a variable" } +end + +function f2 () + !$acc declare present(f2) ! { dg-error "is not a variable" } +end + +program p + !$acc declare copy(p) ! { dg-error "is not a variable" } +end +