[PATCH 2/2] validation: Check C99 for loop variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Previously, sparse would generate incorrect code in the presence of a
C99 variable declaration inside the for statement, completely dropping
the code after the end of the for loop. Check that it's now behaving
correctly by entering a context and not leaving it at the end of the
loop.

Signed-off-by: Emily Maier <emily@xxxxxxxxxxxxxx>
---
 validation/c99-for-loop.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 validation/c99-for-loop.c

diff --git a/validation/c99-for-loop.c b/validation/c99-for-loop.c
new file mode 100644
index 0000000..42246c5
--- /dev/null
+++ b/validation/c99-for-loop.c
@@ -0,0 +1,33 @@
+int op(int);
+
+static int good(void)
+{
+	__context__(1);
+	for (int i = 0; i < 10; i++) {
+		if (!op(i)) {
+			__context__(-1);
+			return 0;
+		}
+	}
+	__context__(-1);
+	return 1;
+}
+
+static int bad(void)
+{
+	__context__(1);
+	for (int i = 0; i < 10; i++) {
+		if (!op(i)) {
+			__context__(-1);
+			return 0;
+		}
+	}
+	return 1;
+}
+/*
+ * check-name: C99 for loop variable declaration
+ *
+ * check-error-start
+c99-for-loop.c:16:12: warning: context imbalance in 'bad' - different lock contexts for basic block
+ * check-error-end
+ */
-- 
2.5.5

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



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux