From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15920 invoked by alias); 15 Jan 2014 21:23:15 -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 15910 invoked by uid 89); 15 Jan 2014 21:23:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 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, 15 Jan 2014 21:23:13 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1W3XvZ-0004DH-BJ from joseph_myers@mentor.com ; Wed, 15 Jan 2014 13:23:09 -0800 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 15 Jan 2014 13:23:09 -0800 Received: from digraph.polyomino.org.uk (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.2.247.3; Wed, 15 Jan 2014 21:23:07 +0000 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.76) (envelope-from ) id 1W3XvW-0006Pv-3N; Wed, 15 Jan 2014 21:23:06 +0000 Date: Wed, 15 Jan 2014 21:23:00 -0000 From: "Joseph S. Myers" To: Marek Polacek CC: Jakub Jelinek , GCC Patches , Richard Biener , Jason Merrill Subject: Re: [C PATCH] Disallow subtracting pointers to empty structs (PR c/58346) In-Reply-To: <20140115135037.GL4458@redhat.com> Message-ID: References: <20140113163226.GD4458@redhat.com> <20140113164859.GE4458@redhat.com> <20140113204839.GF4458@redhat.com> <20140115102737.GJ4458@redhat.com> <20140115103540.GY892@tucnak.redhat.com> <20140115135037.GL4458@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-SW-Source: 2014-01/txt/msg00925.txt.bz2 On Wed, 15 Jan 2014, Marek Polacek wrote: > +/* Return true if T is a pointer to a zero-sized struct/union. */ > + > +bool > +pointer_to_zero_sized_aggr_p (tree t) > +{ > + t = strip_pointer_operator (t); > + return ((RECORD_OR_UNION_TYPE_P (t) || TREE_CODE (t) == ARRAY_TYPE) > + && TYPE_SIZE (t) > + && integer_zerop (TYPE_SIZE (t))); Why have the (RECORD_OR_UNION_TYPE_P (t) || TREE_CODE (t) == ARRAY_TYPE) check at all? It may well be the case that those are the only kinds of types that can have zero size here, but the principle of this error applies to anything with zero size so it would seem best not to have that part of the check at all. strip_pointer_operator seems wrong here. It recursively removes an arbitrary number of pointer type derivations - but where the types are pointer to pointer to zero-size, arithmetic is perfectly valid (so you should have a test that such cases are still accepted, where this patch version would have rejected them). I believe this function should return true if the argument is a pointer (to anything) and after removal of exactly one level of pointer type derivation, the result has zero size (constant zero - also add a test that the array case where the size is a const int initialized to 0 is not, for C, rejected, as those are VLAs in C terms). -- Joseph S. Myers joseph@codesourcery.com