aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2023-12-11 13:01:06 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2023-12-16 12:06:28 +0100
commitdc581e62b74dafb1ef4aca1ab088e37ba6fd7c94 (patch)
tree1dd170508fa32f53eca0b98de7f8756cd48a65af
parentce1a6720f69e6233ec9abd4e9aae5945e05fda41 (diff)
downloadsparse-dev-dc581e62b74dafb1ef4aca1ab088e37ba6fd7c94.tar.gz
parse: add testcases for __cleanup__ attribute
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--validation/parsing/attr-cleanup.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/validation/parsing/attr-cleanup.c b/validation/parsing/attr-cleanup.c
new file mode 100644
index 00000000..76234276
--- /dev/null
+++ b/validation/parsing/attr-cleanup.c
@@ -0,0 +1,34 @@
+#define __cleanup(F) __attribute__((__cleanup__(F)))
+
+void fun(int *ptr);
+
+int test(int n);
+int test(int n)
+{
+ int var __attribute__((cleanup(fun))) = 1;
+ int alt __cleanup(fun) = 2;
+ int mis __cleanup(0) = 3;
+ int non __attribute__((cleanup));
+ int mis __attribute__((cleanup()));
+ int two __attribute__((cleanup(fun, fun)));
+
+ for (int i __cleanup(fun) = 0; i < n; i++)
+ ;
+
+ var = 5;
+ return 0;
+}
+
+/*
+ * check-name: attr-cleanup
+ * check-command: sparse -Wunknown-attribute $file
+ * check-known-to-fail
+ *
+ * check-error-start
+parsing/attr-cleanup.c:10:17: error: argument is not an identifier
+parsing/attr-cleanup.c:11:39: error: an argument is expected for attribute 'cleanup'
+parsing/attr-cleanup.c:12:40: error: an argument is expected for attribute 'cleanup'
+parsing/attr-cleanup.c:13:43: error: Expected ) after attribute's argument'
+parsing/attr-cleanup.c:13:43: error: got ,
+ * check-error-end
+ */