From patchwork Thu Jul 31 18:39:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 4658591 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 450919F36A for ; Thu, 31 Jul 2014 18:39:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2712120138 for ; Thu, 31 Jul 2014 18:39:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CCCE12012E for ; Thu, 31 Jul 2014 18:39:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752080AbaGaSjM (ORCPT ); Thu, 31 Jul 2014 14:39:12 -0400 Received: from mail-vc0-f177.google.com ([209.85.220.177]:53031 "EHLO mail-vc0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751997AbaGaSjL (ORCPT ); Thu, 31 Jul 2014 14:39:11 -0400 Received: by mail-vc0-f177.google.com with SMTP id hy4so4801225vcb.36 for ; Thu, 31 Jul 2014 11:39:03 -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=cTzvvi093LRdqozbbYGrJ24OyWqkbR3FRA8T8rCcxqg=; b=pjVUz+Aiv8B8KUkoHQiEBUpnv8KQlUE9dNCDS+J6DoImczB/LSHXsAFkX7+/Z6N0Fn bokjiyJguzExbYCf0SDXsC0XQO9a67fiWjSGQ5pKdAIwQbra2ynBQGup13Z5FyvjFQbW fD6IyPbFFPTK/7F/bLbRATMgAR+hOCHE+qbNjWNwFSXfaCI7rzAb8pigoMGj+6IMpM4u MEFUSeJepzIaRPlYp34m6Od+RE44Q6j4bGnZg6WZrE+iTiZI7Xzk261OA/M+C2ViO6VM Zo8YNyXlaSkg+PHiLDN+HMR0rquu5PfLw0VFfBV8xLVI00WQktq+II5SH+QHLhLQeUEG 3CtA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=cTzvvi093LRdqozbbYGrJ24OyWqkbR3FRA8T8rCcxqg=; b=WswDyyUvoom0GQZ1bbIAltJzLiQWrVscOW2wUpTLiJ5xZUarDgoM2+Q5T7ATcmRe7Y 4Fyu/mS1TboJFIZnjYI3SZCfuH+5P1GeDDLeYbitiHF7ZBigsUoqhdMuobdYUutWLZzB NIwRN9g/66xbYbYbs/451qBNktlO0ClurChl8= MIME-Version: 1.0 X-Received: by 10.52.129.165 with SMTP id nx5mr17882vdb.25.1406831943546; Thu, 31 Jul 2014 11:39:03 -0700 (PDT) Received: by 10.221.58.194 with HTTP; Thu, 31 Jul 2014 11:39:02 -0700 (PDT) In-Reply-To: <20140731181006.GA13180@cloud> References: <20140731181006.GA13180@cloud> Date: Thu, 31 Jul 2014 11:39:02 -0700 X-Google-Sender-Auth: mvnYhpvBtLnifOPOhpn3_QxWIOU Message-ID: Subject: Re: Designated initializers for fields in anonymous structs and unions From: Linus Torvalds To: Josh Triplett Cc: Sparse Mailing-list , John Keeping 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.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,T_TVD_MIME_EPI, 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 Thu, Jul 31, 2014 at 11:10 AM, wrote: > GCC 4.6 and newer support initializing designated initializers for fields in > anonymous structs and unions. However, sparse does not. I sent patches for this back in April, based on a report from Hans Verkuil. My patches fixed the parsing part, but had a (known) bug with getting the offsets right, so your test-case actually retulrs in t.c:23:6: warning: Initializer entry defined twice t.c:24:6: also defined here because the offset calculation for "b" was wrong, and as a result sparse thinks "a" and "b" overlap. John Keeping had a patch that tried to fix that too. I think they are all in https://github.com/johnkeeping/sparse/ but not in the "official" sparse tree, which hasn't seen any work since January afaik. Maybe there are other trees than John's.. I'm attaching my set of sparse patches from early April in case anybody wants to look at them. No guarantees, and as mentioned there's t least an offset bug, but they should be an improvement, at least. Linus From c011597ff67765da5dacb472ddbd69dc4b51416d Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 1 Apr 2014 10:20:34 -0700 Subject: [PATCH 4/4] Fix scoping of extern symbols in block scope We'd only match them with other symbols marked 'extern', but really, we should match them with any top-level non-static symbol. Signed-off-by: Linus Torvalds --- symbol.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/symbol.c b/symbol.c index 4b91abd8021e..c5e4784734a8 100644 --- a/symbol.c +++ b/symbol.c @@ -576,11 +576,15 @@ void check_declaration(struct symbol *sym) sym->same_symbol = next; return; } - if (sym->ctype.modifiers & next->ctype.modifiers & MOD_EXTERN) { - if ((sym->ctype.modifiers ^ next->ctype.modifiers) & MOD_INLINE) - continue; - sym->same_symbol = next; - return; + /* Extern in block level matches a TOPLEVEL non-static symbol */ + if (sym->ctype.modifiers & MOD_EXTERN) { + if ((next->ctype.modifiers & (MOD_TOPLEVEL|MOD_STATIC)) == MOD_TOPLEVEL) { + /* FIXME? Differs in 'inline' only? Why does that matter? */ + if ((sym->ctype.modifiers ^ next->ctype.modifiers) & MOD_INLINE) + continue; + sym->same_symbol = next; + return; + } } if (!Wshadow || warned) -- 2.0.1.427.gc47372d