All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH] fix value of label statement
Date: Wed,  4 Jan 2017 05:45:33 +0100	[thread overview]
Message-ID: <20170104044533.32555-1-luc.vanoostenryck@gmail.com> (raw)

Normaly a label statement is not also an expression but it could be
in GCC's statement expression like : ({ ...; label: <expression>; })

Currently, during linearization sparse discards the return value
of the linearization of the label's sub-statement, thus also
discarding the value of such statement-expressions.

Trivialy fix this by not discarding the return value but returning
it instead, like other statements that also are an expression and
thus have a value.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 linearize.c             |  3 +--
 validation/label-expr.c | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100644 validation/label-expr.c

This patch can also be found as 'sent/fix-label-statement-value' on
	git://github.com/lucvoo/sparse.git

diff --git a/linearize.c b/linearize.c
index 725eafe7..8bd78777 100644
--- a/linearize.c
+++ b/linearize.c
@@ -2029,8 +2029,7 @@ pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt)
 		if (label->used) {
 			add_label(ep, label);
 		}
-		linearize_statement(ep, stmt->label_statement);
-		break;
+		return linearize_statement(ep, stmt->label_statement);
 	}
 
 	case STMT_GOTO: {
diff --git a/validation/label-expr.c b/validation/label-expr.c
new file mode 100644
index 00000000..e578ed00
--- /dev/null
+++ b/validation/label-expr.c
@@ -0,0 +1,17 @@
+int foo(void);
+int foo(void)
+{
+	int r;
+
+	r = ({ label: 1; });
+	return r;
+}
+
+/*
+ * check-name: label-expr
+ * check-command: test-linearize $file
+ * check-output-ignore
+ *
+ * check-output-excludes: ret\\.32\$
+ * check-output-contains: ret\\.32 *\\$1
+ */
-- 
2.11.0


                 reply	other threads:[~2017-01-04  4:53 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=20170104044533.32555-1-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --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 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.