From patchwork Sat Mar 16 19:40:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 228249 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 7DF9A2C00B6 for ; Sun, 17 Mar 2013 06:41:11 +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=1364067671; 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=ddbnahv3oUw9+EczdWKp OYGq/gk=; b=umHlPU7j7nlBJPB2PO8RKHNhQjVPD4qCCpDtGJCcKOQPx9lYbPcz dW1RPibUGFvKibVFp4ewP9UAYLiG6rQLAxIV6bHaA+PthJ+INf1SpgIThLGcVPTo iCxWdPbSJUv/Vmcnu7NIhOUx+B5tnVLiuxw9RGIzPxky2L4WlWCceI0= 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=KRARA0KxdrR4iiqbEvtl8VVcEAsclJdjurZ3uS0r0+naDb9Q0FZum67O+39rBu fV7NP9lWdVsYmH4smpMkGWeYyMIuPIdJ1p+1gk2wjAweCwWy+d/drAzidy5/FmaG 1c9jf1+eSxuSj5J8mXjqi12KNlDoHU/GUw4TYvMqAUUkk=; Received: (qmail 20765 invoked by alias); 16 Mar 2013 19:40:55 -0000 Received: (qmail 20638 invoked by uid 22791); 16 Mar 2013 19:40:52 -0000 X-SWARE-Spam-Status: No, hits=-7.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, 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; Sat, 16 Mar 2013 19:40:45 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2GJegdM015841 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 16 Mar 2013 15:40:42 -0400 Received: from zalov.cz (vpn1-4-123.ams2.redhat.com [10.36.4.123]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2GJedaf026293 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 16 Mar 2013 15:40:41 -0400 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.cz (8.14.5/8.14.5) with ESMTP id r2GJecxu024889; Sat, 16 Mar 2013 20:40:39 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r2GJebxq024888; Sat, 16 Mar 2013 20:40:37 +0100 Date: Sat, 16 Mar 2013 20:40:37 +0100 From: Jakub Jelinek To: Jason Merrill , "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Don't warn for signed 1-bit enum bitfields (PR c/56566) Message-ID: <20130316194037.GT12913@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! Enum with -1 and 0 values fits nicely into 1-bit signed bitfield, but gcc was assuming that it doesn't and needs 2-bit signed bitfield for that instead. The only thing we really want to special case is that enum containing just value 0 needs 1-bit bitfield instead of 0-bit bitfield. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-03-16 Jakub Jelinek PR c/56566 * tree.c (tree_int_cst_min_precision): For integer_zerop (value) return 1 even for !unsignedp. * c-c++-common/pr56566.c: New test. Jakub --- gcc/tree.c.jj 2013-01-24 17:04:27.000000000 +0100 +++ gcc/tree.c 2013-03-08 09:19:45.608975926 +0100 @@ -6648,8 +6648,6 @@ tree_int_cst_sgn (const_tree t) unsigned int tree_int_cst_min_precision (tree value, bool unsignedp) { - int log; - /* If the value is negative, compute its negative minus 1. The latter adjustment is because the absolute value of the largest negative value is one larger than the largest positive value. This is equivalent to @@ -6659,14 +6657,14 @@ tree_int_cst_min_precision (tree value, value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value); /* Return the number of bits needed, taking into account the fact - that we need one more bit for a signed than unsigned type. */ + that we need one more bit for a signed than unsigned type. + If value is 0 or -1, the minimum precision is 1 no matter + whether unsignedp is true or false. */ if (integer_zerop (value)) - log = 0; + return 1; else - log = tree_floor_log2 (value); - - return log + 1 + !unsignedp; + return tree_floor_log2 (value) + 1 + !unsignedp; } /* Compare two constructor-element-type constants. Return 1 if the lists --- gcc/testsuite/c-c++-common/pr56566.c.jj 2013-03-08 09:31:17.265226082 +0100 +++ gcc/testsuite/c-c++-common/pr56566.c 2013-03-08 09:29:54.000000000 +0100 @@ -0,0 +1,14 @@ +/* PR c/56566 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +struct S1 { enum E1 { N1 = -1, Z1 = 0 } e : 1; }; +struct S2 { enum E2 { N2 = -1 } e : 1; }; +struct S3 { enum E3 { Z3 = 0 } e : 1; }; +struct S4 { enum E4 { N4 = -2, Z4 = 1 } e : 2; }; +struct S5 { enum E5 { N5 = -3, Z5 = 1 } e : 3; }; +struct S6 { enum E6 { N6 = -2, Z6 = 1 } e : 1; }; // { dg-warning "too small|narrower" } +struct S7 { enum E7 { N7 = -3, Z7 = 1 } e : 2; }; // { dg-warning "too small|narrower" } +struct S8 { enum E8 { Z8 = 1 } e : 1; }; +struct S9 { enum E9 { Z9 = 2 } e : 2; }; +struct S0 { enum E0 { Z0 = 2 } e : 1; }; // { dg-warning "too small|narrower" }