diff mbox

[3/3] fix discarded label statement

Message ID 20161110144520.24965-4-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Luc Van Oostenryck Nov. 10, 2016, 2:45 p.m. UTC
When code contains an unused label, it's not needed to create a new
basic block for the code that follow it but that doesn't mean that
the following code is unreachable.

There is currently a bug related to this when processing a label statement
for a label that is never used: not only the label is ignored (and this
no new basic block is created) but the whol statement is ignored.
In other words the statement directly following an unused label is
simply ignored.

The patch fix this by simply moving the code handling the statement out
of the conditional part processing used labels.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 linearize.c                            |  2 +-
 validation/discarded-label-statement.c | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 validation/discarded-label-statement.c

Comments

Christopher Li Nov. 17, 2016, 5:19 p.m. UTC | #1
On Thu, Nov 10, 2016 at 10:45 PM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> The patch fix this by simply moving the code handling the statement out
> of the conditional part processing used labels.

Great catch.

Applied.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/linearize.c b/linearize.c
index c6ada1e8..4dc3d04d 100644
--- a/linearize.c
+++ b/linearize.c
@@ -2026,8 +2026,8 @@  pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt)
 
 		if (label->used) {
 			add_label(ep, label);
-			linearize_statement(ep, stmt->label_statement);
 		}
+		linearize_statement(ep, stmt->label_statement);
 		break;
 	}
 
diff --git a/validation/discarded-label-statement.c b/validation/discarded-label-statement.c
new file mode 100644
index 00000000..b4e58ac6
--- /dev/null
+++ b/validation/discarded-label-statement.c
@@ -0,0 +1,24 @@ 
+/*
+ * Verify that the statement following an unused label
+ * is not discarded with the label.
+ */
+
+static int bad(int a, int b)
+{
+	int r = 0;
+
+start:
+	r += a;
+	r += b;
+
+	return r;
+}
+
+/*
+ * check-name: discarded-label-statement
+ * check-command: test-linearize $file
+ *
+ * check-output-ignore
+ * check-output-contains: add
+ * check-output-contains: %arg1
+ */