From patchwork Sat Aug 2 18:09:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Li X-Patchwork-Id: 4665241 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 C2A479F319 for ; Sat, 2 Aug 2014 18:09:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 176862011B for ; Sat, 2 Aug 2014 18:09:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 69BD8200FF for ; Sat, 2 Aug 2014 18:09:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932334AbaHBSJD (ORCPT ); Sat, 2 Aug 2014 14:09:03 -0400 Received: from mail-qg0-f42.google.com ([209.85.192.42]:43523 "EHLO mail-qg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932131AbaHBSJC (ORCPT ); Sat, 2 Aug 2014 14:09:02 -0400 Received: by mail-qg0-f42.google.com with SMTP id j5so7201942qga.29 for ; Sat, 02 Aug 2014 11:09:01 -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=KfnDlEEVdnu4jEQB3LNJpya3XetNRREUgEAL5wgjvNQ=; b=Mva64o7HDxpAN7vp/60TQllM1S+mj5kIpjSF3SELZha5mouDdbowVL//5tSd/wfpao mpvkwCv9pH5opnOenmQ/FCVC1jtknNJI3q9GpcQETYWUbkkwg+MIlqfNOhAJSE+iDESp vxJSYB7JmFr5mw7JP3R9YN+1Mf/SBPm3RZFgzrIhocdn2HPjAN9sdIrbf4SwtET76H77 7Uo4mfuWXFlyLcRSJeKP2ZeInU4Lm/5M5pRp8HYZ9/zpZBaDVzlDdbK26uz6auvs9qN8 +NUGEAeS5upgrJfgd6L90rEnhQCDfXp9/mR51DyKiiilOde6LHU/x9kyypanCTPfkz1t lscA== MIME-Version: 1.0 X-Received: by 10.140.38.169 with SMTP id t38mr11726656qgt.3.1407002941285; Sat, 02 Aug 2014 11:09:01 -0700 (PDT) Received: by 10.140.21.164 with HTTP; Sat, 2 Aug 2014 11:09:01 -0700 (PDT) In-Reply-To: References: <20140731181006.GA13180@cloud> Date: Sat, 2 Aug 2014 11:09:01 -0700 X-Google-Sender-Auth: zAEI-DArBk8sSuJp1WOzr3vbU-U Message-ID: Subject: Re: Designated initializers for fields in anonymous structs and unions From: Christopher Li To: Linus Torvalds Cc: Josh Triplett , 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 Sat, Aug 2, 2014 at 1:27 AM, Christopher Li wrote: > I just apply that without the "FIXME" part. That two lines are from an incorrect > fix for the external inline bug. I just remove it for now. Currently > sparse will fail > at the external inline test. I will fix that in a separate patch. This is a follow up change to fix the extern-inline.c validation bug. Feed back are welcome. Consider the following case, extern inline declare after extern declare of the same function. extern int g(int); extern __inline__ int g(int x) { return x; } Sparse will give the first function global scope and the second one file scope. Also the first one will get the function body from the second one. That cause the failure of the validation/extern-inlien.c This change rebind the scope of the same_symbol chain to the new scope. It will pass the extern-inline.c test case. Chris From 7abd8a76b4e07ad60b5262e4c7858e638467fab8 Mon Sep 17 00:00:00 2001 From: Christopher Li Date: Sat, 2 Aug 2014 10:56:59 -0700 Subject: [PATCH] Make same_symbol list share the same scope Consider the following case, extern inline declare after extern declare of the same function. extern int g(int); extern __inline__ int g(int x) { return x; } Sparse will give the first function global scope and the second one file scope. Also the first one will get the function body from the second one. That cause the failure of the validation/extern-inlien.c This change rebind the scope of the same_symbol chain to the new scope. It will pass the extern-inline.c test case. Signed-off-by: Christopher Li --- parse.c | 1 + scope.c | 14 ++++++++++++++ scope.h | 1 + 3 files changed, 16 insertions(+) diff --git a/parse.c b/parse.c index 55a57a7..eaa1883 100644 --- a/parse.c +++ b/parse.c @@ -2611,6 +2611,7 @@ static struct token *parse_function_body(struct token *token, struct symbol *dec info(prev->definition->pos, " the previous one is here"); } else { while (prev) { + rebind_scope(prev, decl->scope); prev->definition = decl; prev = prev->same_symbol; } diff --git a/scope.c b/scope.c index b415ace..cbf2fcf 100644 --- a/scope.c +++ b/scope.c @@ -46,6 +46,20 @@ void bind_scope(struct symbol *sym, struct scope *scope) add_symbol(&scope->symbols, sym); } + +void rebind_scope(struct symbol *sym, struct scope *new) +{ + struct scope *old = sym->scope; + + if (old == new) + return; + + if (old) + delete_ptr_list_entry((struct ptr_list**) &old->symbols, sym, 1); + + bind_scope(sym, new); +} + static void start_scope(struct scope **s) { struct scope *scope = __alloc_scope(0); diff --git a/scope.h b/scope.h index 045c356..9bbb675 100644 --- a/scope.h +++ b/scope.h @@ -55,6 +55,7 @@ extern void start_function_scope(void); extern void end_function_scope(void); extern void bind_scope(struct symbol *, struct scope *); +extern void rebind_scope(struct symbol *, struct scope *); extern int is_outer_scope(struct scope *); #endif -- 1.9.3