From patchwork Sun Jan 17 23:01:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Norris X-Patchwork-Id: 569336 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 40B2214076E for ; Mon, 18 Jan 2016 10:02:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=c0KcPTZB; dkim-atps=neutral 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=ie2Z98MoizrSiVP8gOwvhYHkcmsOxRvmkH4HTHPhTuJzk6buaK fjxQBkz4arMeYQs1D3Vm5nKs+ku7BnGMrwRU1Gt/g34emlVeDPq7eCqyiQvlsOAK qWlDWPw9iiKgSXvRRWhyC4dc1le72+iG+4O4zV8we0mzh2urcQY182oB0= 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=IrZkLOLHWfJ9IPMAfNPzQESjfts=; b=c0KcPTZB1jb7NvU3Ye9L 3QjhAFQ9vF4iyaDpGfPw0CflNfQWetYzZq96fujQH+js0tgaLdSAPw4t761VJ9Pw AiW8a5PQek240JjiEvs1yRg5sYl1tmol0XjaHM11Ztp38PVbpCSlwVtuxEgSQJnh B5ijB3Oh3sR9T2PSp8PO8/g= Received: (qmail 121604 invoked by alias); 17 Jan 2016 23:01:39 -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 121543 invoked by uid 89); 17 Jan 2016 23:01:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.8 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=no version=3.3.2 spammy=hongjiuluintelcom, hongjiu.lu@intel.com, Validate, Updates 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; Sun, 17 Jan 2016 23:01:35 +0000 Received: from svr-orw-fem-04.mgc.mentorg.com ([147.34.97.41]) by relay1.mentorg.com with esmtp id 1aKwKA-00003K-AD from James_Norris@mentor.com ; Sun, 17 Jan 2016 15:01:30 -0800 Received: from [172.30.80.119] (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.3.224.2; Sun, 17 Jan 2016 15:01:29 -0800 To: GCC Patches , Jakub Jelinek From: James Norris Subject: [PATCH] Fix use of declare'd vars by routine procedures. Message-ID: <569C1D44.8080404@codesourcery.com> Date: Sun, 17 Jan 2016 17:01:24 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 Hi! The attached patch addresses the failure of declare-4 in the libgomp testsuite. The primary failure was the use a variable with a link clause for an OpenACC routine function. The patch changes the test to use a create clause. The patch also adds checking of those globals used within an OpenACC routine function. Additional gcc testing is also included in the patch. Regtested and bootstrapped on x86_64. OK for trunk? Thanks! Jim Index: gcc/c/ChangeLog =================================================================== --- gcc/c/ChangeLog (revision 232340) +++ gcc/c/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2016-01-XX James Norris + + * c-parser.c (build_external_ref): Add usage check. + 2016-01-06 David Malcolm * c-parser.c (c_parser_unary_expression): For dereferences, build Index: gcc/c/c-typeck.c =================================================================== --- gcc/c/c-typeck.c (revision 232340) +++ gcc/c/c-typeck.c (working copy) @@ -2677,6 +2677,26 @@ tree ref; tree decl = lookup_name (id); + if (decl + && decl != error_mark_node + && current_function_decl + && TREE_CODE (decl) == VAR_DECL + && is_global_var (decl) + && get_oacc_fn_attrib (current_function_decl)) + { + /* Validate data type for use with routine directive. */ + if (lookup_attribute ("omp declare target link", + DECL_ATTRIBUTES (decl)) + || ((!lookup_attribute ("omp declare target", + DECL_ATTRIBUTES (decl)) + && ((TREE_STATIC (decl) && !DECL_EXTERNAL (decl)) + || (!TREE_STATIC (decl) && DECL_EXTERNAL (decl)))))) + { + error_at (loc, "invalid use in % function"); + return error_mark_node; + } + } + /* In Objective-C, an instance variable (ivar) may be preferred to whatever lookup_name() found. */ decl = objc_lookup_ivar (decl, id); Index: gcc/cp/ChangeLog =================================================================== --- gcc/cp/ChangeLog (revision 232340) +++ gcc/cp/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2016-01-XX James Norris + + * semantics.c (finish_id_expression): Add usage check. + 2016-01-12 Marek Polacek PR c++/68979 Index: gcc/cp/semantics.c =================================================================== --- gcc/cp/semantics.c (revision 232340) +++ gcc/cp/semantics.c (working copy) @@ -3712,6 +3712,25 @@ decl = convert_from_reference (decl); } + + if (decl != error_mark_node + && current_function_decl + && TREE_CODE (decl) == VAR_DECL + && is_global_var (decl) + && get_oacc_fn_attrib (current_function_decl)) + { + /* Validate data type for use with routine directive. */ + if (lookup_attribute ("omp declare target link", + DECL_ATTRIBUTES (decl)) + || ((!lookup_attribute ("omp declare target", + DECL_ATTRIBUTES (decl)) + && ((TREE_STATIC (decl) && !DECL_EXTERNAL (decl)) + || (!TREE_STATIC (decl) && DECL_EXTERNAL (decl)))))) + { + *error_msg = "invalid use in % function"; + return error_mark_node; + } + } } return cp_expr (decl, location); Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (revision 232340) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2016-01-XX James Norris + + * c-c++-common/goacc/routine-5.c: Additional tests. + 2016-01-13 H.J. Lu * gcc.target/i386/pr69225-7.c: New test. Index: gcc/testsuite/c-c++-common/goacc/routine-5.c =================================================================== --- gcc/testsuite/c-c++-common/goacc/routine-5.c (revision 232340) +++ gcc/testsuite/c-c++-common/goacc/routine-5.c (working copy) @@ -45,3 +45,49 @@ #pragma acc routine (a) /* { dg-error "does not refer to" } */ #pragma acc routine (c) /* { dg-error "does not refer to" } */ + +float vb1; + +#pragma acc routine +int +func1 (int a) +{ + vb1 = a + 1; /* { dg-error "invalid use in" } */ + + return vb1; /* { dg-error "invalid use in" } */ +} + +#pragma acc routine +int +func2 (int a) +{ + static int vb2; + + vb2 = a + 1; /* { dg-error "invalid use in" } */ + + return vb2; /* { dg-error "invalid use in" } */ +} + +float vb3; +#pragma acc declare link (vb3) + +#pragma acc routine +int +func3 (int a) +{ + vb3 = a + 1; /* { dg-error "invalid use in" } */ + + return vb3; /* { dg-error "invalid use in" } */ +} + +float vb4; +#pragma acc declare create (vb4) + +#pragma acc routine +int +func4 (int a) +{ + vb4 = a + 1; + + return vb4; +} Index: libgomp/ChangeLog =================================================================== --- libgomp/ChangeLog (revision 232341) +++ libgomp/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2016-01-XX James Norris + + * testsuite/libgomp.oacc-c-c++-common/declare-4.c: Fix test. + 2016-01-12 James Norris * libgomp.texi: Updates for OpenACC. Index: libgomp/testsuite/libgomp.oacc-c-c++-common/declare-4.c =================================================================== --- libgomp/testsuite/libgomp.oacc-c-c++-common/declare-4.c (revision 232340) +++ libgomp/testsuite/libgomp.oacc-c-c++-common/declare-4.c (working copy) @@ -4,7 +4,7 @@ #include float b; -#pragma acc declare link (b) +#pragma acc declare create (b) #pragma acc routine int