From patchwork Tue Jul 15 19:51:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Li X-Patchwork-Id: 4558481 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4227D9F295 for ; Tue, 15 Jul 2014 19:51:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 51B342018A for ; Tue, 15 Jul 2014 19:51:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 48DA520179 for ; Tue, 15 Jul 2014 19:51:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933004AbaGOTvE (ORCPT ); Tue, 15 Jul 2014 15:51:04 -0400 Received: from mail-qc0-f174.google.com ([209.85.216.174]:39041 "EHLO mail-qc0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933003AbaGOTvE (ORCPT ); Tue, 15 Jul 2014 15:51:04 -0400 Received: by mail-qc0-f174.google.com with SMTP id o8so2568140qcw.33 for ; Tue, 15 Jul 2014 12:51:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=mM2PsGDn62IYp8F7ATzbCHw9RSPreDMW1tzXc64+D/k=; b=ZU7jJshWuBy1b8fx9vn6aphzKA3eT6a9Iuey72dJhJheIrpV9GV780tyto0PhGdKZk +mKJe94ITvkOxhsYIMh7I5AT9mgHsgSvNwmZU8mumBP/PThQMa/4hY3SiZ6mrs5UXb8C IHLjJf32hfyZPj4TvQKZpOa3OZyX/69ZzRRLay6LsIcFDe2IYu4Gx5YLYZmC9l7Akl89 qhcFwYfx5+0okA07Eyu597KVjxDI0ibmgK+7qvn1D5GnhjWYRJng4nlXDDheth4FuGCU 1GC4ajk9hcmT5+/2ltZU0wZszcGTRO+F2TB82ihEJa5SYSjo1T+0fRJdXVgYdOliZeDe X4qw== MIME-Version: 1.0 X-Received: by 10.229.82.74 with SMTP id a10mr39142012qcl.21.1405453862152; Tue, 15 Jul 2014 12:51:02 -0700 (PDT) Received: by 10.140.102.120 with HTTP; Tue, 15 Jul 2014 12:51:02 -0700 (PDT) In-Reply-To: <1405439200-27515-1-git-send-email-jlayton@primarydata.com> References: <1405439200-27515-1-git-send-email-jlayton@primarydata.com> Date: Tue, 15 Jul 2014 12:51:02 -0700 X-Google-Sender-Auth: Na0IrkvwIVJxlWp7oV31d599r34 Message-ID: Subject: Re: [sparse PATCH RFC] Revert "Revert "sparse: Bump up sizeof(_Bool) to 8 bits"" From: Christopher Li To: Jeff Layton Cc: Linux-Sparse , Pekka Enberg Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Jul 15, 2014 at 8:46 AM, Jeff Layton wrote: > > > The problem here is that, at least with GCC on x86_64, a _Bool always > seems to be end up being 8 bits (which makes sense -- how would you get > a pointer to it otherwise?). If you declare and initialize an array like > this: > > static _Bool boolarray[3] = { > [0] = 1, > [1] = 1, > }; > > ...you get warnings like this (which are bogus): > > ./test.c:2:10: warning: Initializer entry defined twice > ./test.c:3:10: also defined here Right. The bug is in bits_to_bytes(). It round down instead of round up. "bits_in_bool" is only a default value. It can be reset to other value by the sparse application (sparse as library). So the rest of the code still need to coupe with it. How about fix bits_to_bytes() to round up: > integer division, and that causes the above bogus warning. > > Reset it back to 8 bits, and add a validation test that creates the > above array to ensure that we don't end up breaking it again. The rest of the change looks good. Thanks for the test case. My patch is not tested. If you are OK with it, submit a V2 or I can fix the change for you. Thanks Chris --- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/target.h b/target.h index 1030c7c..140df3c 100644 --- a/target.h +++ b/target.h @@ -49,7 +49,7 @@ extern int enum_alignment; static inline int bits_to_bytes(int bits) { - return bits >= 0 ? bits / bits_in_char : -1; + return bits >= 0 ? (bits + bits_in_char - 1) / bits_in_char : -1; } >