summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/guality/example.c
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.dg/guality/example.c
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.dg/guality/example.c')
-rw-r--r--gcc/testsuite/gcc.dg/guality/example.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/guality/example.c b/gcc/testsuite/gcc.dg/guality/example.c
new file mode 100644
index 000000000..26d25c285
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/guality/example.c
@@ -0,0 +1,138 @@
+/* { dg-do run { xfail *-*-* } } */
+/* { dg-options "-g" } */
+
+#define GUALITY_DONT_FORCE_LIVE_AFTER -1
+
+#ifndef STATIC_INLINE
+#define STATIC_INLINE /*static*/
+#endif
+
+#include "guality.h"
+
+#include <assert.h>
+
+/* Test the debug info for the functions used in the VTA
+ presentation at the GCC Summit 2008. */
+
+typedef struct list {
+ struct list *n;
+ int v;
+} elt, *node;
+
+STATIC_INLINE node
+find_val (node c, int v, node e)
+{
+ while (c < e)
+ {
+ GUALCHK (c);
+ GUALCHK (v);
+ GUALCHK (e);
+ if (c->v == v)
+ return c;
+ GUALCHK (c);
+ GUALCHK (v);
+ GUALCHK (e);
+ c++;
+ }
+ return NULL;
+}
+
+STATIC_INLINE node
+find_prev (node c, node w)
+{
+ while (c)
+ {
+ node o = c;
+ c = c->n;
+ GUALCHK (c);
+ GUALCHK (o);
+ GUALCHK (w);
+ if (c == w)
+ return o;
+ GUALCHK (c);
+ GUALCHK (o);
+ GUALCHK (w);
+ }
+ return NULL;
+}
+
+STATIC_INLINE node
+check_arr (node c, node e)
+{
+ if (c == e)
+ return NULL;
+ e--;
+ while (c < e)
+ {
+ GUALCHK (c);
+ GUALCHK (e);
+ if (c->v > (c+1)->v)
+ return c;
+ GUALCHK (c);
+ GUALCHK (e);
+ c++;
+ }
+ return NULL;
+}
+
+STATIC_INLINE node
+check_list (node c, node t)
+{
+ while (c != t)
+ {
+ node n = c->n;
+ GUALCHK (c);
+ GUALCHK (n);
+ GUALCHK (t);
+ if (c->v > n->v)
+ return c;
+ GUALCHK (c);
+ GUALCHK (n);
+ GUALCHK (t);
+ c = n;
+ }
+ return NULL;
+}
+
+struct list testme[] = {
+ { &testme[1], 2 },
+ { &testme[2], 3 },
+ { &testme[3], 5 },
+ { &testme[4], 7 },
+ { &testme[5], 11 },
+ { NULL, 13 },
+};
+
+int
+main (int argc, char *argv[])
+{
+ int n = sizeof (testme) / sizeof (*testme);
+ node first, last, begin, end, ret;
+
+ GUALCHKXPR (n);
+
+ begin = first = &testme[0];
+ last = &testme[n-1];
+ end = &testme[n];
+
+ GUALCHKXPR (first);
+ GUALCHKXPR (last);
+ GUALCHKXPR (begin);
+ GUALCHKXPR (end);
+
+ ret = find_val (begin, 13, end);
+ GUALCHK (ret);
+ assert (ret == last);
+
+ ret = find_prev (first, last);
+ GUALCHK (ret);
+ assert (ret == &testme[n-2]);
+
+ ret = check_arr (begin, end);
+ GUALCHK (ret);
+ assert (!ret);
+
+ ret = check_list (first, last);
+ GUALCHK (ret);
+ assert (!ret);
+}