aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
Diffstat (limited to 'validation')
-rw-r--r--validation/arch/short-wchar.c6
-rw-r--r--validation/attr-visible.c13
-rw-r--r--validation/attr-visible2.c10
-rw-r--r--validation/bitwise-function-pointer.c17
-rw-r--r--validation/char-signed-native.c9
-rw-r--r--validation/char-unsigned-native.c11
-rw-r--r--validation/char-unsigned.c2
-rw-r--r--validation/function-attribute-inner.c9
-rw-r--r--validation/function-attribute-pointer.c33
-rw-r--r--validation/function-attribute-void-ptr.c14
-rw-r--r--validation/function-attribute.c22
-rw-r--r--validation/function-redecl-funattr.c13
-rw-r--r--validation/function-redecl2.c3
-rw-r--r--validation/pure-function.c17
-rw-r--r--validation/static-forward-decl.c19
15 files changed, 181 insertions, 17 deletions
diff --git a/validation/arch/short-wchar.c b/validation/arch/short-wchar.c
new file mode 100644
index 00000000..de05313c
--- /dev/null
+++ b/validation/arch/short-wchar.c
@@ -0,0 +1,6 @@
+_Static_assert([__WCHAR_TYPE__] == [unsigned short], "short wchar");
+
+/*
+ * check-name: short-wchar
+ * check-command: sparse -fshort-wchar $file
+ */
diff --git a/validation/attr-visible.c b/validation/attr-visible.c
new file mode 100644
index 00000000..38ee8575
--- /dev/null
+++ b/validation/attr-visible.c
@@ -0,0 +1,13 @@
+#define __visible __attribute__((externally_visible))
+
+__visible void foo(void)
+{
+}
+
+int flag __visible;
+
+/*
+ * check-name: attr-visible
+ * check-command: sparse -Wdecl $file
+ * check-known-to-fail
+ */
diff --git a/validation/attr-visible2.c b/validation/attr-visible2.c
new file mode 100644
index 00000000..62949b47
--- /dev/null
+++ b/validation/attr-visible2.c
@@ -0,0 +1,10 @@
+#define __visible __attribute__((externally_visible))
+
+int flag __visible;
+int arr[2] __visible;
+
+/*
+ * check-name: attr-visible-after
+ * check-command: sparse -Wdecl $file
+ * check-known-to-fail
+ */
diff --git a/validation/bitwise-function-pointer.c b/validation/bitwise-function-pointer.c
new file mode 100644
index 00000000..544f2fc0
--- /dev/null
+++ b/validation/bitwise-function-pointer.c
@@ -0,0 +1,17 @@
+#define __bitwise __attribute__((bitwise))
+
+typedef unsigned int __bitwise t;
+
+unsigned int fun(void);
+
+static t (*ptr)(void) = fun;
+
+/*
+ * check-name: bitwise-function-pointer
+ *
+ * check-error-start
+bitwise-function-pointer.c:7:25: warning: incorrect type in initializer (different base types)
+bitwise-function-pointer.c:7:25: expected restricted t ( *static [toplevel] ptr )( ... )
+bitwise-function-pointer.c:7:25: got unsigned int ( * )( ... )
+ * check-error-end
+ */
diff --git a/validation/char-signed-native.c b/validation/char-signed-native.c
new file mode 100644
index 00000000..5185fce9
--- /dev/null
+++ b/validation/char-signed-native.c
@@ -0,0 +1,9 @@
+void foo(void)
+{
+ _Static_assert((char) -1 == -1, "plain char is not signed");
+}
+
+/*
+ * check-name: char-signed-native
+ * check-command: sparse --arch=i386 -Wno-decl $file
+ */
diff --git a/validation/char-unsigned-native.c b/validation/char-unsigned-native.c
new file mode 100644
index 00000000..b8645842
--- /dev/null
+++ b/validation/char-unsigned-native.c
@@ -0,0 +1,11 @@
+#define MASK ((1 << __CHAR_BIT__) - 1)
+
+void foo(void)
+{
+ _Static_assert((char) -1 == (-1 & MASK), "plain char is not unsigned");
+}
+
+/*
+ * check-name: char-unsigned-native
+ * check-command: sparse --arch=arm -Wno-decl $file
+ */
diff --git a/validation/char-unsigned.c b/validation/char-unsigned.c
index 19cadbda..354aa40d 100644
--- a/validation/char-unsigned.c
+++ b/validation/char-unsigned.c
@@ -6,6 +6,6 @@ void foo(void)
}
/*
- * check-name: fsigned-char
+ * check-name: funsigned-char
* check-command: sparse -funsigned-char -Wno-decl $file
*/
diff --git a/validation/function-attribute-inner.c b/validation/function-attribute-inner.c
new file mode 100644
index 00000000..3a8a8407
--- /dev/null
+++ b/validation/function-attribute-inner.c
@@ -0,0 +1,9 @@
+#define __noreturn __attribute__((__noreturn__))
+
+void __noreturn fun(void);
+
+_Static_assert([void (__noreturn *)(void)] == [typeof(&fun)], "");
+
+/*
+ * check-name: function-attribute-inner
+ */
diff --git a/validation/function-attribute-pointer.c b/validation/function-attribute-pointer.c
new file mode 100644
index 00000000..fd08ac71
--- /dev/null
+++ b/validation/function-attribute-pointer.c
@@ -0,0 +1,33 @@
+#define __noreturn __attribute__((__noreturn__))
+
+void set_die(void (*)(void));
+void set_die_nr(__noreturn void (*)(void));
+
+void die(void);
+void __noreturn die_nr(void);
+
+static void foo(void)
+{
+ set_die(die);
+ set_die(die_nr);
+ set_die_nr(die_nr);
+ set_die_nr(die);
+
+ void (*fptr0)(void) = die;
+ void (*fptr1)(void) = die_nr;
+ __noreturn void (*fptr3)(void) = die_nr;
+ __noreturn void (*fptr2)(void) = die;
+}
+
+/*
+ * check-name: function-attribute-pointer
+ *
+ * check-error-start
+function-attribute-pointer.c:14:20: warning: incorrect type in argument 1 (different modifiers)
+function-attribute-pointer.c:14:20: expected void ( [noreturn] * )( ... )
+function-attribute-pointer.c:14:20: got void ( * )( ... )
+function-attribute-pointer.c:19:42: warning: incorrect type in initializer (different modifiers)
+function-attribute-pointer.c:19:42: expected void ( [noreturn] *fptr2 )( ... )
+function-attribute-pointer.c:19:42: got void ( * )( ... )
+ * check-error-end
+ */
diff --git a/validation/function-attribute-void-ptr.c b/validation/function-attribute-void-ptr.c
new file mode 100644
index 00000000..0092b63c
--- /dev/null
+++ b/validation/function-attribute-void-ptr.c
@@ -0,0 +1,14 @@
+#define __noreturn __attribute__((__noreturn__))
+
+void fun(void *);
+void __noreturn die(void);
+
+static void foo(void)
+{
+ void *ptr = die;
+ fun(die);
+}
+
+/*
+ * check-name: function-attribute-void-ptr
+ */
diff --git a/validation/function-attribute.c b/validation/function-attribute.c
new file mode 100644
index 00000000..2be180c4
--- /dev/null
+++ b/validation/function-attribute.c
@@ -0,0 +1,22 @@
+#define __pure __attribute__((pure))
+
+
+static __pure int funi(int val)
+{
+ return val;
+}
+
+static __pure int *funp(int *ptr)
+{
+ return ptr;
+}
+
+static void foo(int val, int *ptr)
+{
+ int nbr = funi(val);
+ int *res = funp(ptr);
+}
+
+/*
+ * check-name: function-attribute
+ */
diff --git a/validation/function-redecl-funattr.c b/validation/function-redecl-funattr.c
new file mode 100644
index 00000000..b1e2fb19
--- /dev/null
+++ b/validation/function-redecl-funattr.c
@@ -0,0 +1,13 @@
+#define __pure __attribute__((pure))
+#define __noreturn __attribute__((noreturn))
+
+
+int __pure p(int i);
+int p(int i) { return i; }
+
+void __noreturn n(void);
+void n(void) { while (1) ; }
+
+/*
+ * check-name: function-redecl-funattr
+ */
diff --git a/validation/function-redecl2.c b/validation/function-redecl2.c
index 3435aa00..ef396137 100644
--- a/validation/function-redecl2.c
+++ b/validation/function-redecl2.c
@@ -25,7 +25,4 @@ void func2(int a)
/*
* check-name: function-redecl2
- *
- * check-known-to-fail
- *
*/
diff --git a/validation/pure-function.c b/validation/pure-function.c
index 04bb85e4..9692cc84 100644
--- a/validation/pure-function.c
+++ b/validation/pure-function.c
@@ -1,16 +1,25 @@
-static __attribute__((__pure__)) int pure1(void)
+static __attribute__((__pure__)) int pure_int(int v)
{
- int i = 0;
+ int i = v;
return i;
}
-static __attribute__((__pure__)) void *pure2(void)
+static __attribute__((__pure__)) void *pure_ptr(void *p)
{
- void *i = (void *)0;
+ void *i = p;
return i;
}
+static void foo(int v, void *p)
+{
+ int val = pure_int(v);
+ void *ptr = pure_ptr(p);
+
+ (void)val;
+ (void)ptr;
+}
+
/*
* check-name: Pure function attribute
*/
diff --git a/validation/static-forward-decl.c b/validation/static-forward-decl.c
index daad1ecb..d25d8152 100644
--- a/validation/static-forward-decl.c
+++ b/validation/static-forward-decl.c
@@ -1,13 +1,14 @@
-static int f(void);
+int fref(void);
+int fref(void) { return 0; }
+
+static
+int floc(void);
+int floc(void) { return 0; }
+
+static
+int oloc;
+int oloc = 0;
-int f(void)
-{
- return 0;
-}
/*
* check-name: static forward declaration
- *
- * check-error-start
-static-forward-decl.c:3:5: warning: symbol 'f' was not declared. Should it be static?
- * check-error-end
*/