Patchwork [trunk] contribute GDB/thread testing infrastructure from cxx-mem-model branch

login
register
mail settings
Submitter Aldy Hernandez
Date Sept. 21, 2011, 7:02 p.m.
Message ID <4E7A34BA.6010203@redhat.com>
Download mbox | patch
Permalink /patch/115842/
State New
Headers show

Comments

Aldy Hernandez - Sept. 21, 2011, 7:02 p.m.
I've gotten tired of the false positives in the current testsuite for 
the cxxbitfield* tests.  The tests are highly dependent on assembly 
output, and currently they only work on x86-64/x86-32 (mostly).

I have rewritten the tests to be platform agnostic, by using the 
GDB/thread testing infrastructure from the cxx-mem-model branch.

The original submission happened here:

http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00535.html

I would like to officially contribute the testing infrastructure, which 
not only benefits the bitfield tests, but all the tests Andrew MacLeod 
will bring over when we merge the entire cxx-mem-model branch.

I have rewritten and adapted all the current bitfield tests that are 
store data race dependent.

I am open to a better name than "memmodel".  If any one has a better 
idea, I'm sed competent.

OK for trunk?
testsuite/
	* lib/gcc-memmodel-gdb-test.exp: New.
	* gcc.dg/memmodel/guality.h: New.
	* gcc.dg/memmodel/memmodel.h: New.
	* gcc.dg/memmodel/memmodel.exp: New.
	* gcc.dg/memmodel/memmodel.gdb: New.
	* gcc.dg/memmodel/README: New.
	* g++.dg/memmodel/guality.h: New.
	* g++.dg/memmodel/memmodel.h: New.
	* g++.dg/memmodel/memmodel.exp: New.
	* g++.dg/memmodel/memmodel.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/memmodel/bitfields-1.c: New.
	* c-c++-common/memmodel/bitfields-2.c: New.
	* c-c++-common/memmodel/bitfields-3.c: New.
	* c-c++-common/memmodel/bitfields-4.c: New.
Andrew MacLeod - Sept. 22, 2011, 3:53 p.m.
>
> I have rewritten and adapted all the current bitfield tests that are 
> store data race dependent.
>
> I am open to a better name than "memmodel".  If any one has a better 
> idea, I'm sed competent.

I'd definately suggest something more generic which gives an indication 
of whats being done... memmodel is too specific since I think it'll be 
testing more than memory-model functionality now.

It invokes GDB to step through the program, looking at and/or modifying 
memory every simulated cycle of a function's execution, and checking to 
make sure execution proceeds as expected.

off the top of my head, maybe something like one of the following:

step-through
gdb-invoked
side-effects
simulate-thread

Or something else you can think of that is more appropriate generic name 
for the types of tests.

Andrew
Aldy Hernandez - Sept. 22, 2011, 4:47 p.m.
> off the top of my head, maybe something like one of the following:
>
> step-through
> gdb-invoked
> side-effects
> simulate-thread

simulate-thread or step-through sound fine.  I'd vote for 
simulate-thread, but really-- whatever...

Patch

Index: testsuite/lib/gcc-memmodel-gdb-test.exp
===================================================================
--- testsuite/lib/gcc-memmodel-gdb-test.exp	(revision 0)
+++ testsuite/lib/gcc-memmodel-gdb-test.exp	(revision 0)
@@ -0,0 +1,77 @@ 
+#   Copyright (C) 2011 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# Utility for running a given test through the memmodel harness using gdb.
+# This is invoked via dg-final.
+#
+# Adapted from the guality harness.
+#
+# Call 'fail' if a given test printed "FAIL:", otherwise call 'pass'.
+
+proc memmodel-gdb-test { args } {
+    if { ![isnative] || [is_remote target] } { return }
+
+    if { [llength $args] == 1 } {
+	switch [dg-process-target [lindex $args 0]] {
+		"F" { setup_xfail "*-*-*" }
+	}
+    }
+
+    # This assumes that we are three frames down from dg-test, and that
+    # it still stores the filename of the testcase in a local variable "name".
+    # A cleaner solution would require a new DejaGnu release.
+    upvar 2 name testcase
+    upvar 2 prog prog
+    upvar 2 srcdir testsuite_dir
+
+    set gdb_name $::env(GUALITY_GDB_NAME)
+    set exec_file "[file rootname [file tail $prog]].exe"
+    set cmd_file "$testsuite_dir/gcc.dg/memmodel/memmodel.gdb"
+
+    if ![file exists $exec_file] {
+	return
+    }
+
+    send_log "Spawning: $gdb_name -nx -nw -quiet -x $cmd_file ./$exec_file\n"
+    set res [remote_spawn target "$gdb_name -nx -nw  -x $cmd_file ./$exec_file"]
+    if { $res < 0 || $res == "" } {
+	unsupported "$testcase"
+	return
+    }
+
+    remote_expect target [timeout_value] {
+	-re "FAIL:" {
+	    fail "$testcase"
+	    remote_close target
+	    return
+	}
+	# Too old GDB
+	-re "Unhandled dwarf expression|Error in sourced command file" {
+	    unsupported "$testcase"
+	    remote_close target
+	    return
+	}
+	timeout {
+	    unsupported "$testcase"
+	    remote_close target
+	    return
+	}
+    }
+
+    remote_close target
+    pass "$testcase"
+    return
+}
Index: testsuite/gcc.dg/memmodel/guality.h
===================================================================
--- testsuite/gcc.dg/memmodel/guality.h	(revision 0)
+++ testsuite/gcc.dg/memmodel/guality.h	(revision 0)
@@ -0,0 +1 @@ 
+#include "../../gcc.dg/guality/guality.h"
Index: testsuite/gcc.dg/memmodel/memmodel.h
===================================================================
--- testsuite/gcc.dg/memmodel/memmodel.h	(revision 0)
+++ testsuite/gcc.dg/memmodel/memmodel.h	(revision 0)
@@ -0,0 +1,7 @@ 
+int memmodel_fini = 0;
+
+void __attribute__((noinline))
+memmodel_done ()
+{
+  memmodel_fini = 1;
+}
Index: testsuite/gcc.dg/memmodel/memmodel.exp
===================================================================
--- testsuite/gcc.dg/memmodel/memmodel.exp	(revision 0)
+++ testsuite/gcc.dg/memmodel/memmodel.exp	(revision 0)
@@ -0,0 +1,74 @@ 
+# Copyright (C) 2011 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# Your run of the mill dg test, but verify that we have a working GDB first.
+
+load_lib gcc-dg.exp
+load_lib gcc-memmodel-gdb-test.exp
+load_lib torture-options.exp
+
+proc check_guality {args} {
+    set result [eval check_compile guality_check executable $args "-g -O0"]
+    set lines [lindex $result 0]
+    set output [lindex $result 1]
+    set ret 0
+    if {[string match "" $lines]} {
+      set execout [gcc_load "./$output"]
+      set ret [string match "*1 PASS, 0 FAIL, 0 UNRESOLVED*" $execout]
+    }
+    remote_file build delete $output
+    return $ret
+}
+
+dg-init
+torture-init
+set-torture-options [list \
+	{ -O0 -g } \
+	{ -O1 -g } \
+	{ -O2 -g } \
+	{ -O3 -g } \
+	{ -Os -g } ]
+
+# Test the presence of gdb with the guality infrastructure.
+global GDB
+if ![info exists ::env(GUALITY_GDB_NAME)] {
+    if [info exists GDB] {
+	set guality_gdb_name "$GDB"
+    } else {
+	set guality_gdb_name "[transform gdb]"
+    }
+    setenv GUALITY_GDB_NAME "$guality_gdb_name"
+}
+
+if {[check_guality "
+  #include \"$srcdir/$subdir/guality.h\"
+  volatile long int varl = 6;
+  int main (int argc, char *argv\[\])
+  {
+    GUALCHKVAL (varl);
+    return 0;
+  }
+"]} {
+  gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.c]] ""
+  gcc-dg-runtest [lsort [glob $srcdir/c-c++-common/memmodel/*.c]] ""
+}
+
+if [info exists guality_gdb_name] {
+    unsetenv GUALITY_GDB_NAME
+}
+
+torture-finish
+dg-finish
Index: testsuite/gcc.dg/memmodel/memmodel.gdb
===================================================================
--- testsuite/gcc.dg/memmodel/memmodel.gdb	(revision 0)
+++ testsuite/gcc.dg/memmodel/memmodel.gdb	(revision 0)
@@ -0,0 +1,17 @@ 
+set height 0
+break memmodel_main
+disp/i $pc
+run
+
+set $ret = 0
+while (memmodel_fini != 1) && (! $ret)
+  call memmodel_other_threads()
+  stepi
+  set $ret |= memmodel_step_verify()
+end
+
+if (! $ret)
+  set $ret |= memmodel_final_verify()
+end
+continue
+quit $ret
Index: testsuite/gcc.dg/memmodel/README
===================================================================
--- testsuite/gcc.dg/memmodel/README	(revision 0)
+++ testsuite/gcc.dg/memmodel/README	(revision 0)
@@ -0,0 +1,118 @@ 
+OVERVIEW
+--------
+
+This is a harness to test the atomicity of certain operations, and to
+make sure the compiler does not introduce data races in a
+multi-threaded environment.
+
+The basic premise is that we set up testcases such that the thing we
+want test, say an atomic instruction which stores a double word is in
+a function of its own.  We then run this testcase within GDB,
+controlled by a gdb script (memmodel.gdb).  The gdb script will break
+on the function to be tested, and then single step through every
+machine instruction in the function.  We set this up so GDB can make a
+couple of inferior function calls before and after each of these
+single step instructions for a couple of purposes:
+
+       1.  One of the calls simulates another thread running in the
+           process which changes or access memory.
+
+       2.  The other calls are used to verify that we always get the
+           expected behavior.
+
+For example, in the case of an atomic store, anyone looking at the
+memory associated with an atomic variable should never see any in
+between states. If you have an atomic long long int, and it starts
+with the value 0, and you write the value MAX_LONG_LONG, any other
+thread looking at that variable should never see anything other than 0
+or MAX_LONG_LONG.  If you implement the atomic write as a sequence of
+2 stores, it is possible for another thread to read the location after
+the first store, but before the second one is complete. That thread
+would then see an in-between state (one word would still be 0).
+
+We simulate this in the testcase by having GDB step through the
+program, instruction by instruction, and after each step, making an
+inferior function call which looks at the value of the atomic variable
+and verifies that it sees either 0 or MAX_LONG_LONG.  If it sees any
+other value, it fails the testcase.
+
+This way, we are *sure* there is no in between state because we
+effectively acted like an OS and switched to another thread after
+every single instruction of the routine is executed and looked at the
+results each time.
+
+We use the same idea to test for data races to see if an illegal load
+has been hoisted, or that two parallel bitfield writes don't overlap
+in a data race.
+
+Below is a skeleton of how a test should look like.  For more details,
+look at the tests themselves.
+
+ANATOMY OF A TEST
+-----------------
+
+/* { dg-do link } */
+/* { dg-options "-some-flags" } */
+/* { dg-final { memmodel-gdb-test } } */
+
+/* NOTE: Any failure must be indicated by displaying "FAIL:".  */
+
+#include "memmodel.h"
+
+/* Called before each instruction, simulating another thread executing.  */
+void memmodel_other_threads()
+{
+}
+
+/* Called after each instruction.  Returns 1 if any inconsistency is
+   found, 0 otherwise.  */
+int memmodel_step_verify()
+{
+  if (some_problem)
+    {
+      printf("FAIL: reason\n");
+      return 1;
+    }
+  return 0;
+}
+
+/* Called at the end of the program (memmodel_fini == 1).  Verifies
+   the state of the program and returns 1 if any inconsistency is
+   found, 0 otherwise.  */
+int memmodel_final_verify()
+{
+  if (some_problem)
+    {
+      printf("FAIL: reason\n");
+      return 1;
+    }
+  return 0;
+}
+
+/* The gdb script will break on memmodel_main(), so make sure GCC does
+   not inline it, thus making the break point fail.  */
+__attribute__((noinline))
+void memmodel_main()
+{
+  /* Do stuff.  */
+}
+
+int main()
+{
+
+  /* Perform any setup code that will run outside of the testing
+     harness.  Put code here that you do NOT want to be interrupted on
+     an instruction basis.  E.g., setup code, and system library
+     calls.  */
+
+     /* Do un-instrumented stuff. */
+     /* ... */
+
+  /* Start the instrumented show.  */
+  memmodel_main();
+
+  /* Must be called at the end of the test.  */
+  memmodel_done();
+
+  return 0;
+}
Index: testsuite/g++.dg/memmodel/guality.h
===================================================================
--- testsuite/g++.dg/memmodel/guality.h	(revision 0)
+++ testsuite/g++.dg/memmodel/guality.h	(revision 0)
@@ -0,0 +1 @@ 
+#include "../../gcc.dg/guality/guality.h"
Index: testsuite/g++.dg/memmodel/memmodel.h
===================================================================
--- testsuite/g++.dg/memmodel/memmodel.h	(revision 0)
+++ testsuite/g++.dg/memmodel/memmodel.h	(revision 0)
@@ -0,0 +1 @@ 
+#include "../../gcc.dg/memmodel/memmodel.h"
Index: testsuite/g++.dg/memmodel/memmodel.exp
===================================================================
--- testsuite/g++.dg/memmodel/memmodel.exp	(revision 0)
+++ testsuite/g++.dg/memmodel/memmodel.exp	(revision 0)
@@ -0,0 +1,74 @@ 
+# Copyright (C) 2011 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+
+# Your run of the mill dg test, but verify that we have a working GDB first.
+
+load_lib g++-dg.exp
+load_lib gcc-memmodel-gdb-test.exp
+load_lib torture-options.exp
+
+proc check_guality {args} {
+    set result [eval check_compile guality_check executable $args "-g -O0"]
+    set lines [lindex $result 0]
+    set output [lindex $result 1]
+    set ret 0
+    if {[string match "" $lines]} {
+      set execout [g++_load "./$output"]
+      set ret [string match "*1 PASS, 0 FAIL, 0 UNRESOLVED*" $execout]
+    }
+    remote_file build delete $output
+    return $ret
+}
+
+dg-init
+torture-init
+set-torture-options [list \
+	{ -O0 -g } \
+	{ -O1 -g } \
+	{ -O2 -g } \
+	{ -O3 -g } \
+	{ -Os -g } ]
+
+# Test the presence of gdb with the guality infrastructure.
+global GDB
+if ![info exists ::env(GUALITY_GDB_NAME)] {
+    if [info exists GDB] {
+	set guality_gdb_name "$GDB"
+    } else {
+	set guality_gdb_name "[transform gdb]"
+    }
+    setenv GUALITY_GDB_NAME "$guality_gdb_name"
+}
+if {[check_guality "
+  #include \"$srcdir/$subdir/guality.h\"
+  volatile long int varl = 6;
+  int main (int argc, char *argv\[\])
+  {
+    GUALCHKVAL (varl);
+    return 0;
+  }
+"]} {
+  gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C]] ""
+  gcc-dg-runtest [lsort [glob $srcdir/c-c++-common/memmodel/*.c]] ""
+}
+
+if [info exists guality_gdb_name] {
+    unsetenv GUALITY_GDB_NAME
+}
+
+torture-finish
+dg-finish
Index: testsuite/g++.dg/memmodel/memmodel.gdb
===================================================================
--- testsuite/g++.dg/memmodel/memmodel.gdb	(revision 0)
+++ testsuite/g++.dg/memmodel/memmodel.gdb	(revision 0)
@@ -0,0 +1 @@ 
+source ../../gcc.dg/memmodel/memmodel.gdb
Index: testsuite/c-c++-common/cxxbitfields-2.c
===================================================================
--- testsuite/c-c++-common/cxxbitfields-2.c	(revision 178608)
+++ testsuite/c-c++-common/cxxbitfields-2.c	(working copy)
@@ -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" } } */
Index: testsuite/c-c++-common/cxxbitfields.c
===================================================================
--- testsuite/c-c++-common/cxxbitfields.c	(revision 178608)
+++ testsuite/c-c++-common/cxxbitfields.c	(working copy)
@@ -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" } } */
Index: testsuite/c-c++-common/cxxbitfields-4.c
===================================================================
--- testsuite/c-c++-common/cxxbitfields-4.c	(revision 178608)
+++ testsuite/c-c++-common/cxxbitfields-4.c	(working copy)
@@ -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\]" } } */
Index: testsuite/c-c++-common/memmodel/bitfields-1.c
===================================================================
--- testsuite/c-c++-common/memmodel/bitfields-1.c	(revision 0)
+++ testsuite/c-c++-common/memmodel/bitfields-1.c	(revision 0)
@@ -0,0 +1,71 @@ 
+/* { dg-do link } */
+/* { dg-options "--param allow-store-data-races=0" } */
+/* { dg-final { memmodel-gdb-test } } */
+
+#include <stdio.h>
+#include "../../gcc.dg/memmodel/memmodel.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 memmodel_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 memmodel_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 (memmodel_fini == 1).  Verifies
+   the state of the program and returns 1 if any inconsistency is
+   found, 0 otherwise.  */
+int memmodel_final_verify()
+{
+  if (var.a != 12)
+    {
+      printf("FAIL: invalid final result for <a>.\n");
+      return 1;
+    }
+  return 0;
+}
+
+__attribute__((noinline))
+void memmodel_main()
+{
+  var.a = 12;
+}
+
+int main()
+{
+  memmodel_main();
+  memmodel_done();
+  return 0;
+}
Index: testsuite/c-c++-common/memmodel/bitfields-2.c
===================================================================
--- testsuite/c-c++-common/memmodel/bitfields-2.c	(revision 0)
+++ testsuite/c-c++-common/memmodel/bitfields-2.c	(revision 0)
@@ -0,0 +1,59 @@ 
+/* { dg-do link } */
+/* { dg-options "--param allow-store-data-races=0" } */
+/* { dg-final { memmodel-gdb-test } } */
+
+#include <stdio.h>
+#include "../../gcc.dg/memmodel/memmodel.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 memmodel_other_threads()
+{
+  global++;
+  var.c[0] = global % 256;
+  var.c[1] = global % 256;
+}
+
+int memmodel_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 memmodel_final_verify()
+{
+  if (var.k != 13)
+    {
+      printf("FAIL: invalid final result\n");
+      return 1;
+    }
+  return 0;
+}
+
+__attribute__((noinline))
+void memmodel_main()
+{
+  var.k = 13;
+}
+
+int main()
+{
+  memmodel_main();
+  memmodel_done();
+  return 0;
+}
Index: testsuite/c-c++-common/memmodel/bitfields-3.c
===================================================================
--- testsuite/c-c++-common/memmodel/bitfields-3.c	(revision 0)
+++ testsuite/c-c++-common/memmodel/bitfields-3.c	(revision 0)
@@ -0,0 +1,63 @@ 
+/* { dg-do link } */
+/* { dg-options "--param allow-store-data-races=0" } */
+/* { dg-final { memmodel-gdb-test } } */
+
+#include <stdio.h>
+#include "../../gcc.dg/memmodel/memmodel.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 memmodel_other_threads()
+{
+  global++;
+  var.d = global;
+}
+
+int memmodel_step_verify()
+{
+  if (var.d != global)
+    {
+      printf("FAIL: invalid intermediate result\n");
+      return 1;
+    }
+  return 0;
+}
+
+int memmodel_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 memmodel_main()
+{
+  update_c(&var, 5);
+}
+
+int main()
+{
+  memmodel_main();
+  memmodel_done();
+  return 0;
+}
Index: testsuite/c-c++-common/memmodel/bitfields-4.c
===================================================================
--- testsuite/c-c++-common/memmodel/bitfields-4.c	(revision 0)
+++ testsuite/c-c++-common/memmodel/bitfields-4.c	(revision 0)
@@ -0,0 +1,60 @@ 
+/* { dg-do link } */
+/* { dg-options "--param allow-store-data-races=0" } */
+/* { dg-final { memmodel-gdb-test } } */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "../../gcc.dg/memmodel/memmodel.h"
+
+struct bits
+{
+  char a;
+  int b:7;
+  int c:9;
+  unsigned char d;
+} *p;
+
+static int global = 0;
+
+void memmodel_other_threads()
+{
+  global++;
+  p->d = global % 256;
+}
+
+int memmodel_step_verify()
+{
+  if (p->d != global % 256)
+    {
+      printf("FAIL: invalid intermediate result\n");
+      return 1;
+    }
+  return 0;
+}
+
+int memmodel_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 memmodel_main()
+{
+  p -> c = 55;
+}
+  
+
+int main()
+{
+  p = (struct bits *) calloc (1, sizeof (struct bits));
+  memmodel_main();
+  memmodel_done();
+  return 0;
+}
Index: testsuite/c-c++-common/cxxbitfields-5.c
===================================================================
--- testsuite/c-c++-common/cxxbitfields-5.c	(revision 178608)
+++ testsuite/c-c++-common/cxxbitfields-5.c	(working copy)
@@ -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\]" } } */