From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32635 invoked by alias); 29 Oct 2010 15:26:06 -0000 Received: (qmail 32613 invoked by uid 22791); 29 Oct 2010 15:26:05 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-iw0-f175.google.com (HELO mail-iw0-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 29 Oct 2010 15:25:46 +0000 Received: by iwn42 with SMTP id 42so2750411iwn.20 for ; Fri, 29 Oct 2010 08:25:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.17.203 with SMTP id t11mr3146375iba.1.1288365944781; Fri, 29 Oct 2010 08:25:44 -0700 (PDT) Received: by 10.231.144.197 with HTTP; Fri, 29 Oct 2010 08:25:44 -0700 (PDT) In-Reply-To: <4CC97076.5040506@redhat.com> References: <4CC7579A.6020408@redhat.com> <4CC97076.5040506@redhat.com> Date: Fri, 29 Oct 2010 16:06:00 -0000 Message-ID: Subject: Re: RFA: PATCH to make fold_indirect_ref_1 fold more things From: Richard Guenther To: Jason Merrill Cc: gcc-patches List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes 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 X-SW-Source: 2010-10/txt/msg02536.txt.bz2 On Thu, Oct 28, 2010 at 2:45 PM, Jason Merrill wrote: > On 10/27/2010 02:29 PM, Richard Guenther wrote: >> >> On Tue, Oct 26, 2010 at 6:35 PM, Jason Merrill =A0wrot= e: >>> >>> For constexpr I need to be able to fold some tree forms that >>> fold_indirect_ref_1 didn't handle; this patch extends it to handle >>> folding >>> POINTER_PLUS_EXPR to an ARRAY_REF, and also folding to COMPONENT_REF. >> >> I think by making this kind of transforms you are prone to bugs like >> PR44468. > > Ah, interesting. =A0But it seems to me that this case is different becaus= e we > are starting from an ADDR_EXPR around an expression of the aggregate type= in > the folded expression, not just any pointer to the aggregate type. =A0Wha= t do > you think? Hm, I think what might save you is that you only look into immediate fields (not fields in sub-structs as we originally did). Now I am concerned about sth like struct S { int i; int j; }; struct R { struct S a; int k; }; struct S s; int main() { struct R *p =3D (struct R *)&s; s.i =3D 1; s.j =3D 2; (*(struct S *)&*p).i =3D 0; if (s.i !=3D 0) abort (); return 0; } where if we end up folding the obfuscated access to p->a.i =3D 0 we will ge= nerate wrong code (one might argue that *p is invalid in C, but I'm viewing this f= rom a middle-end POV, not a C one). Now if &* is already folded it will look as p and so your code wouldn't trigger, but I guess this is just a matter of obfuscating (like using &(*p + offset)) - the point is that the actual acce= ss would change from one via struct S to one via struct R (and the alias set of struct is a subset of that of R, but not the other way around). So - what kind of testcases are you trying to handle? (the middle-end will optimize this stuff keeping TBAA info correct during forwprop) Richard. > Jason >