From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 595CF385E00B for ; Thu, 26 Mar 2020 20:53:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 595CF385E00B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Thomas_Schwinge@mentor.com IronPort-SDR: VFxwtyY/EwQbs4cY+QPj+qsB9123X+seL1rR3mCgEsQ6BOTe+fgJx8ZjWvmLGxpdjn/oO0mwNL /U7O1Ae6u5vuQiA2xdwZ1uA2h5ZqmEx7woS0nWx97qjpoROCt48Spms9fRzi1iBLNe5C3HGmJT TPJA/wYbNr+/WdY+3l/a+bxaiRjMeIdK0W1XHw3XAmBbzlO2LxrQnZP4QU5xz0k7dt+CxqcfAb fDJlwWkr1dx0T4/K1MoX1awterTi8BFztsPg2FugeyCVp+OonpwznL7M97XJhl3S26bCyOvWtV qtk= X-IronPort-AV: E=Sophos;i="5.72,309,1580803200"; d="scan'208,223";a="47070366" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 26 Mar 2020 12:53:26 -0800 IronPort-SDR: +eDJUTaX7LiHCA5jer2J9hc5sQ5IAhWNT+Ob7e6lthLs7+UAkbIk0PFM14scUhqBHzKrdG85oZ KlkDjuK6+4o79vI7voYHZcw5cusrnq/pxKEUSBWBc0CxjCELxXHT9hXIW1B4//ajxgWgY80AbP 6Qm+KLhZJpdtaSLPwBKFxr0+vEpCC8LElQG9sox/0jTb06gLCkz+T9Q0OppbknVYwzzbZNNtyT Rg0B+w7NbPjqgWMQ3UwU4CH2BVy2rZXxC+DXL8eWh7OqAweiEK83ZjYhxin4bOBhKHXsZZp9t1 EIw= From: Thomas Schwinge To: Sandra Loosemore , Jakub Jelinek , Subject: Re: C++ 'NON_LVALUE_EXPR' in OMP array section handling In-Reply-To: References: <5a782157-d5ab-e9af-9a6a-78d97fc4fb07@codesourcery.com> User-Agent: Notmuch/0.29.1+93~g67ed7df (https://notmuchmail.org) Emacs/25.2.2 (x86_64-pc-linux-gnu) Date: Thu, 26 Mar 2020 21:53:19 +0100 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) To SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) X-Spam-Status: No, score=-30.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Mar 2020 20:53:30 -0000 --=-=-= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi! On 2020-03-26T09:09:01-0600, Sandra Loosemore wro= te: > On 3/26/20 8:27 AM, Thomas Schwinge wrote: >> Note that as this code is shared between OpenACC/OpenMP, this might >> affect OpenMP, too, as far as I can tell. (Subject updated.) Jakub, ca= n >> you please have a look, too? >> >> On 2020-03-25T23:02:38-0600, Sandra Loosemore = wrote: >>> The attached patch fixes a bug I found in the C++ front end's handling >>> of OpenACC data clauses. The problem here is that the C++ front end >>> wraps the array bounds expressions in NON_LVALUE_EXPR tree nodes, and >>> the code here (which appears to have been copied from similar code in >>> the C front end) was failing to strip those before checking to see if >>> they were INTEGER_CST nodes, etc. >> >> So, I had a quick look. I'm confirming the 'NON_LVALUE_EXPR' (C++ only, >> not seen for C) difference, and that 'STRIP_NOPS' gets rid of these. >> However, I also in some code paths see, for example, 'integer_nonzerop' >> calls, which internally do 'STRIP_ANY_LOCATION_WRAPPER'. >> >> I don't know if 'STRIP_NOPS' is the correct "hammer" to use here, I don'= t >> know what the usual convention is: explicitly remove (via 'STRIP_NOPS' a= s >> you suggested, or something else), or have the enquiry functions do it >> ('STRIP_ANY_LOCATION_WRAPPER' as 'integer_nonzerop' is doing, for >> example). >> >> Empirical data doesn't mean too much here, of course, I'm not seeing a >> lot of explicit 'STRIP_*' calls in 'gcc/cp/semantics.c'. ;-) > > I saw that STRIP_NOPS seem to be the preferred way to do things in e.g. > fold-const.c. I don't know if there's a reason to use some less general > form of STRIP_* here? > >>> Sadly, I have no test case for this because it was only triggering an >>> error in conjunction with some other OpenACC patches that are not yet o= n >>> trunk >> >> So maybe the problem is actually that these "other OpenACC patches" are >> not sufficiently sanitizing the input data they're doing checks on? > > No. In the current code on trunk, both places that are being patched > continue with checks like > > TREE_CODE (low_bound) =3D=3D INTEGER_CST > > etc. So when they're wrapped in NON_LVALUE_EXPRs, it's basically > failing to detect constants in array dimension specifiers and falling > through to other code. Eh, indeed... ;-\ (So we should be able to deduce some misbehavior from that, to construct a test case. I'll have a look.) >>> and the tree dumps don't show anything useful. >> >> Well, the 'original' tree dumps do show (C++) vs. don't show (C) the >> 'NON_LVALUE_EXPR's. While true, that of course doesn't tell us anything what the OMP array section handling is doing with these. I guess I was half-asleep when I wrote my email... ;-/ So. I'm not objecting to handling 'NON_LVALUE_EXPR's locally here via any kind of 'STRIP_*', but it somehow doesn't seem the general solution. Another option seems to be to teach 'fold_simple' to handle 'NON_LVALUE_EXPR's, so that the existing code: /* We need to reduce to real constant-values for checks below. */ if (length) length =3D fold_simple (length); if (low_bound) low_bound =3D fold_simple (low_bound); if (low_bound && TREE_CODE (low_bound) =3D=3D INTEGER_CST && [...]) low_bound =3D fold_convert (sizetype, low_bound); if (length && TREE_CODE (length) =3D=3D INTEGER_CST && [...]) length =3D fold_convert (sizetype, length); ... would then just work. But: I don't know if 'fold_simple' (and others?) should handle 'NON_LVALUE_EXPR's, or if there's a reason why it doesn't. (Have not yet tried to figure that out.) What I can tell is that the attached patch does solve the issue in the C++ OMP array section handling, and survives a powerpc64le-unknown-linux-gnu '--enable-checking=3Dyes' (will now re-run with 'fold' checking) bootstrap, with no testsuite regressions. Hmm. Gr=C3=BC=C3=9Fe Thomas ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstra=C3=9Fe 201, 80634 M=C3=BCnch= en / Germany Registergericht M=C3=BCnchen HRB 106955, Gesch=C3=A4ftsf=C3=BChrer: Thomas = Heurung, Alexander Walter --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename="0001-Fold-NON_LVALUE_EXPR-some-more.patch" >From 611fbe24b7e459829c0a304a58963d4987c8de0a Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Thu, 26 Mar 2020 21:22:54 +0100 Subject: [PATCH] Fold 'NON_LVALUE_EXPR' some more --- gcc/cp/constexpr.c | 1 + gcc/fold-const.c | 1 + 2 files changed, 2 insertions(+) diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 192face9a3a..f31d61c1460 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -6650,6 +6650,7 @@ fold_simple_1 (tree t) case BIT_NOT_EXPR: case TRUTH_NOT_EXPR: case NOP_EXPR: + case NON_LVALUE_EXPR: case VIEW_CONVERT_EXPR: case CONVERT_EXPR: case FLOAT_EXPR: diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 71a1d3eb735..b6bc5080ff3 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -1739,6 +1739,7 @@ const_unop (enum tree_code code, tree type, tree arg0) switch (code) { CASE_CONVERT: + case NON_LVALUE_EXPR: case FLOAT_EXPR: case FIX_TRUNC_EXPR: case FIXED_CONVERT_EXPR: -- 2.17.1 --=-=-=--