From patchwork Tue Dec 11 14:21:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 205239 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]) by ozlabs.org (Postfix) with SMTP id E0F9D2C008A for ; Wed, 12 Dec 2012 01:21:35 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1355840497; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=HLeHeBZA/+4y2L1EoTIf C0kMvJI=; b=Voyg6rhPSpOsO8fY7CmqlDKzxFdnEKku4ZS2n6EHjYJZRTBUgew1 90+9P9zDUCvg3a0AgWX85yQIYm9LVZ0z5EjAhguC1aNlmEr9cmfQBT1LGsp24iXl /OgBp1J+qliAd/UCa2wjM2Q0nH98ziDfwdr3qcubJ4MjxrW0gZ2o49Y= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=yglZJt6oDgIyNQO31n9eqiAr95MS7KMGshFtbOuRT27exAOAdgXGQY41ltUUIA nJ2OzMX43wlaOyNFE0zRU8bhQLOhoIxSis3wmc0IeKslYWDRFpVy0FS95NPaaHZn HgcG/WsQc6+pkxwu6TaXEMk/gK9q6FDIQRTYUiN/dxmNA=; Received: (qmail 25906 invoked by alias); 11 Dec 2012 14:21:24 -0000 Received: (qmail 25832 invoked by uid 22791); 11 Dec 2012 14:21:22 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 11 Dec 2012 14:21:12 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBBELBBH000819 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Dec 2012 09:21:11 -0500 Received: from zalov.redhat.com (vpn1-5-246.ams2.redhat.com [10.36.5.246]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qBBEL8fn009754 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 11 Dec 2012 09:21:10 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id qBBEL85Q027940; Tue, 11 Dec 2012 15:21:08 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id qBBEL78l027939; Tue, 11 Dec 2012 15:21:07 +0100 Date: Tue, 11 Dec 2012 15:21:07 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Xfail builtin-object-size-8.c test (PR tree-optimization/54570) Message-ID: <20121211142107.GP2315@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! As discussed on IRC, fixing this issue is probably 4.9 material, we have some plans, but not for 4.8. What GCC generates is actually not incorrect, given __builtin_object_size (x, 1) being a high bound, it is just larger than strictly required, but I hope it won't trigger very much on real-world code, where it could mean less strict -D_FORTIFY_SOURCE=2 protection. The following patch xfails the problematic testcase and instead adds a new testcase which tests the same things, but doesn't test interaction of different __builtin_object_size calls (for different fields) from the same pointer. Tested on x86_64-linux, ok for trunk? 2012-12-11 Jakub Jelinek PR tree-optimization/54570 * gcc.dg/builtin-object-size-8.c: Xfail. * gcc.dg/builtin-object-size-13.c: New test. Jakub --- gcc/testsuite/gcc.dg/builtin-object-size-8.c.jj 2009-07-20 20:41:51.000000000 +0200 +++ gcc/testsuite/gcc.dg/builtin-object-size-8.c 2012-12-11 15:13:59.646748335 +0100 @@ -1,4 +1,4 @@ -/* { dg-do run } */ +/* { dg-do run { xfail *-*-* } } */ /* { dg-options "-O2" } */ typedef __SIZE_TYPE__ size_t; --- gcc/testsuite/gcc.dg/builtin-object-size-13.c.jj 2012-12-11 15:10:48.046891600 +0100 +++ gcc/testsuite/gcc.dg/builtin-object-size-13.c 2012-12-11 15:10:24.000000000 +0100 @@ -0,0 +1,351 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +typedef __SIZE_TYPE__ size_t; +extern void *malloc (size_t); +extern void free (void *); +extern void abort (void); + +union A +{ + int a1; + char a2[3]; +}; + +union B +{ + long long b1; + union A b2; +}; + +struct C +{ + int c1; + union A c2; +}; + +struct D +{ + int d1; + union B d2; +}; + +union E +{ + struct C e1; + char e2[3]; +}; + +union F +{ + int f1; + struct D f2; +}; + +struct G +{ + union A g1; + char g2; +}; + +struct H +{ + int h1; + union E h2; +}; + +#define T(X, S0, S1) \ + if (__builtin_object_size (X, 0) != (S0)) \ + abort (); \ + if (__builtin_object_size (X, 1) != (S1)) \ + abort (); \ + if (__builtin_object_size (X, 2) != (S0)) \ + abort (); \ + if (__builtin_object_size (X, 3) != (S1)) \ + abort () +#define TS(X, S0) T(&X, S0, sizeof (X)) +#define TA(X, S0, S1) \ + T(X, S0, S1); T(&X[0], S0, S1); T(&X[1], (S0) - 1, (S1) - 1) +#define TF(X, S0) TA(X, S0, S0) + +int +main (void) +{ + size_t s, o, o2; + + s = sizeof (union A); + o = 0; + union A *a1 = malloc (s); + union A *a2 = malloc (o + 212); + TS (a1->a1, s); + s = o + 212; + TS (a2->a1, s); + free (a2); + free (a1); + s = sizeof (union A); + o = 0; + a1 = malloc (s); + a2 = malloc (o + 212); + TF (a1->a2, s); + s = o + 212; + TF (a2->a2, s); + free (a2); + free (a1); + + s = sizeof (union B); + o = 0; + union B *b1 = malloc (s); + union B *b2 = malloc (o + 212); + TS (b1->b1, s); + s = o + 212; + TS (b2->b1, s); + free (b2); + free (b1); + s = sizeof (union B); + o = 0; + b1 = malloc (s); + b2 = malloc (o + 212); + TS (b1->b2.a1, s); + s = o + 212; + TS (b2->b2.a1, s); + free (b2); + free (b1); + s = sizeof (union B); + o = 0; + b1 = malloc (s); + b2 = malloc (o + 212); + TF (b1->b2.a2, s); + s = o + 212; + TF (b2->b2.a2, s); + free (b2); + free (b1); + + s = sizeof (struct C); + o = __builtin_offsetof (struct C, c2); + struct C *c1 = malloc (s); + struct C *c2 = malloc (o + 212); + TS (c1->c1, s); + s = o + 212; + TS (c2->c1, s); + free (c2); + free (c1); + s = sizeof (struct C); + o = __builtin_offsetof (struct C, c2); + c1 = malloc (s); + c2 = malloc (o + 212); + TS (c1->c2.a1, s - o); + s = o + 212; + TS (c2->c2.a1, s - o); + free (c2); + free (c1); + s = sizeof (struct C); + o = __builtin_offsetof (struct C, c2); + c1 = malloc (s); + c2 = malloc (o + 212); + TF (c1->c2.a2, s - o); + s = o + 212; + TF (c2->c2.a2, s - o); + free (c2); + free (c1); + + s = sizeof (struct D); + o = __builtin_offsetof (struct D, d2); + struct D *d1 = malloc (s); + struct D *d2 = malloc (o + 212); + TS (d1->d1, s); + s = o + 212; + TS (d2->d1, s); + free (d2); + free (d1); + s = sizeof (struct D); + o = __builtin_offsetof (struct D, d2); + d1 = malloc (s); + d2 = malloc (o + 212); + TS (d1->d2.b1, s - o); + s = o + 212; + TS (d2->d2.b1, s - o); + free (d2); + free (d1); + s = sizeof (struct D); + o = __builtin_offsetof (struct D, d2); + d1 = malloc (s); + d2 = malloc (o + 212); + TS (d1->d2.b2.a1, s - o); + s = o + 212; + TS (d2->d2.b2.a1, s - o); + free (d2); + free (d1); + s = sizeof (struct D); + o = __builtin_offsetof (struct D, d2); + d1 = malloc (s); + d2 = malloc (o + 212); + TF (d1->d2.b2.a2, s - o); + s = o + 212; + TF (d2->d2.b2.a2, s - o); + free (d2); + free (d1); + + s = sizeof (union E); + o = __builtin_offsetof (union E, e1.c2); + union E *e1 = malloc (s); + union E *e2 = malloc (o + 212); + TS (e1->e1.c1, s); + s = o + 212; + TS (e2->e1.c1, s); + free (e2); + free (e1); + s = sizeof (union E); + o = __builtin_offsetof (union E, e1.c2); + e1 = malloc (s); + e2 = malloc (o + 212); + TS (e1->e1.c2.a1, s - o); + s = o + 212; + TS (e2->e1.c2.a1, s - o); + free (e2); + free (e1); + s = sizeof (union E); + o = __builtin_offsetof (union E, e1.c2); + e1 = malloc (s); + e2 = malloc (o + 212); + TF (e1->e1.c2.a2, s - o); + s = o + 212; + TF (e2->e1.c2.a2, s - o); + free (e2); + free (e1); + s = sizeof (union E); + o = __builtin_offsetof (union E, e1.c2); + e1 = malloc (s); + e2 = malloc (o + 212); + TF (e1->e2, s); + s = o + 212; + TF (e2->e2, s); + free (e2); + free (e1); + + s = sizeof (union F); + o = __builtin_offsetof (union F, f2.d2); + union F *f1 = malloc (s); + union F *f2 = malloc (o + 212); + TS (f1->f1, s); + s = o + 212; + TS (f2->f1, s); + free (f2); + free (f1); + s = sizeof (union F); + o = __builtin_offsetof (union F, f2.d2); + f1 = malloc (s); + f2 = malloc (o + 212); + TS (f1->f2.d1, s); + s = o + 212; + TS (f2->f2.d1, s); + free (f2); + free (f1); + s = sizeof (union F); + o = __builtin_offsetof (union F, f2.d2); + f1 = malloc (s); + f2 = malloc (o + 212); + TS (f1->f2.d2.b1, s - o); + s = o + 212; + TS (f2->f2.d2.b1, s - o); + free (f2); + free (f1); + s = sizeof (union F); + o = __builtin_offsetof (union F, f2.d2); + f1 = malloc (s); + f2 = malloc (o + 212); + TS (f1->f2.d2.b2.a1, s - o); + s = o + 212; + TS (f2->f2.d2.b2.a1, s - o); + free (f2); + free (f1); + s = sizeof (union F); + o = __builtin_offsetof (union F, f2.d2); + f1 = malloc (s); + f2 = malloc (o + 212); + TF (f1->f2.d2.b2.a2, s - o); + s = o + 212; + TF (f2->f2.d2.b2.a2, s - o); + free (f2); + free (f1); + + s = sizeof (struct G); + o = __builtin_offsetof (struct G, g2); + struct G *g1 = malloc (s); + struct G *g2 = malloc (o + 212); + TS (g1->g1.a1, s); + s = o + 212; + TS (g2->g1.a1, s); + free (g2); + free (g1); + s = sizeof (struct G); + o = __builtin_offsetof (struct G, g2); + g1 = malloc (s); + g2 = malloc (o + 212); + TA (g1->g1.a2, s, sizeof (g1->g1.a2)); + s = o + 212; + TA (g2->g1.a2, s, sizeof (g1->g1.a2)); + free (g2); + free (g1); + s = sizeof (struct G); + o = __builtin_offsetof (struct G, g2); + g1 = malloc (s); + g2 = malloc (o + 212); + TS (g1->g2, s - o); + s = o + 212; + TS (g2->g2, s - o); + free (g2); + free (g1); + + s = sizeof (struct H); + o = __builtin_offsetof (struct H, h2); + o2 = __builtin_offsetof (struct H, h2.e1.c2); + struct H *h1 = malloc (s); + struct H *h2 = malloc (o2 + 212); + TS (h1->h1, s); + s = o2 + 212; + TS (h2->h1, s); + free (h2); + free (h1); + s = sizeof (struct H); + o = __builtin_offsetof (struct H, h2); + o2 = __builtin_offsetof (struct H, h2.e1.c2); + h1 = malloc (s); + h2 = malloc (o2 + 212); + TS (h1->h2.e1.c1, s - o); + s = o2 + 212; + TS (h2->h2.e1.c1, s - o); + free (h2); + free (h1); + s = sizeof (struct H); + o = __builtin_offsetof (struct H, h2); + o2 = __builtin_offsetof (struct H, h2.e1.c2); + h1 = malloc (s); + h2 = malloc (o2 + 212); + TS (h1->h2.e1.c2.a1, s - o2); + s = o2 + 212; + TS (h2->h2.e1.c2.a1, s - o2); + free (h2); + free (h1); + s = sizeof (struct H); + o = __builtin_offsetof (struct H, h2); + o2 = __builtin_offsetof (struct H, h2.e1.c2); + h1 = malloc (s); + h2 = malloc (o2 + 212); + TA (h1->h2.e1.c2.a2, s - o2, sizeof (h1->h2.e1.c2.a2)); + s = o2 + 212; + TA (h2->h2.e1.c2.a2, s - o2, sizeof (h2->h2.e1.c2.a2)); + free (h2); + free (h1); + s = sizeof (struct H); + o = __builtin_offsetof (struct H, h2); + o2 = __builtin_offsetof (struct H, h2.e1.c2); + h1 = malloc (s); + h2 = malloc (o2 + 212); + TF (h1->h2.e2, s - o); + s = o2 + 212; + TF (h2->h2.e2, s - o); + free (h2); + free (h1); + + return 0; +}