summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2011-10-10 13:42:41 +0000
committerAldy Hernandez <aldyh@gcc.gnu.org>2011-10-10 13:42:41 +0000
commitff8e7c4d682099d61e81a20b465280bcc7cdaab5 (patch)
treebba6939b464863b1cd47394507ef6db3d08fb471 /gcc/testsuite/c-c++-common
parent53fbb7241f0d2d4e3a4eb8b3225671b121091b06 (diff)
downloadgcc-ff8e7c4d682099d61e81a20b465280bcc7cdaab5.tar.gz
gcc-simulate-thread.exp: New.
* lib/gcc-simulate-thread.exp: New. * gcc.dg/simulate-thread/guality.h: New. * gcc.dg/simulate-thread/simulate-thread.h: New. * gcc.dg/simulate-thread/simulate-thread.exp: New. * gcc.dg/simulate-thread/simulate-thread.gdb: New. * gcc.dg/simulate-thread/README: New. * g++.dg/simulate-thread/guality.h: New. * g++.dg/simulate-thread/simulate-thread.h: New. * g++.dg/simulate-thread/simulate-thread.exp: New. * g++.dg/simulate-thread/simulate-thread.gdb: New. * c-c++-common/cxxbitfields-2.c: Remove. * c-c++-common/cxxbitfields.c: Remove. * c-c++-common/cxxbitfields-4.c: Remove. * c-c++-common/cxxbitfields-5.c: Remove. * c-c++-common/simulate-thread/bitfields-1.c: New. * c-c++-common/simulate-thread/bitfields-2.c: New. * c-c++-common/simulate-thread/bitfields-3.c: New. * c-c++-common/simulate-thread/bitfields-4.c: New. From-SVN: r179751
Diffstat (limited to 'gcc/testsuite/c-c++-common')
-rw-r--r--gcc/testsuite/c-c++-common/cxxbitfields-2.c19
-rw-r--r--gcc/testsuite/c-c++-common/cxxbitfields-4.c18
-rw-r--r--gcc/testsuite/c-c++-common/cxxbitfields-5.c29
-rw-r--r--gcc/testsuite/c-c++-common/cxxbitfields.c18
-rw-r--r--gcc/testsuite/c-c++-common/simulate-thread/bitfields-1.c71
-rw-r--r--gcc/testsuite/c-c++-common/simulate-thread/bitfields-2.c59
-rw-r--r--gcc/testsuite/c-c++-common/simulate-thread/bitfields-3.c63
-rw-r--r--gcc/testsuite/c-c++-common/simulate-thread/bitfields-4.c60
8 files changed, 253 insertions, 84 deletions
diff --git a/gcc/testsuite/c-c++-common/cxxbitfields-2.c b/gcc/testsuite/c-c++-common/cxxbitfields-2.c
deleted file mode 100644
index b98b56daa91..00000000000
--- a/gcc/testsuite/c-c++-common/cxxbitfields-2.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
-/* { dg-options "-O2 --param allow-store-data-races=0" } */
-
-/* Test that we don't store past VAR.K. */
-
-struct S
-{
- volatile int i;
- volatile int j: 32;
- volatile int k: 15;
- volatile char c[2];
-} var;
-
-void setit()
-{
- var.k = 13;
-}
-
-/* { dg-final { scan-assembler-not "movl.*, var" } } */
diff --git a/gcc/testsuite/c-c++-common/cxxbitfields-4.c b/gcc/testsuite/c-c++-common/cxxbitfields-4.c
deleted file mode 100644
index 7023b31654a..00000000000
--- a/gcc/testsuite/c-c++-common/cxxbitfields-4.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
-/* { dg-options "-O2 --param allow-store-data-races=0" } */
-
-struct bits
-{
- char a;
- int b:7;
- int c:9;
- unsigned char d;
-} x;
-
-/* Store into <c> should not clobber <d>. */
-void update_c(struct bits *p, int val)
-{
- p -> c = val;
-}
-
-/* { dg-final { scan-assembler "mov\[bw\]" } } */
diff --git a/gcc/testsuite/c-c++-common/cxxbitfields-5.c b/gcc/testsuite/c-c++-common/cxxbitfields-5.c
deleted file mode 100644
index fba604fccc7..00000000000
--- a/gcc/testsuite/c-c++-common/cxxbitfields-5.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
-/* { dg-options "-O2 --param allow-store-data-races=0" } */
-
-#include <stdlib.h>
-
-struct bits
-{
- char a;
- int b:7;
- int c:9;
- unsigned char d;
-} x;
-
-struct bits *p;
-
-static void allocit()
-{
- p = (struct bits *) malloc (sizeof (struct bits));
-}
-
-/* Store into <c> should not clobber <d>. */
-/* We should not use a 32-bit move to store into p->, but a smaller move. */
-void foo()
-{
- allocit();
- p -> c = 55;
-}
-
-/* { dg-final { scan-assembler "mov\[bw\]" } } */
diff --git a/gcc/testsuite/c-c++-common/cxxbitfields.c b/gcc/testsuite/c-c++-common/cxxbitfields.c
deleted file mode 100644
index 43c840b15eb..00000000000
--- a/gcc/testsuite/c-c++-common/cxxbitfields.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
-/* { dg-options "-O2 --param allow-store-data-races=0" } */
-
-/* Test that we don't store past VAR.A. */
-
-struct S
-{
- volatile unsigned int a : 4;
- unsigned char b;
- unsigned int c : 6;
-} var;
-
-void set_a()
-{
- var.a = 12;
-}
-
-/* { dg-final { scan-assembler-not "movl.*, var" } } */
diff --git a/gcc/testsuite/c-c++-common/simulate-thread/bitfields-1.c b/gcc/testsuite/c-c++-common/simulate-thread/bitfields-1.c
new file mode 100644
index 00000000000..9ca3a67f3c4
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/simulate-thread/bitfields-1.c
@@ -0,0 +1,71 @@
+/* { dg-do link } */
+/* { dg-options "--param allow-store-data-races=0" } */
+/* { dg-final { simulate-thread } } */
+
+#include <stdio.h>
+#include "../../gcc.dg/simulate-thread/simulate-thread.h"
+
+/* Test that we don't store past VAR.A. */
+
+struct S
+{
+ volatile unsigned int a : 4;
+ unsigned char b;
+ unsigned int c : 6;
+} var = { 1, 2, 3 };
+
+static int global = 0;
+
+/* Called before each instruction, simulating another thread
+ executing. */
+void simulate_thread_other_threads()
+{
+ global++;
+ var.b = global;
+ /* Don't go past the 6 bits var.c can hold. */
+ var.c = global % 64;
+}
+
+/* Called after each instruction. Returns 1 if any inconsistency is
+ found, 0 otherwise. */
+int simulate_thread_step_verify()
+{
+ int ret = 0;
+ if (var.b != global)
+ {
+ printf("FAIL: invalid intermediate value for <b>.\n");
+ ret = 1;
+ }
+ if (var.c != global % 64)
+ {
+ printf("FAIL: invalid intermediate value for <c>.\n");
+ ret = 1;
+ }
+ return ret;
+}
+
+/* Called at the end of the program (simulate_thread_fini == 1). Verifies
+ the state of the program and returns 1 if any inconsistency is
+ found, 0 otherwise. */
+int simulate_thread_final_verify()
+{
+ if (var.a != 12)
+ {
+ printf("FAIL: invalid final result for <a>.\n");
+ return 1;
+ }
+ return 0;
+}
+
+__attribute__((noinline))
+void simulate_thread_main()
+{
+ var.a = 12;
+}
+
+int main()
+{
+ simulate_thread_main();
+ simulate_thread_done();
+ return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/simulate-thread/bitfields-2.c b/gcc/testsuite/c-c++-common/simulate-thread/bitfields-2.c
new file mode 100644
index 00000000000..392f779bad5
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/simulate-thread/bitfields-2.c
@@ -0,0 +1,59 @@
+/* { dg-do link } */
+/* { dg-options "--param allow-store-data-races=0" } */
+/* { dg-final { simulate-thread } } */
+
+#include <stdio.h>
+#include "../../gcc.dg/simulate-thread/simulate-thread.h"
+
+/* Test that we don't store past VAR.K. */
+
+struct S
+{
+ volatile int i;
+ volatile int j: 32;
+ volatile int k: 15;
+ volatile unsigned char c[2];
+} var;
+
+static int global = 0;
+
+void simulate_thread_other_threads()
+{
+ global++;
+ var.c[0] = global % 256;
+ var.c[1] = global % 256;
+}
+
+int simulate_thread_step_verify()
+{
+ if (var.c[0] != global % 256
+ || var.c[1] != global % 256)
+ {
+ printf("FAIL: invalid intermediate result for <var.c[]>.\n");
+ return 1;
+ }
+ return 0;
+}
+
+int simulate_thread_final_verify()
+{
+ if (var.k != 13)
+ {
+ printf("FAIL: invalid final result\n");
+ return 1;
+ }
+ return 0;
+}
+
+__attribute__((noinline))
+void simulate_thread_main()
+{
+ var.k = 13;
+}
+
+int main()
+{
+ simulate_thread_main();
+ simulate_thread_done();
+ return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/simulate-thread/bitfields-3.c b/gcc/testsuite/c-c++-common/simulate-thread/bitfields-3.c
new file mode 100644
index 00000000000..78f4d75c8ba
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/simulate-thread/bitfields-3.c
@@ -0,0 +1,63 @@
+/* { dg-do link } */
+/* { dg-options "--param allow-store-data-races=0" } */
+/* { dg-final { simulate-thread } } */
+
+#include <stdio.h>
+#include "../../gcc.dg/simulate-thread/simulate-thread.h"
+
+/* Store into <c> should not clobber <d>. */
+
+struct bits
+{
+ char a;
+ int b:7;
+ int c:9;
+ unsigned char d;
+} var;
+
+static int global = 0;
+
+void simulate_thread_other_threads()
+{
+ global++;
+ var.d = global;
+}
+
+int simulate_thread_step_verify()
+{
+ if (var.d != global)
+ {
+ printf("FAIL: invalid intermediate result\n");
+ return 1;
+ }
+ return 0;
+}
+
+int simulate_thread_final_verify()
+{
+ if (var.c != 5)
+ {
+ printf("FAIL: invalid final result\n");
+ return 1;
+ }
+ return 0;
+}
+
+__attribute__((noinline))
+void update_c(struct bits *p, int val)
+{
+ p -> c = val;
+}
+
+__attribute__((noinline))
+void simulate_thread_main()
+{
+ update_c(&var, 5);
+}
+
+int main()
+{
+ simulate_thread_main();
+ simulate_thread_done();
+ return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/simulate-thread/bitfields-4.c b/gcc/testsuite/c-c++-common/simulate-thread/bitfields-4.c
new file mode 100644
index 00000000000..cd6badf3329
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/simulate-thread/bitfields-4.c
@@ -0,0 +1,60 @@
+/* { dg-do link } */
+/* { dg-options "--param allow-store-data-races=0" } */
+/* { dg-final { simulate-thread } } */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "../../gcc.dg/simulate-thread/simulate-thread.h"
+
+struct bits
+{
+ char a;
+ int b:7;
+ int c:9;
+ unsigned char d;
+} *p;
+
+static int global = 0;
+
+void simulate_thread_other_threads()
+{
+ global++;
+ p->d = global % 256;
+}
+
+int simulate_thread_step_verify()
+{
+ if (p->d != global % 256)
+ {
+ printf("FAIL: invalid intermediate result\n");
+ return 1;
+ }
+ return 0;
+}
+
+int simulate_thread_final_verify()
+{
+ if (p->c != 55)
+ {
+ printf("FAIL: invalid final result\n");
+ return 1;
+ }
+ return 0;
+}
+
+/* Store into <c> should not clobber <d>. */
+/* We should not use a 32-bit move to store into p->, but a smaller move. */
+__attribute__((noinline))
+void simulate_thread_main()
+{
+ p -> c = 55;
+}
+
+
+int main()
+{
+ p = (struct bits *) calloc (1, sizeof (struct bits));
+ simulate_thread_main();
+ simulate_thread_done();
+ return 0;
+}