From patchwork Wed Feb 22 15:30:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9587141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 176436051E for ; Wed, 22 Feb 2017 16:31:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1F5E28616 for ; Wed, 22 Feb 2017 16:31:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD44428648; Wed, 22 Feb 2017 16:31:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75BD128616 for ; Wed, 22 Feb 2017 16:31:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932523AbdBVQbe (ORCPT ); Wed, 22 Feb 2017 11:31:34 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33386 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932833AbdBVQb3 (ORCPT ); Wed, 22 Feb 2017 11:31:29 -0500 Received: by mail-wm0-f68.google.com with SMTP id v77so1319406wmv.0 for ; Wed, 22 Feb 2017 08:31:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kiiwOU5CiBKF4QSUWoUD3M/O5qzCeQehSXkpyJv4vCk=; b=nj+LsSprAD4/zgVbJc/U0HttB+5FvRSa5HYB8ZvjsJBDIguHf9irjHVOsOHst8sDgw 9Me9YkDFDqooEudgX69YRF08U/79U/9WYslnH+CFrEy0KUygPAdAxSluQjiDxTcWFGUt ajhUzH66ra3sT4f6gL4V1usewrsvpeCVwHEJ4JLWGoySPZl57BIz1doTqXSBouuLblH8 fouMaAWy08SU0hJugUWtlkYg+zLNGzTVrY8XyNkfB0UzP0kVxi/3Xz7l0RtxNIkWxepl wJrdvEuQufwNbKzW1aMsMvHQOB5Rz8haFBcjdpdh48MKpHIjqiRG0DOQOlviV6x67P3k pe7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kiiwOU5CiBKF4QSUWoUD3M/O5qzCeQehSXkpyJv4vCk=; b=qH6OXpFzF7LY1pvNdfKaSJ27WAin97FxJb/J4fsK2fxrfPDIX+YWz6JzZVM6eCp/y5 DdLDTs9Rr0nYZYG6OCYqHvhBWxnbBZl8iG7j5pM/sraBfguniE/yoPIZLqFOU4Bu7nRs 9q1cFwl0+nA4CrF2AuK7uhwuGjmIQpBT6+T2OgPC1kSpogjP96pqkbMnMd5xCQdwGd9o svoqDyT2/rAazvVRn+YdDQCYzykOAo2s8RLg4ocx/cKOs4aZyO1fc7YOlSYyEAix5TkX 7lLY9KOwCoLrzSid+p2qqYCXXzL9fB2mXLnYMmxPfY4qi7g7RBGxMEh3XKPxlMpxx98c G9FA== X-Gm-Message-State: AMke39nt5abdxc3aee5E6vRUJcyj2XE79v6LiOoiyFqnhyP+P6lbS+JFHXYLM1W4p7K9HA== X-Received: by 10.28.51.72 with SMTP id z69mr3254985wmz.38.1487777424665; Wed, 22 Feb 2017 07:30:24 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:8de:6300:cc39:b82b:b425:b146]) by smtp.gmail.com with ESMTPSA id b87sm2510346wmi.0.2017.02.22.07.30.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Feb 2017 07:30:24 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Mark Rutland , Stephen Boyd , Will Deacon , Luc Van Oostenryck Subject: [PATCH 4/5] fix checking of overlapping initializer Date: Wed, 22 Feb 2017 16:30:05 +0100 Message-Id: <20170222153006.3035-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170222153006.3035-1-luc.vanoostenryck@gmail.com> References: <20170221110355.GD300@arm.com> <20170222153006.3035-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The current routine checking if some initializers overlap with each others only check the offset of the initialierd fields, not taking in account that array elements can be initialized by range with the '[a ... b]' notation. Fix this by changing the check so that now we compare the offset of the current field with the end of the previous one. Signed-off-by: Luc Van Oostenryck --- expand.c | 25 +++++++++++++++++++++++-- validation/field-override.c | 1 - 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/expand.c b/expand.c index 48cfa33d8..80699c4d6 100644 --- a/expand.c +++ b/expand.c @@ -896,6 +896,20 @@ static unsigned long bit_offset(const struct expression *expr) return offset; } +static unsigned long bit_range(const struct expression *expr) +{ + unsigned long range = 0; + unsigned long size = 0; + while (expr->type == EXPR_POS) { + unsigned long nr = expr->init_nr; + size = expr->ctype->bit_size; + range += (nr - 1) * size; + expr = expr->init_expr; + } + range += size; + return range; +} + static int compare_expressions(const void *_a, const void *_b) { const struct expression *a = _a; @@ -914,21 +928,28 @@ static void sort_expression_list(struct expression_list **list) static void verify_nonoverlapping(struct expression_list **list) { struct expression *a = NULL; + unsigned long max = 0; struct expression *b; if (!Woverride_init) return; FOR_EACH_PTR(*list, b) { + unsigned long off, end; if (!b->ctype || !b->ctype->bit_size) continue; - if (a && bit_offset(a) == bit_offset(b)) { + off = bit_offset(b); + if (a && off < max) { warning(a->pos, "Initializer entry defined twice"); info(b->pos, " also defined here"); if (!Woverride_init_all) return; } - a = b; + end = off + bit_range(b); + if (end > max) { + max = end; + a = b; + } } END_FOR_EACH_PTR(b); } diff --git a/validation/field-override.c b/validation/field-override.c index cae30b4a2..5b77af73e 100644 --- a/validation/field-override.c +++ b/validation/field-override.c @@ -69,7 +69,6 @@ static struct s b[2] = { /* * check-name: field-override * check-command: sparse -Woverride-init -Woverride-init-all $file - * check-known-to-fail * * check-error-start field-override.c:2:10: warning: Initializer entry defined twice