From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Christopher Li <sparse@chrisli.org>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
"Jason J. Herne" <jjherne@linux.vnet.ibm.com>,
Linux-Sparse <linux-sparse@vger.kernel.org>
Subject: [PATCH] Teach sparse about the __COUNTER__ predefined macro
Date: Fri, 23 Jan 2015 23:23:32 +0100 [thread overview]
Message-ID: <20150123222332.GB42179@macpro.local> (raw)
In-Reply-To: <CANeU7QmVQyRFHJ+YSDPkfDfXsNSLL4rJ-jA4v3UQH0tNqjEPOw@mail.gmail.com>
On Fri, Jan 23, 2015 at 08:40:17AM -0800, Christopher Li wrote:
> On Thu, Jan 22, 2015 at 12:31 PM, Christian Borntraeger
> <borntraeger@de.ibm.com> wrote:
> > Linus, Christopher,
> >
> > Commit 0f25c6a78e08fdc15af5e599d836fa24349c042f ("Add warning about duplicate initializers") has a false positive on arch/s390/kvm/kvm-s390.c
> >
> > CHECK arch/s390/kvm/kvm-s390.c
> > arch/s390/kvm/kvm-s390.c:1823:1: error: symbol '__UNIQUE_ID_alias__COUNTER__' has multiple initializers (originally initialized at arch/s390/kvm/kvm-s390.c:1822)
>
> Search the "__COUNTER__" macro shows that:
> https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
>
> __COUNTER__This macro expands to sequential integral values starting
> from 0. In conjunction with the ## operator, this provides a
> convenient means to generate unique identifiers. Care must be taken to
> ensure that __COUNTER__ is not expanded prior to inclusion of
> precompiled headers which use it. Otherwise, the precompiled headers
> will not be used.
>
> I think sparse haven't implement the __COUNTER__ macro. That is why it emit the
> error on duplicate entry.
>
> Chris
> --
The following patch should fix that.
Luc
Subject: [PATCH] Teach sparse about the __COUNTER__ predefined macro.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
ident-list.h | 1 +
pre-process.c | 4 ++++
validation/preprocessor/__COUNTER__.c | 12 ++++++++++++
3 files changed, 17 insertions(+)
create mode 100644 validation/preprocessor/__COUNTER__.c
diff --git a/ident-list.h b/ident-list.h
index d5a145f8..b65b667d 100644
--- a/ident-list.h
+++ b/ident-list.h
@@ -108,6 +108,7 @@ __IDENT(__TIME___ident, "__TIME__", 0);
__IDENT(__func___ident, "__func__", 0);
__IDENT(__FUNCTION___ident, "__FUNCTION__", 0);
__IDENT(__PRETTY_FUNCTION___ident, "__PRETTY_FUNCTION__", 0);
+__IDENT(__COUNTER___ident, "__COUNTER__", 0);
/* Sparse commands */
IDENT_RESERVED(__context__);
diff --git a/pre-process.c b/pre-process.c
index 1aa3d2c4..316247ac 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -181,6 +181,10 @@ static int expand_one_symbol(struct token **list)
time(&t);
strftime(buffer, 9, "%T", localtime(&t));
replace_with_string(token, buffer);
+ } else if (token->ident == &__COUNTER___ident) {
+ static int counter;
+
+ replace_with_integer(token, counter++);
}
return 1;
}
diff --git a/validation/preprocessor/__COUNTER__.c b/validation/preprocessor/__COUNTER__.c
new file mode 100644
index 00000000..98187ee6
--- /dev/null
+++ b/validation/preprocessor/__COUNTER__.c
@@ -0,0 +1,12 @@
+__COUNTER__
+__COUNTER__
+/*
+ * check-name: __COUNTER__ #1
+ * check-command: sparse -E $file
+ *
+ * check-output-start
+
+0
+1
+ * check-output-end
+ */
next prev parent reply other threads:[~2015-01-23 22:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-22 20:31 sparse: new feature " multiple initializers" has false positives on MODULE_ALIAS Christian Borntraeger
2015-01-23 16:40 ` Christopher Li
2015-01-23 22:23 ` Luc Van Oostenryck [this message]
2015-01-23 22:28 ` [PATCH] Teach sparse about the __COUNTER__ predefined macro Sam Ravnborg
2015-01-23 22:38 ` josh
2015-01-23 23:59 ` Luc Van Oostenryck
2015-01-24 1:29 ` Josh Triplett
2015-01-24 11:27 ` Luc Van Oostenryck
2015-01-24 20:19 ` Josh Triplett
2015-01-24 20:39 ` Luc Van Oostenryck
2015-01-25 20:12 ` Christian Borntraeger
2015-01-28 10:08 ` Christian Borntraeger
2015-02-02 5:17 ` Christopher Li
2015-02-04 2:38 ` Luc Van Oostenryck
2015-02-12 20:16 ` Christopher Li
2015-02-04 2:46 ` [PATCH 1/3] test-suite: add support for tests case involving several input files Luc Van Oostenryck
2015-02-06 15:02 ` Christopher Li
2015-02-04 2:49 ` [PATCH 2/3] test-suite: allow filename expansion of the input sections Luc Van Oostenryck
2015-02-04 2:51 ` [PATCH 3/3] test-suite: consolidate tests that require include files into single test files Luc Van Oostenryck
2015-02-04 3:11 ` [PATCH 2/3] test-suite: allow filename expansion of the input sections Luc Van Oostenryck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150123222332.GB42179@macpro.local \
--to=luc.vanoostenryck@gmail.com \
--cc=borntraeger@de.ibm.com \
--cc=jjherne@linux.vnet.ibm.com \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.