From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17493 invoked by alias); 23 May 2016 18:28:11 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 17461 invoked by uid 89); 23 May 2016 18:28:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1330 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 23 May 2016 18:28:09 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DEF2764472; Mon, 23 May 2016 18:28:07 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-88.ams2.redhat.com [10.36.116.88]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4NIS6x6021576 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 23 May 2016 14:28:07 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u4NIS4B0013274; Mon, 23 May 2016 20:28:04 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u4NIS1fl013272; Mon, 23 May 2016 20:28:01 +0200 Date: Mon, 23 May 2016 18:28:00 -0000 From: Jakub Jelinek To: Alexander Monakov Cc: Ilya Verbin , Nathan Sidwell , Thomas Schwinge , Jan Hubicka , gcc-patches@gcc.gnu.org Subject: Re: "omp declare target" on DECL_EXTERNAL vars Message-ID: <20160523182801.GA28550@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20160520161244.GN28550@tucnak.redhat.com> <20160520162120.GO28550@tucnak.redhat.com> <20160523165110.GV28550@tucnak.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2016-05/txt/msg01831.txt.bz2 On Mon, May 23, 2016 at 09:19:47PM +0300, Alexander Monakov wrote: > > So unlike for functions, for variables GCC needs to know exactly whether they > are 'omp declare target [link]' at all points of use, not just at the point of > definition. There are many bugs that just can't be diagnosed by the compiler. It is up to the users to make sure they write sane code. > There's a pitfall if the user forgets the pragma on the external declaration: > > === a.c > > #pragma omp declare target > int a; > void set_a() > { > a = 42; > } > #pragma omp end declare target > > === main.c > > extern int a; > extern void set_a(); > #pragma omp declare target to(set_a) > > int main() > { > a = 0; > #pragma omp target map(tofrom:a) > set_a(); > > if (a != 42) abort(); > } > === The above will abort always, no matter if you have #pragma omp declare target to(a) in main.c or not, because a is already mapped (with infinite refcount), so the map(tofrom:a) doesn't actually do anything (but prevent firstprivatization of the var). With map clause on the target, the only change would be that the body of the target (but not functions it calls), if they reference a, would be less efficient (would reference a through some pointer set up during the mapping, instead of a directly). Jakub