From patchwork Fri Apr 19 19:10:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Triplett X-Patchwork-Id: 2466821 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id BDB8FDF25A for ; Fri, 19 Apr 2013 19:10:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753394Ab3DSTKq (ORCPT ); Fri, 19 Apr 2013 15:10:46 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:39063 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753124Ab3DSTKp (ORCPT ); Fri, 19 Apr 2013 15:10:45 -0400 Received: from mfilter20-d.gandi.net (mfilter20-d.gandi.net [217.70.178.148]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id B8339172089; Fri, 19 Apr 2013 21:10:43 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter20-d.gandi.net Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mfilter20-d.gandi.net (mfilter20-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id F17v9wDHnKRH; Fri, 19 Apr 2013 21:10:42 +0200 (CEST) X-Originating-IP: 173.246.103.110 Received: from jtriplet-mobl1 (joshtriplett.org [173.246.103.110]) (Authenticated sender: josh@joshtriplett.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id BECEB172055; Fri, 19 Apr 2013 21:10:40 +0200 (CEST) Date: Fri, 19 Apr 2013 12:10:38 -0700 From: Josh Triplett To: linux-sparse@vger.kernel.org Cc: Christopher Li , Auke Kok Subject: [PATCH] Support #pragma once Message-ID: <20130419191036.GA8615@jtriplet-mobl1> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org "#pragma once" acts like a multiple-inclusion guard affecting the entire file, without an associated preprocessor symbol. This allows use of sparse on projects that rely on #pragma once without also using an ifndef-based multiple-inclusion guard, such as systemd; without this change, sparse will get into an include loop. Signed-off-by: Josh Triplett --- ident-list.h | 1 + pre-process.c | 9 +++++++++ token.h | 2 +- validation/pragma-once.c | 5 +++++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 validation/pragma-once.c diff --git a/ident-list.h b/ident-list.h index e00cd96..e93aae7 100644 --- a/ident-list.h +++ b/ident-list.h @@ -97,6 +97,7 @@ IDENT(error); IDENT(__error__); * itself by name, preventing these tokens from expanding when compiling * sparse. */ IDENT(defined); +IDENT(once); __IDENT(pragma_ident, "__pragma__", 0); __IDENT(__VA_ARGS___ident, "__VA_ARGS__", 0); __IDENT(__LINE___ident, "__LINE__", 0); diff --git a/pre-process.c b/pre-process.c index 486fec4..4d84965 100644 --- a/pre-process.c +++ b/pre-process.c @@ -743,6 +743,11 @@ static int already_tokenized(const char *path) struct stream *s = input_streams + stream; next = s->next_stream; + if (s->once) { + if (strcmp(path, s->name)) + continue; + return 1; + } if (s->constant != CONSTANT_FILE_YES) continue; if (strcmp(path, s->name)) @@ -1809,6 +1814,10 @@ static int handle_pragma(struct stream *stream, struct token **line, struct toke { struct token *next = *line; + if (match_ident(token->next, &once_ident) && eof_token(token->next->next)) { + stream->once = 1; + return 1; + } token->ident = &pragma_ident; token->pos.newline = 1; token->pos.whitespace = 1; diff --git a/token.h b/token.h index a1218c6..cfe907b 100644 --- a/token.h +++ b/token.h @@ -40,7 +40,7 @@ struct stream { /* Use these to check for "already parsed" */ enum constantfile constant; - int dirty, next_stream; + int dirty, next_stream, once; struct ident *protect; struct token *ifndef; struct token *top_if; diff --git a/validation/pragma-once.c b/validation/pragma-once.c new file mode 100644 index 0000000..5e8b825 --- /dev/null +++ b/validation/pragma-once.c @@ -0,0 +1,5 @@ +#pragma once +#include "pragma-once.c" +/* + * check-name: #pragma once + */