From patchwork Wed Jul 16 21:39:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Li X-Patchwork-Id: 4571511 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4D5BFC0514 for ; Wed, 16 Jul 2014 21:39:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7CDEE2017D for ; Wed, 16 Jul 2014 21:39:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 97E692010F for ; Wed, 16 Jul 2014 21:39:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752598AbaGPVjR (ORCPT ); Wed, 16 Jul 2014 17:39:17 -0400 Received: from mail-qc0-f182.google.com ([209.85.216.182]:45933 "EHLO mail-qc0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751758AbaGPVjP (ORCPT ); Wed, 16 Jul 2014 17:39:15 -0400 Received: by mail-qc0-f182.google.com with SMTP id r5so1366970qcx.27 for ; Wed, 16 Jul 2014 14:39:14 -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=Tn2TLEX6OCcn7KYG6AoJUn0FXMDKrX6WdYfy4909oiQ=; b=o66ne70QbqKGrtvBaW0JSD3ZI3bm+pfUOcZoCj7NRdUZHCnBKRAxhtO1mowAdYbayA ouAcOmL0fJj/QoEftXZXWmOlaU0jpWEgz8FIO2i+40JK+95eN8BaQZrcjqhah5E55cLx I5sIWTsSmH4rUy0bzmN8JWnRocSDSbDJuy+8YrAPhIlbQj/kIqjtlEgG52ll1ME5k7ux Vie7YoUrJMmPjvlX2qAvYd0xt2PfeRhaHueSmsoGPtqLyCCq7op50EKjFRia2evuT0Nx xDYgicLmFImKKHUa53ZeWbTgfr6R0N0b/jd1em/khKPJRiEgt3Uz0cW0cI+0AdsqJQRM ko4A== MIME-Version: 1.0 X-Received: by 10.224.129.201 with SMTP id p9mr49306524qas.45.1405546754202; Wed, 16 Jul 2014 14:39:14 -0700 (PDT) Received: by 10.140.102.120 with HTTP; Wed, 16 Jul 2014 14:39:14 -0700 (PDT) In-Reply-To: <20140716122455.33df512f@tlielax.poochiereds.net> References: <1405439200-27515-1-git-send-email-jlayton@primarydata.com> <20140715222350.028a7bf6@f20.localdomain> <20140716122455.33df512f@tlielax.poochiereds.net> Date: Wed, 16 Jul 2014 14:39:14 -0700 X-Google-Sender-Auth: gX1kQB-dDbG20FlUcxZELTMthZk 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=unavailable 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 Wed, Jul 16, 2014 at 9:24 AM, Jeff Layton wrote: > > Thanks, I think I might have found it. init_ctype tries to correct for > the fact that bits_to_bytes rounds up instead of down. With the > corrected function, we don't need that correction anymore. > > I'll send the v2 patch soon, which seems to do the right thing. > Great catch. I was looking at the it last night but haven't found the cause. It was not cause by the array element alignment, which I attach a purposed patch. I will apply your V2 patch and the fix for the array. Every thing should be happy now. Chris round up for array element size to byte align When layout the array element, the element size should round up to byte align. Signed-off-by: Christopher Li #endif --- 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/evaluate.c b/evaluate.c index 7ce8c55..03992d0 100644 --- a/evaluate.c +++ b/evaluate.c @@ -2302,7 +2302,7 @@ static struct expression *check_designators(struct expression *e, } type = ctype->ctype.base_type; if (ctype->bit_size >= 0 && type->bit_size >= 0) { - unsigned offset = e->idx_to * type->bit_size; + unsigned offset = array_element_offset(type->bit_size, e->idx_to); if (offset >= ctype->bit_size) { err = "index out of bounds in"; break; diff --git a/symbol.c b/symbol.c index 1a3df63..a697627 100644 --- a/symbol.c +++ b/symbol.c @@ -234,7 +234,8 @@ static struct symbol * examine_array_type(struct symbol *sym) return sym; if (array_size) { - bit_size = base_type->bit_size * get_expression_value_silent(array_size); + bit_size = array_element_offset(base_type->bit_size, + get_expression_value_silent(array_size)); if (array_size->type != EXPR_VALUE) { if (Wvla) warning(array_size->pos, "Variable length array is used."); diff --git a/target.h b/target.h index 140df3c..78c85cf 100644 --- a/target.h +++ b/target.h @@ -57,4 +57,12 @@ static inline int bytes_to_bits(int bytes) return bytes * bits_in_char; } +static inline unsigned long array_element_offset(unsigned long base_bits, int idx) +{ + int fragment = base_bits % bits_in_char; + if (fragment) + base_bits += bits_in_char - fragment; + return base_bits * idx; +} +