From: Pavel Roskin <proski@gnu.org>
To: linux-sparse@vger.kernel.org
Subject: [PATCH] Expand initializers when testing them for being constant
Date: Sun, 01 Jun 2008 19:26:18 -0400 [thread overview]
Message-ID: <20080601232618.32306.5330.stgit@dv.roinet.com> (raw)
Signed-off-by: Pavel Roskin <proski@gnu.org>
---
expand.c | 2 ++
validation/array-size-known.c | 9 +++++++++
validation/array-size-unknown.c | 14 ++++++++++++++
3 files changed, 25 insertions(+), 0 deletions(-)
create mode 100644 validation/array-size-known.c
create mode 100644 validation/array-size-unknown.c
diff --git a/expand.c b/expand.c
index 032f0c5..bbe8d6c 100644
--- a/expand.c
+++ b/expand.c
@@ -620,6 +620,8 @@ static int expand_dereference(struct expression *expr)
/* Const symbol with a constant initializer? */
if (value) {
+ expand_expression(value);
+
/* FIXME! We should check that the size is right! */
if (value->type == EXPR_VALUE) {
expr->type = EXPR_VALUE;
diff --git a/validation/array-size-known.c b/validation/array-size-known.c
new file mode 100644
index 0000000..8f4603a
--- /dev/null
+++ b/validation/array-size-known.c
@@ -0,0 +1,9 @@
+void foo(void);
+void foo(void) {
+ const int len = 32 + 32;
+ int buf[len];
+ buf[0] = 0;
+}
+/*
+ * check-name: Array size known at the compile time
+ */
diff --git a/validation/array-size-unknown.c b/validation/array-size-unknown.c
new file mode 100644
index 0000000..825accb
--- /dev/null
+++ b/validation/array-size-unknown.c
@@ -0,0 +1,14 @@
+extern int extra;
+void foo(void);
+void foo(void) {
+ const int len = 32 + extra;
+ int buf[len];
+ buf[0] = 0;
+}
+/*
+ * check-name: Array size unknown at the compile time
+ *
+ * check-error-start
+array-size-unknown.c:5:10: error: bad constant expression
+ * check-error-end
+ */
reply other threads:[~2008-06-01 23:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20080601232618.32306.5330.stgit@dv.roinet.com \
--to=proski@gnu.org \
--cc=linux-sparse@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).