aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-12-09 18:20:45 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-12-28 21:52:20 +0100
commitd111934dc7d80de62a95acab0d9e35b8ceafca07 (patch)
treeec578748cf9a144e4730c0455b06d9f67d79cbd7 /validation
parent69a789a78d4e64052628307f25310e195a50f5ee (diff)
downloadsparse-dev-d111934dc7d80de62a95acab0d9e35b8ceafca07.tar.gz
add testcases for type comparison
Sparse, as an extension and with a special syntax, supports the direct comparison of types, either equality modulo qualifiers for '==' and '!=', or size comparison for '<', '>', '<=' and '>='. Add some testcases to avoid possible regressions here. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
-rw-r--r--validation/type-compare.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/validation/type-compare.c b/validation/type-compare.c
new file mode 100644
index 00000000..1adcd704
--- /dev/null
+++ b/validation/type-compare.c
@@ -0,0 +1,76 @@
+#define __user __attribute__((address_space(1)))
+#define __safe __attribute__((safe))
+#define __nocast __attribute__((nocast))
+#define __bitwise __attribute__((bitwise))
+#define __noderef __attribute__((noderef))
+
+int test(void)
+{
+ if ([int] != [int]) return 1;
+ if (!([int] == [int])) return 1;
+
+ if ([int] == [long]) return 1;
+ if (!([int] != [long])) return 1;
+
+ if ([int] == [unsigned int]) return 1;
+ if (!([int] != [unsigned int])) return 1;
+
+ if ([int] != [int]) return 1;
+ if ([typeof(int)] != [int]) return 1;
+ if ([int] != [typeof(int)]) return 1;
+ if ([typeof(int)] != [typeof(int)]) return 1;
+
+ if ([char] > [short]) return 1;
+ if ([short] < [char]) return 1;
+ if (!([char] <= [short])) return 1;
+ if (!([short] >= [char])) return 1;
+
+ if ([short] > [int]) return 1;
+ if ([int] < [short]) return 1;
+ if (!([short] <= [int])) return 1;
+ if (!([int] >= [short])) return 1;
+
+ if ([int] > [long]) return 1;
+ if ([long] < [int]) return 1;
+ if (!([int] <= [long])) return 1;
+ if (!([long] >= [int])) return 1;
+
+ if ([long] > [long long]) return 1;
+ if ([long long] < [long]) return 1;
+ if (!([long] <= [long long])) return 1;
+ if (!([long long] >= [long])) return 1;
+
+ if ([int *] != [int *]) return 1;
+ if ([int *] == [void *]) return 1;
+
+ // qualifiers are ignored
+ if ([int] != [const int]) return 1;
+ if ([int] != [volatile int]) return 1;
+
+ // but others modifiers are significant
+ if ([int] == [int __nocast]) return 1;
+ if ([int] == [int __bitwise]) return 1;
+
+ //
+ if ([int *] == [const int *]) return 1;
+ if ([int *] == [volatile int *]) return 1;
+ if ([int *] == [int __user *]) return 1;
+ if ([int *] == [int __safe *]) return 1;
+ if ([int *] == [int __nocast *]) return 1;
+ if ([int *] == [int __bitwise *]) return 1;
+ if ([int *] == [int __noderef *]) return 1;
+
+ return 0;
+}
+
+/*
+ * check-name: type-as-first-class comparison
+ * check-description: This test the sparse extension making
+ * types first class citizens which can be compared
+ * for equality (or size for <, >, <=, >=).
+ * See expand.c:compare_types().
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ *
+ * check-output-contains: ret\\..*\\$0
+ */