aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
Diffstat (limited to 'validation')
-rw-r--r--validation/c11-atomic.c93
-rw-r--r--validation/cast-kinds.c12
-rw-r--r--validation/fp2i-cast.c30
-rw-r--r--validation/memops-volatile.c15
-rw-r--r--validation/optim/restrict.c73
-rw-r--r--validation/optim/volatile-side-effect.c13
-rw-r--r--validation/reload-aliasing.c41
-rw-r--r--validation/restrict.c93
-rw-r--r--validation/typeof-mods.c28
9 files changed, 384 insertions, 14 deletions
diff --git a/validation/c11-atomic.c b/validation/c11-atomic.c
new file mode 100644
index 00000000..bea3dab8
--- /dev/null
+++ b/validation/c11-atomic.c
@@ -0,0 +1,93 @@
+void f00(int _Atomic dst);
+void f01(int _Atomic *dst);
+void f02(int _Atomic *dst);
+void f03(int _Atomic *dst);
+
+int _Atomic qo;
+int uo;
+
+void f00(int dst) { } /* check-should-pass */
+void f01(typeof(&qo) dst) { } /* check-should-pass */
+void f02(int *dst) { } /* check-should-fail */
+void f03(typeof(&uo) dst) { } /* check-should-fail */
+
+void foo(void)
+{
+ qo = uo; /* check-should-pass */
+ uo = qo; /* check-should-pass */
+}
+
+void ref(void)
+{
+ const int qo;
+ int uo;
+ extern const int *pqo;
+ extern int *puo;
+
+ pqo = &qo; /* check-should-pass */
+ pqo = &uo; /* check-should-pass */
+ pqo = puo;
+
+ puo = &uo; /* check-should-pass */
+
+ puo = &qo; /* check-should-fail */
+ puo = pqo; /* check-should-fail */
+}
+
+void bar(void)
+{
+ extern int _Atomic *pqo;
+ extern int *puo;
+
+ pqo = &qo; /* check-should-pass */
+ pqo = &uo; /* check-should-pass */
+ pqo = puo;
+
+ puo = &uo; /* check-should-pass */
+
+ puo = &qo; /* check-should-fail */
+ puo = pqo; /* check-should-fail */
+}
+
+void baz(void)
+{
+ extern typeof(&qo) pqo;
+ extern typeof(&uo) puo;
+
+ pqo = &qo; /* check-should-pass */
+ pqo = &uo; /* check-should-pass */
+ pqo = puo;
+
+ puo = &uo; /* check-should-pass */
+
+ puo = &qo; /* check-should-fail */
+ puo = pqo; /* check-should-fail */
+}
+
+/*
+ * check-name: C11 _Atomic type qualifier
+ * check-command: sparse -Wno-decl $file;
+ *
+ * check-error-start
+c11-atomic.c:11:6: error: symbol 'f02' redeclared with different type (originally declared at c11-atomic.c:3) - incompatible argument 1 (different modifiers)
+c11-atomic.c:12:6: error: symbol 'f03' redeclared with different type (originally declared at c11-atomic.c:4) - incompatible argument 1 (different modifiers)
+c11-atomic.c:33:13: warning: incorrect type in assignment (different modifiers)
+c11-atomic.c:33:13: expected int *extern [assigned] puo
+c11-atomic.c:33:13: got int const *<noident>
+c11-atomic.c:34:13: warning: incorrect type in assignment (different modifiers)
+c11-atomic.c:34:13: expected int *extern [assigned] puo
+c11-atomic.c:34:13: got int const *extern [assigned] pqo
+c11-atomic.c:48:13: warning: incorrect type in assignment (different modifiers)
+c11-atomic.c:48:13: expected int *extern [assigned] puo
+c11-atomic.c:48:13: got int [atomic] *<noident>
+c11-atomic.c:49:13: warning: incorrect type in assignment (different modifiers)
+c11-atomic.c:49:13: expected int *extern [assigned] puo
+c11-atomic.c:49:13: got int [atomic] *extern [assigned] pqo
+c11-atomic.c:63:13: warning: incorrect type in assignment (different modifiers)
+c11-atomic.c:63:13: expected int *extern [assigned] puo
+c11-atomic.c:63:13: got int [atomic] *<noident>
+c11-atomic.c:64:13: warning: incorrect type in assignment (different modifiers)
+c11-atomic.c:64:13: expected int *extern [assigned] puo
+c11-atomic.c:64:13: got int [atomic] *extern [assigned] pqo
+ * check-error-end
+ */
diff --git a/validation/cast-kinds.c b/validation/cast-kinds.c
index 697f9735..e686c01e 100644
--- a/validation/cast-kinds.c
+++ b/validation/cast-kinds.c
@@ -92,7 +92,8 @@ iptr_2_int:
float_2_int:
.L10:
<entry-point>
- ret.32 %arg1
+ cast.32 %r17 <- (32) %arg1
+ ret.32 %r17
double_2_int:
@@ -139,7 +140,8 @@ iptr_2_uint:
float_2_uint:
.L24:
<entry-point>
- ret.32 %arg1
+ cast.32 %r38 <- (32) %arg1
+ ret.32 %r38
double_2_uint:
@@ -193,7 +195,8 @@ float_2_long:
double_2_long:
.L40:
<entry-point>
- ret.64 %arg1
+ cast.64 %r62 <- (64) %arg1
+ ret.64 %r62
int_2_ulong:
@@ -240,7 +243,8 @@ float_2_ulong:
double_2_ulong:
.L54:
<entry-point>
- ret.64 %arg1
+ cast.64 %r83 <- (64) %arg1
+ ret.64 %r83
int_2_vptr:
diff --git a/validation/fp2i-cast.c b/validation/fp2i-cast.c
new file mode 100644
index 00000000..08f8c925
--- /dev/null
+++ b/validation/fp2i-cast.c
@@ -0,0 +1,30 @@
+#if __SIZEOF_INT__ == __SIZEOF_FLOAT__
+typedef signed int si;
+typedef unsigned int ui;
+#else
+#error "no float-sized integer type"
+#endif
+
+#if __SIZEOF_LONG_LONG__ == __SIZEOF_DOUBLE__
+typedef signed long long sl;
+typedef unsigned long long ul;
+#else
+#error "no double-sized integer type"
+#endif
+
+si f2si(float a) { return a; }
+ui f2ui(float a) { return a; }
+sl f2sl(float a) { return a; }
+ul f2ul(float a) { return a; }
+si d2si(double a) { return a; }
+ui d2ui(double a) { return a; }
+sl d2sl(double a) { return a; }
+ul d2ul(double a) { return a; }
+
+/*
+ * check-name: fp2i cast
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern-8-times: cast\\.
+ */
diff --git a/validation/memops-volatile.c b/validation/memops-volatile.c
index 0f3e12ad..15314e1c 100644
--- a/validation/memops-volatile.c
+++ b/validation/memops-volatile.c
@@ -1,6 +1,7 @@
static int foo(volatile int *a, int v)
{
*a = v;
+ *a = 0;
return *a;
}
@@ -8,14 +9,8 @@ static int foo(volatile int *a, int v)
* check-name: memops-volatile
* check-command: test-linearize $file
*
- * check-output-start
-foo:
-.L0:
- <entry-point>
- store.32 %arg2 -> 0[%arg1]
- load.32 %r5 <- 0[%arg1]
- ret.32 %r5
-
-
- * check-output-end
+ * check-output-ignore
+ * check-output-contains: store\\..*%arg2 -> 0\\[%arg1]
+ * check-output-contains: store\\..*\\$0 -> 0\\[%arg1]
+ * check-output-contains: load\\..*%r.* <- 0\\[%arg1]
*/
diff --git a/validation/optim/restrict.c b/validation/optim/restrict.c
new file mode 100644
index 00000000..de6289e2
--- /dev/null
+++ b/validation/optim/restrict.c
@@ -0,0 +1,73 @@
+extern int g, h;
+
+void f00u(int *s)
+{
+ g = *s;
+ h = *s;
+}
+
+void f00r(int *restrict s)
+{
+ g = *s;
+ h = *s;
+}
+
+
+void f01u(int *a, int *b, int *s)
+{
+ *a = *s;
+ *b = *s;
+}
+
+void f01r(int *restrict a, int *restrict b, int *restrict s)
+{
+ *a = *s;
+ *b = *s;
+}
+
+/*
+ * check-name: optim/restrict
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-start
+f00u:
+.L0:
+ <entry-point>
+ load.32 %r2 <- 0[%arg1]
+ store.32 %r2 -> 0[g]
+ load.32 %r4 <- 0[%arg1]
+ store.32 %r4 -> 0[h]
+ ret
+
+
+f00r:
+.L2:
+ <entry-point>
+ load.32 %r6 <- 0[%arg1]
+ store.32 %r6 -> 0[g]
+ store.32 %r6 -> 0[h]
+ ret
+
+
+f01u:
+.L4:
+ <entry-point>
+ load.32 %r10 <- 0[%arg3]
+ store.32 %r10 -> 0[%arg1]
+ load.32 %r13 <- 0[%arg3]
+ store.32 %r13 -> 0[%arg2]
+ ret
+
+
+f01r:
+.L6:
+ <entry-point>
+ load.32 %r16 <- 0[%arg3]
+ store.32 %r16 -> 0[%arg1]
+ store.32 %r16 -> 0[%arg2]
+ ret
+
+
+ * check-output-end
+ */
diff --git a/validation/optim/volatile-side-effect.c b/validation/optim/volatile-side-effect.c
new file mode 100644
index 00000000..842b7228
--- /dev/null
+++ b/validation/optim/volatile-side-effect.c
@@ -0,0 +1,13 @@
+void foo(int p, volatile int *ptr)
+{
+ p ? : *ptr;
+ p ? : *ptr;
+}
+
+/*
+ * check-name: volatile-side-effect
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ *
+ * check-output-pattern(2): load
+ */
diff --git a/validation/reload-aliasing.c b/validation/reload-aliasing.c
new file mode 100644
index 00000000..3aad317b
--- /dev/null
+++ b/validation/reload-aliasing.c
@@ -0,0 +1,41 @@
+extern int g, h;
+
+void f00(int *s)
+{
+ g = *s;
+ h = *s;
+}
+
+void f01(int *a, int *b, int *s)
+{
+ *a = *s;
+ *b = *s;
+}
+
+/*
+ * check-name: reload-aliasing.c
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+f00:
+.L0:
+ <entry-point>
+ load.32 %r2 <- 0[%arg1]
+ store.32 %r2 -> 0[g]
+ load.32 %r4 <- 0[%arg1]
+ store.32 %r4 -> 0[h]
+ ret
+
+
+f01:
+.L2:
+ <entry-point>
+ load.32 %r6 <- 0[%arg3]
+ store.32 %r6 -> 0[%arg1]
+ load.32 %r9 <- 0[%arg3]
+ store.32 %r9 -> 0[%arg2]
+ ret
+
+
+ * check-output-end
+ */
diff --git a/validation/restrict.c b/validation/restrict.c
new file mode 100644
index 00000000..f431f6d0
--- /dev/null
+++ b/validation/restrict.c
@@ -0,0 +1,93 @@
+void f00(void *restrict dst);
+void f01(void *restrict *dst);
+void f02(void *restrict *dst);
+void f03(void *restrict *dst);
+
+void *restrict rp;
+void * up;
+
+void f00(void *dst) { } /* check-should-pass */
+void f01(typeof(&rp) dst) { } /* check-should-pass */
+void f02(void **dst) { } /* check-should-fail */
+void f03(typeof(&up) dst) { } /* check-should-fail */
+
+void foo(void)
+{
+ rp = up; /* check-should-pass */
+ up = rp; /* check-should-pass */
+}
+
+void ref(void)
+{
+ void *const qp;
+ void * up;
+ extern void *const *pqp;
+ extern void **pup;
+
+ pqp = &qp; /* check-should-pass */
+ pqp = &up; /* check-should-pass */
+ pqp = pup;
+
+ pup = &up; /* check-should-pass */
+
+ pup = &qp; /* check-should-fail */
+ pup = pqp; /* check-should-fail */
+}
+
+void bar(void)
+{
+ extern void *restrict *prp;
+ extern void **pup;
+
+ prp = &rp; /* check-should-pass */
+ prp = &up; /* check-should-pass */
+ prp = pup;
+
+ pup = &up; /* check-should-pass */
+
+ pup = &rp; /* check-should-fail */
+ pup = prp; /* check-should-fail */
+}
+
+void baz(void)
+{
+ extern typeof(&rp) prp;
+ extern typeof(&up) pup;
+
+ prp = &rp; /* check-should-pass */
+ prp = &up; /* check-should-pass */
+ prp = pup;
+
+ pup = &up; /* check-should-pass */
+
+ pup = &rp; /* check-should-fail */
+ pup = prp; /* check-should-fail */
+}
+
+/*
+ * check-name: restrict qualifier
+ * check-command: sparse -Wno-decl $file;
+ *
+ * check-error-start
+restrict.c:11:6: error: symbol 'f02' redeclared with different type (originally declared at restrict.c:3) - incompatible argument 1 (different modifiers)
+restrict.c:12:6: error: symbol 'f03' redeclared with different type (originally declared at restrict.c:4) - incompatible argument 1 (different modifiers)
+restrict.c:33:13: warning: incorrect type in assignment (different modifiers)
+restrict.c:33:13: expected void **extern [assigned] pup
+restrict.c:33:13: got void *const *<noident>
+restrict.c:34:13: warning: incorrect type in assignment (different modifiers)
+restrict.c:34:13: expected void **extern [assigned] pup
+restrict.c:34:13: got void *const *extern [assigned] pqp
+restrict.c:48:13: warning: incorrect type in assignment (different modifiers)
+restrict.c:48:13: expected void **extern [assigned] pup
+restrict.c:48:13: got void *restrict *<noident>
+restrict.c:49:13: warning: incorrect type in assignment (different modifiers)
+restrict.c:49:13: expected void **extern [assigned] pup
+restrict.c:49:13: got void *restrict *extern [assigned] prp
+restrict.c:63:13: warning: incorrect type in assignment (different modifiers)
+restrict.c:63:13: expected void **extern [assigned] pup
+restrict.c:63:13: got void *restrict *<noident>
+restrict.c:64:13: warning: incorrect type in assignment (different modifiers)
+restrict.c:64:13: expected void **extern [assigned] pup
+restrict.c:64:13: got void *restrict *extern [assigned] prp
+ * check-error-end
+ */
diff --git a/validation/typeof-mods.c b/validation/typeof-mods.c
index 9822e96f..aa880f37 100644
--- a/validation/typeof-mods.c
+++ b/validation/typeof-mods.c
@@ -43,6 +43,34 @@ static void test_volatile(void)
obj = *ptr;
}
+static void test_restrict(void)
+{
+ int *restrict obj, *restrict *ptr;
+ typeof(obj) var = obj;
+ typeof(ptr) ptr2 = ptr;
+ typeof(*ptr) var2 = obj;
+ typeof(*ptr) *ptr3 = ptr;
+ typeof(obj) *ptr4 = ptr;
+ obj = obj;
+ ptr = ptr;
+ ptr = &obj;
+ obj = *ptr;
+}
+
+static void test_atomic(void)
+{
+ int _Atomic obj, *ptr;
+ typeof(obj) var = obj;
+ typeof(ptr) ptr2 = ptr;
+ typeof(*ptr) var2 = obj;
+ typeof(*ptr) *ptr3 = ptr;
+ typeof(obj) *ptr4 = ptr;
+ obj = obj;
+ ptr = ptr;
+ ptr = &obj;
+ obj = *ptr;
+}
+
static void test_bitwise(void)
{
typedef int __bitwise type_t;