From patchwork Wed Feb 3 14:24:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Norris X-Patchwork-Id: 578142 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 4452F140B04 for ; Thu, 4 Feb 2016 01:25:08 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=r/cCdwOd; 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=UQ47zJVYa1tf7krJuVk82/l1yajpH3A5VCyiAlSMu0KtkShsy3 TWM/JQ4+dV3iDJL4OhtoJJ77PMJkoqAWsYGCueltu4dqmpaawPiGo/8TnUdW0Cua ffePsvL9KTY5ZynbX4m1iv9ySIHZsqlsmumVnHR3FTVvbAZxpqUerbGeY= 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=vgBEpGfI3TGZTvNrinh5wawrygk=; b=r/cCdwOdqGzdQElPwMbr JS5mX9eFI08Cx9JC1guRUVQBSgb8ogt6amCQGSY3Osk6yy98aolgjRJxYWsMxhLl kXYBXFAiQIUve7R8XdW52FGTDhjE2LwtwUHH51rZ7qbjA6qibfi1Hb1u9kLHIN5b KB+9ZzD0yBh9HQU12pnpe84= Received: (qmail 125014 invoked by alias); 3 Feb 2016 14:25:01 -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 124995 invoked by uid 89); 3 Feb 2016 14:25:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=no version=3.3.2 spammy=2016-01-14, 20160114, objective-c, Objective-C 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; Wed, 03 Feb 2016 14:24:58 +0000 Received: from svr-orw-fem-02x.mgc.mentorg.com ([147.34.96.206] helo=SVR-ORW-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1aQyMX-0002ko-US from James_Norris@mentor.com for gcc-patches@gcc.gnu.org; Wed, 03 Feb 2016 06:24:54 -0800 Received: from [172.30.96.124] (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.3.224.2; Wed, 3 Feb 2016 06:24:53 -0800 To: GCC Patches From: James Norris Subject: [gomp4] Fix use of declare'd vars by routine procedures. Message-ID: <56B20DB3.7040208@codesourcery.com> Date: Wed, 3 Feb 2016 08:24:51 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 I've backported this patch from trunk to gomp-4_0-branch. This patch updates a previous patch to gomp4 in dealing with variables used within a routine procedure. Reference: https://gcc.gnu.org/ml/gcc-patches/2016-01/msg01231.html Thanks, Jim ==== ChangeLog entries... gcc/ * gimplify.c (omp_notice_variable): Add usage check. gcc/testsuite/ * c-c++-common/goacc/routine-5.c: Add tests. gcc/c/ * c-typeck.c (build_external_ref): Remove usage check. gcc/cp/ * semantics.c (finish_id_expression): Remove usage check. Index: gcc/ChangeLog.gomp =================================================================== --- gcc/ChangeLog.gomp (revision 233104) +++ gcc/ChangeLog.gomp (working copy) @@ -1,3 +1,9 @@ +2016-02-03 James Norris + * gimplify.c (omp_notice_variable): Add usage check. + 2016-01-22 Nathan Sidwell * omp-low.c (struct oacc_loop): Add 'inner' field. Index: gcc/c/ChangeLog.gomp =================================================================== --- gcc/c/ChangeLog.gomp (revision 233104) +++ gcc/c/ChangeLog.gomp (working copy) @@ -1,3 +1,7 @@ +2016-02-03 James Norris + + * c-typeck.c (build_external_ref): Remove usage check. + 2016-01-14 James Norris * c-parser.c (c_finish_oacc_routine): Remove attribute. Index: gcc/c/c-typeck.c =================================================================== --- gcc/c/c-typeck.c (revision 233104) +++ gcc/c/c-typeck.c (working copy) @@ -2677,26 +2677,6 @@ 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.gomp =================================================================== --- gcc/cp/ChangeLog.gomp (revision 233104) +++ gcc/cp/ChangeLog.gomp (working copy) @@ -1,3 +1,7 @@ +2016-02-03 James Norris + + * semantics.c (finish_id_expression): Remove usage check. + 2016-01-20 Cesar Philippidis * parser.c (cp_parser_oacc_all_clauses): Call finish_omp_clauses Index: gcc/cp/semantics.c =================================================================== --- gcc/cp/semantics.c (revision 233104) +++ gcc/cp/semantics.c (working copy) @@ -3712,25 +3712,6 @@ 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/gimplify.c =================================================================== --- gcc/gimplify.c (revision 233104) +++ gcc/gimplify.c (working copy) @@ -6095,9 +6095,9 @@ if (ctx->region_type == ORT_NONE) return lang_hooks.decls.omp_disregard_value_expr (decl, false); - /* Threadprivate variables are predetermined. */ if (is_global_var (decl)) { + /* Threadprivate variables are predetermined. */ if (DECL_THREAD_LOCAL_P (decl)) return omp_notice_threadprivate_variable (ctx, decl, NULL_TREE); @@ -6108,6 +6108,30 @@ if (value && DECL_P (value) && DECL_THREAD_LOCAL_P (value)) return omp_notice_threadprivate_variable (ctx, decl, value); } + + if (gimplify_omp_ctxp->outer_context == NULL + && VAR_P (decl) + && get_oacc_fn_attrib (current_function_decl)) + { + location_t loc = DECL_SOURCE_LOCATION (decl); + + if (lookup_attribute ("omp declare target link", + DECL_ATTRIBUTES (decl))) + { + error_at (loc, + "%qE with % clause used in % function", + DECL_NAME (decl)); + return false; + } + else if (!lookup_attribute ("omp declare target", + DECL_ATTRIBUTES (decl))) + { + error_at (loc, + "%qE requires a % directive for use " + "in a % function", DECL_NAME (decl)); + return false; + } + } } n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl); Index: gcc/testsuite/ChangeLog.gomp =================================================================== --- gcc/testsuite/ChangeLog.gomp (revision 233104) +++ gcc/testsuite/ChangeLog.gomp (working copy) @@ -1,3 +1,9 @@ +2016-02-03 James Norris + + Backport from trunk: + 2016-02-02 James Norris + * c-c++-common/goacc/routine-5.c: Add tests. + 2016-01-22 Nathan Sidwell * c-c++-common/goacc/loop-auto-1.c: Adjust expected warnings. Index: gcc/testsuite/c-c++-common/goacc/routine-5.c =================================================================== --- gcc/testsuite/c-c++-common/goacc/routine-5.c (revision 233104) +++ gcc/testsuite/c-c++-common/goacc/routine-5.c (working copy) @@ -60,48 +60,96 @@ #pragma acc routine (Baz) // { dg-error "not been declared" } -float vb1; +int vb1; /* { dg-error "directive for use" } */ +extern int vb2; /* { dg-error "directive for use" } */ +static int vb3; /* { dg-error "directive for use" } */ #pragma acc routine int func1 (int a) { - vb1 = a + 1; /* { dg-error "invalid use in" } */ + vb1 = a + 1; + vb2 = vb1 + 1; + vb3 = vb2 + 1; - return vb1; /* { dg-error "invalid use in" } */ + return vb3; } #pragma acc routine int func2 (int a) { - static int vb2; + extern int vb4; /* { dg-error "directive for use" } */ + static int vb5; /* { dg-error "directive for use" } */ - vb2 = a + 1; /* { dg-error "invalid use in" } */ + vb4 = a + 1; + vb5 = vb4 + 1; - return vb2; /* { dg-error "invalid use in" } */ + return vb5; } -float vb3; -#pragma acc declare link (vb3) +extern int vb6; /* { dg-error "clause used in" } */ +#pragma acc declare link (vb6) +static int vb7; /* { dg-error "clause used in" } */ +#pragma acc declare link (vb7) #pragma acc routine int func3 (int a) { - vb3 = a + 1; /* { dg-error "invalid use in" } */ + vb6 = a + 1; + vb7 = vb6 + 1; - return vb3; /* { dg-error "invalid use in" } */ + return vb7; } -float vb4; -#pragma acc declare create (vb4) +int vb8; +#pragma acc declare create (vb8) +extern int vb9; +#pragma acc declare create (vb9) +static int vb10; +#pragma acc declare create (vb10) #pragma acc routine int func4 (int a) { - vb4 = a + 1; + vb8 = a + 1; + vb9 = vb8 + 1; + vb10 = vb9 + 1; - return vb4; + return vb10; } + +int vb11; +#pragma acc declare device_resident (vb11) +extern int vb12; +#pragma acc declare device_resident (vb12) +extern int vb13; +#pragma acc declare device_resident (vb13) + +#pragma acc routine +int +func5 (int a) +{ + vb11 = a + 1; + vb12 = vb11 + 1; + vb13 = vb12 + 1; + + return vb13; +} + +#pragma acc routine +int +func6 (int a) +{ + extern int vb14; +#pragma acc declare create (vb14) + static int vb15; +#pragma acc declare create (vb15) + + vb14 = a + 1; + vb15 = vb14 + 1; + + return vb15; +}