diff gcc/testsuite/c-c++-common/simulate-thread/bitfields-4.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 1830386684a0
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/c-c++-common/simulate-thread/bitfields-4.c	Fri Oct 27 22:46:09 2017 +0900
@@ -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;
+}