From patchwork Sun Mar 30 17:22:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 3909971 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 3F589BF540 for ; Sun, 30 Mar 2014 17:22:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6130A202EB for ; Sun, 30 Mar 2014 17:22:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 82E20202D1 for ; Sun, 30 Mar 2014 17:22:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752064AbaC3RWi (ORCPT ); Sun, 30 Mar 2014 13:22:38 -0400 Received: from mail-pb0-f53.google.com ([209.85.160.53]:57760 "EHLO mail-pb0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751982AbaC3RWh (ORCPT ); Sun, 30 Mar 2014 13:22:37 -0400 Received: by mail-pb0-f53.google.com with SMTP id rp16so7151005pbb.12 for ; Sun, 30 Mar 2014 10:22:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:user-agent:mime-version :content-type; bh=H7uml5uc9wvKVYVr6mhOpDBMf1+EY7d2benDoEL2sQ0=; b=CB1Ew4NQgT1Chf7DCdGs/FlnkSK+lbLoTYAdISvXVnE4ehW9NKGUuUnrMT5b2+zcxl jNmh2wyQ7JxIWnesMDMPBsBIZbMlyOsXheRDN/TWZW/BLYYcFSDLdiwMpLIcEQ8UOmay i4uJE8tmr5GOnwxdSy8SDMrrGQFMcLxIeX05KPl5foNgBNuAkx3Ph7OI711+PYMXhzzE lOz/Vj6Gl1qhzjyDWEAOaSwyCyIPNT2p1Aw18QAunGzicGVxzE2AjRMpyEA6lgh17t/O E2JzRX62OL/DnJPen+qL4xJ/XvPUtIMUo9ng1D3XvU9LLt5DrApHXfoDPdEVn0f65qwg s5HA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=sender:date:from:to:cc:subject:message-id:user-agent:mime-version :content-type; bh=H7uml5uc9wvKVYVr6mhOpDBMf1+EY7d2benDoEL2sQ0=; b=I8eueGqB739IQkRHbRqplW1SNL+7FcTxGb8y2EtJNtf6pMmXsew+09Vy6aKszvPa/r jgN9KkU/3fJsqE2qF2Q2ZJhzTrZzTGehYRX0MmIPqahpoHBfNnGtc06je9Jk23rZu+35 3ITuK4JEWv6RQCB0tbgOqFZ9BrZBa4m0vBbE8= X-Received: by 10.66.20.10 with SMTP id j10mr20255212pae.11.1396200157010; Sun, 30 Mar 2014 10:22:37 -0700 (PDT) Received: from i7.lan (c-24-22-13-12.hsd1.or.comcast.net. [24.22.13.12]) by mx.google.com with ESMTPSA id om6sm38213391pbc.43.2014.03.30.10.22.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Mar 2014 10:22:36 -0700 (PDT) Date: Sun, 30 Mar 2014 10:22:35 -0700 (PDT) From: Linus Torvalds To: Christopher Li , Hans Verkuil cc: Linux-Sparse Subject: [PATCH 2/2] Use any previous initializer to size a symbol Message-ID: User-Agent: Alpine 2.11 (LFD 23 2013-08-11) MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Spam-Status: No, score=-7.3 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 From: Linus Torvalds Date: Sun, 30 Mar 2014 10:13:54 -0700 Subject: [PATCH 2/2] Use any previous initializer to size a symbol When we size a symbol, we only have one initializer per symbol, but we may have multiple symbol declarations for the same symbol. So make sure to walk the "same_symbol" chain to find the initializer, rather than assuming it is attached to the current declaration. Reported-by: Hans Verkuil Signed-off-by: Linus Torvalds --- This seems to be the simplest approach. Chris, what was your concern about scoping? The "same_symbol" list should already take scoping into account. symbol.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/symbol.c b/symbol.c index eb6e1215ee87..4b91abd8021e 100644 --- a/symbol.c +++ b/symbol.c @@ -354,6 +354,15 @@ static int count_array_initializer(struct symbol *t, struct expression *expr) return nr; } +static struct expression *get_symbol_initializer(struct symbol *sym) +{ + do { + if (sym->initializer) + return sym->initializer; + } while ((sym = sym->same_symbol) != NULL); + return NULL; +} + static struct symbol * examine_node_type(struct symbol *sym) { struct symbol *base_type = examine_base_type(sym); @@ -376,12 +385,15 @@ static struct symbol * examine_node_type(struct symbol *sym) sym->ctype.alignment = alignment; /* Unsized array? The size might come from the initializer.. */ - if (bit_size < 0 && base_type->type == SYM_ARRAY && sym->initializer) { - struct symbol *node_type = base_type->ctype.base_type; - int count = count_array_initializer(node_type, sym->initializer); - - if (node_type && node_type->bit_size >= 0) - bit_size = node_type->bit_size * count; + if (bit_size < 0 && base_type->type == SYM_ARRAY) { + struct expression *initializer = get_symbol_initializer(sym); + if (initializer) { + struct symbol *node_type = base_type->ctype.base_type; + int count = count_array_initializer(node_type, initializer); + + if (node_type && node_type->bit_size >= 0) + bit_size = node_type->bit_size * count; + } } sym->bit_size = bit_size;