aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2016-11-10 15:45:20 +0100
committerChristopher Li <sparse@chrisli.org>2017-02-13 09:34:43 +0800
commit28f6f5d2ee0389e27d6c8b8e35840df7ac3793ed (patch)
treed45fde56df49f345622f5b6a96f34544009c5d32 /validation
parentbb33d4ecc3446248617d4d2f66868c46635ce497 (diff)
downloadsparse-dev-28f6f5d2ee0389e27d6c8b8e35840df7ac3793ed.tar.gz
fix discarded label statement
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> Signed-off-by: Christopher Li <sparse@chrisli.org>
Diffstat (limited to 'validation')
-rw-r--r--validation/discarded-label-statement.c24
1 files changed, 24 insertions, 0 deletions
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
+ */