From patchwork Mon Aug 15 09:52:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chung-Lin Tang X-Patchwork-Id: 659159 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 3sCW510ff0z9t22 for ; Mon, 15 Aug 2016 19:52:52 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=JlSMbdxT; 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:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=RC3Fp1EUN+OA0Ojrx6N1cJN3e7SrefWZnEe9Vmg2r10kISfCDi rEyM6kMUZzzAp8AEyoTHmyWxuQWFm+OlJ2PEUClBduGhTDA+KY/HrPZsSIbaz/Gu Qc9dN1LUihVB2Q3xyAf1uuOoFoKqJcTtwSYx3r+M8eLWjnYz+4XvoVBqs= 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:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=BLBVdUfmvsj+iq+fEUrDmc4OdaA=; b=JlSMbdxTQiNLtNSVydZa o60cBZ00BJRIVkTXx8KAHP8atbGi2FveFFkEpx3/qlDRFwraLQETgkYBq8g1jLnO hf879pIlAmK1j6mBJIdIvnpLYW/g/nCGFARWyza5pLexAHS1JPyfZdM8MZSSGnJD Zb7pQImIaLoUt0qygDfpyHw= Received: (qmail 58155 invoked by alias); 15 Aug 2016 09:52:45 -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 58145 invoked by uid 89); 15 Aug 2016 09:52:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=H*r:ip*0.0.0.0, H*r:0.0.0, H*r:Mon, Hx-languages-length:1264 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; Mon, 15 Aug 2016 09:52:34 +0000 Received: from svr-orw-fem-03.mgc.mentorg.com ([147.34.97.39]) by relay1.mentorg.com with esmtp id 1bZEZL-0006RE-43 from ChungLin_Tang@mentor.com ; Mon, 15 Aug 2016 02:52:31 -0700 Received: from [0.0.0.0] (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.3.224.2; Mon, 15 Aug 2016 02:52:30 -0700 To: gcc-patches , Jakub Jelinek CC: Cesar Philippidis From: Chung-Lin Tang Subject: [patch, OpenACC] Fix reduction lowering segfault in omp-low Message-ID: <7d98ae79-3cb7-03f2-bbd5-34a78d30dfd4@codesourcery.com> Date: Mon, 15 Aug 2016 17:52:29 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi Jakub, This patch fixes an OpenACC reduction lowering segfault which triggers when nested acc loop directives are present. Cesar has reviewed this patch internally (since he mostly wrote the code originally) Patch has been tested and committed to gomp-4_0-branch, is this also okay for trunk? Thanks, Chung-Lin 2016-08-15 Chung-Lin Tang * omp-low.c (lower_oacc_reductions): Adjust variable lookup to use maybe_lookup_decl, to handle nested acc loop directives. Index: omp-low.c =================================================================== --- omp-low.c (revision 239324) +++ omp-low.c (working copy) @@ -5687,10 +5687,19 @@ lower_oacc_reductions (location_t loc, tree clause outgoing = var; incoming = omp_reduction_init_op (loc, rcode, type); } - else if (ctx->outer) - incoming = outgoing = lookup_decl (orig, ctx->outer); else - incoming = outgoing = orig; + { + /* Try to look at enclosing contexts for reduction var, + use original if no mapping found. */ + tree t = NULL_TREE; + omp_context *c = ctx->outer; + while (c && !t) + { + t = maybe_lookup_decl (orig, c); + c = c->outer; + } + incoming = outgoing = (t ? t : orig); + } has_outer_reduction:; }