From patchwork Mon Jul 3 18:41:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Li X-Patchwork-Id: 9823827 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 8A193604D9 for ; Mon, 3 Jul 2017 18:41:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A4152018F for ; Mon, 3 Jul 2017 18:41:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CDB627D4D; Mon, 3 Jul 2017 18:41:34 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_TVD_MIME_EPI 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 D173A2018F for ; Mon, 3 Jul 2017 18:41:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754168AbdGCSld (ORCPT ); Mon, 3 Jul 2017 14:41:33 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:34802 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754143AbdGCSlc (ORCPT ); Mon, 3 Jul 2017 14:41:32 -0400 Received: by mail-pg0-f43.google.com with SMTP id t186so99203807pgb.1 for ; Mon, 03 Jul 2017 11:41:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:from:date:message-id:subject:to:cc; bh=1PlnhR/95zXWsqpKInk+GMYsmTpzoA9THVGb5bZluDY=; b=cZTpTnUC3HnlT34wiE3qHN9MlQUtdhJFoNYqjMQ/uTmUPVr6WVM5LRnrPN04b6aA2K rtRIYRxUfFuEACyiMruJv232hYz9xF2j2TP/yFbjQ5Wn53QpcxsV1kURQKhH3sqsJFSO wXiEQFtjfvFyibDpdNmLbli8piF1uJ3u/sOzk/moJSFlcMQFF0SXxOklxTOF8YSd8381 VbR9sPBR8AqgM2KXSv9zffLZgZ/5tZtLskDfsahp7dITOqkaU74x5/d6KOYwDu8M+D6o RcqTjWxn5MlDbKgobLC6y9LL2+OQE5qVwtNPDXiF3WQPelqcMRX+ja2Ak1iE3AKiRQ0J JzRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to:cc; bh=1PlnhR/95zXWsqpKInk+GMYsmTpzoA9THVGb5bZluDY=; b=txo97HfUK5mPlVaDLBC/dZtp1Nb5zRMzKqNJm9VgKlbNXgB+lpkVytImD6dpaeMHZq MrXaE6QWCZFf0/jZcvnWWcreUsehNHJS/ykIAQxrJVI1tFkcYa5syzf3WIJbWlwW4D26 piUVXlvr37LN22xNGTIn6WsP3F/uAbgsQ7lW13XeMqAFuL3KUQZwksgTqN4twhooGbHw ZWOi/QabF/uDLMCyUaCzw6kdPzhRMR10wNcgG2Lodj/S0nHTPSKFnLSZGpXoNnLhsL5E gdU47K2vdKL1m6zrvD4HOGFLmkfIDO6IAy50K1WeMttlBZxWe6fxReRv/KgoD56gVtyQ tcAQ== X-Gm-Message-State: AIVw113OsvlTjOFyJ7F4jTugNfyN2yNrGE76543hjJPYzoFcSmIZ3wzK TgSis/uqO2i6NUjyPf7kWJcSEUgWdIdO X-Received: by 10.84.139.36 with SMTP id 33mr11885224plq.20.1499107291672; Mon, 03 Jul 2017 11:41:31 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.149.130 with HTTP; Mon, 3 Jul 2017 11:41:31 -0700 (PDT) From: Christopher Li Date: Mon, 3 Jul 2017 11:41:31 -0700 X-Google-Sender-Auth: 2uGCuBWjOnmS3t9vQuxtnwstYMM Message-ID: Subject: [PATCH 1/2] Let create_symbol check for previous same symbol To: Linux-Sparse Cc: Luc Van Oostenryck 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 Avoid create a new one if same symbol exists. This allow sparse process the full list of gcc supported attribute without worry about the duplicate one already implemented in sparse. Chris From 36c23fe2d00f36a2afa0a2d4690c098a5de11d18 Mon Sep 17 00:00:00 2001 From: Christopher Li Date: Mon, 3 Jul 2017 03:34:11 -0700 Subject: [PATCH 1/2] Let create_symbol check for previous same symbol Avoid create a new one if same symbol exists. Signed-off-By: --- parse.c | 6 ++++-- symbol.c | 15 ++++++++++++--- token.h | 2 +- tokenize.c | 4 ++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/parse.c b/parse.c index f665f05..953d04b 100644 --- a/parse.c +++ b/parse.c @@ -671,8 +671,10 @@ void init_parser(int stream) const char * name = ignored_attributes[i]; struct symbol *sym = create_symbol(stream, name, SYM_KEYWORD, NS_KEYWORD); - sym->ident->keyword = 1; - sym->op = &ignore_attr_op; + if (!sym->op) { + sym->ident->keyword = 1; + sym->op = &ignore_attr_op; + } } } diff --git a/symbol.c b/symbol.c index 08c85f4..301fe13 100644 --- a/symbol.c +++ b/symbol.c @@ -639,10 +639,19 @@ void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns) struct symbol *create_symbol(int stream, const char *name, int type, int namespace) { - struct token *token = built_in_token(stream, name); - struct symbol *sym = alloc_symbol(token->pos, type); + struct ident *ident = built_in_ident(name); + struct symbol *sym = lookup_symbol(ident, namespace); - bind_symbol(sym, token->ident, namespace); + if (sym && sym->type != type) + die("symbol %s create with different type: %d old %d", name, + type, sym->type); + + if (!sym) { + struct token *token = built_in_token(stream, ident); + + sym = alloc_symbol(token->pos, type); + bind_symbol(sym, token->ident, namespace); + } return sym; } diff --git a/token.h b/token.h index f7d88eb..847fdf4 100644 --- a/token.h +++ b/token.h @@ -218,7 +218,7 @@ extern int init_stream(const char *, int fd, const char **next_path); extern const char *stream_name(int stream); extern struct ident *hash_ident(struct ident *); extern struct ident *built_in_ident(const char *); -extern struct token *built_in_token(int, const char *); +extern struct token *built_in_token(int, struct ident *); extern const char *show_special(int); extern const char *show_ident(const struct ident *); extern const char *show_string(const struct string *string); diff --git a/tokenize.c b/tokenize.c index bc97242..99b9580 100644 --- a/tokenize.c +++ b/tokenize.c @@ -904,14 +904,14 @@ struct ident *built_in_ident(const char *name) return create_hashed_ident(name, len, hash_name(name, len)); } -struct token *built_in_token(int stream, const char *name) +struct token *built_in_token(int stream, struct ident *ident) { struct token *token; token = __alloc_token(0); token->pos.stream = stream; token_type(token) = TOKEN_IDENT; - token->ident = built_in_ident(name); + token->ident = ident; return token; } -- 2.9.4