From patchwork Sun Mar 30 17:20:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 3909961 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 19307BF540 for ; Sun, 30 Mar 2014 17:20:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3D402202D1 for ; Sun, 30 Mar 2014 17:20:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6927A2018E for ; Sun, 30 Mar 2014 17:20:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752128AbaC3RUn (ORCPT ); Sun, 30 Mar 2014 13:20:43 -0400 Received: from mail-pb0-f44.google.com ([209.85.160.44]:35590 "EHLO mail-pb0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752092AbaC3RUn (ORCPT ); Sun, 30 Mar 2014 13:20:43 -0400 Received: by mail-pb0-f44.google.com with SMTP id rp16so7146965pbb.17 for ; Sun, 30 Mar 2014 10:20:43 -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=tsKjgpWDbsS/iDCMZRqHDY0xlxHLcmYOxSokd/OAiHk=; b=cxC9dBEKU2lUSCsE0lHFzeJHsnfcQugN1a3qeurJXq9C4nj9xTG7uu9ugdkuAGlAod LICASQszfsT8pMdX0DT85D0CeaCAJqsCrXISqcR/E/yOljDG05v4oxsuOha9ntbB0Gw+ 0XI4d1pMTnty4dLwgs7INnoSTZ7ZYCV0GGUD8xKsgwIVA0cb7TFeYbTGqCIIHJxCbj8T lLvYqzs4/zVYqhgDAoM6UyI6+dMP8wJRYFk3Kw28EJH4BF8NmA60OVuyFbfIizGz8c7c TjbvYJH/Vn3U9+rQsa1nL5O0zGLA9MvaH/MPq9GXJW7UdVwuLwGBfz1kK3AoYfjBNKJ1 V7MQ== 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=tsKjgpWDbsS/iDCMZRqHDY0xlxHLcmYOxSokd/OAiHk=; b=DaD2kuAo6267WJJ+6Bqr4puSErJBdAUvdrR5bk3msi0anDP+y6ktpfNnOFs8wEGfw3 fM4pz/BxGoV4XVNyM6Y3N9pUfAjBd2Ylni7wVOBk9B6M/fH2t31qEeTuKqpTg2vBM8Ml Temi8CxuxAYtl1cf6lklB9oHqJDkmEO6CC15M= X-Received: by 10.66.228.37 with SMTP id sf5mr20389035pac.19.1396200043008; Sun, 30 Mar 2014 10:20:43 -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 vd8sm28340211pac.12.2014.03.30.10.20.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Mar 2014 10:20:42 -0700 (PDT) Date: Sun, 30 Mar 2014 10:20:41 -0700 (PDT) From: Linus Torvalds To: Christopher Li , Hans Verkuil cc: Linux-Sparse Subject: [PATCH 1/2] Add warning about duplicate initializers 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 09:49:13 -0700 Subject: [PATCH 1/2] Add warning about duplicate initializers Noticed this while looking at an independent bug reported by Hans Verkuil. Signed-off-by: Linus Torvalds Reviewed-by: Josh Triplett --- This is not a big deal, but the next patch will make us take the array size from any initializer, so let's warn on multiple initializers. evaluate.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/evaluate.c b/evaluate.c index 66556150ddac..8a53b3e884e0 100644 --- a/evaluate.c +++ b/evaluate.c @@ -3043,10 +3043,18 @@ static void check_duplicates(struct symbol *sym) { int declared = 0; struct symbol *next = sym; + int initialized = sym->initializer != NULL; while ((next = next->same_symbol) != NULL) { const char *typediff; evaluate_symbol(next); + if (initialized && next->initializer) { + sparse_error(sym->pos, "symbol '%s' has multiple initializers (originally initialized at %s:%d)", + show_ident(sym->ident), + stream_name(next->pos.stream), next->pos.line); + /* Only warn once */ + initialized = 0; + } declared++; typediff = type_difference(&sym->ctype, &next->ctype, 0, 0); if (typediff) {