Move the test for __sync_bool_compare_and_swap almost to the bottom,
so it can use $mflag_primary.  This makes the word size for which the
test is done (-m32 or -m64) be the same as for which it is actually
needed, and in some situations unbreaks building of the regtests in
32-bit mode on a 64-bit machine.

For the same reason, apply $mflag_primary to the test for OpenMP.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9034 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/configure.in b/configure.in
index 3ca0ef0..b6e6b27 100644
--- a/configure.in
+++ b/configure.in
@@ -1215,24 +1215,6 @@
 fi
 
 
-# does this compiler have built-in functions for atomic memory access ?
-AC_MSG_CHECKING([if gcc supports __sync_bool_compare_and_swap])
-
-AC_TRY_LINK(,
-[
-  int variable = 1;
-  return (__sync_bool_compare_and_swap(&variable, 1, 2)
-         && __sync_add_and_fetch(&variable, 1) ? 1 : 0)
-],
-[
-  AC_MSG_RESULT([yes])
-  AC_DEFINE(HAVE_BUILTIN_ATOMIC, 1, [Define to 1 if gcc supports __sync_bool_compare_and_swap() a.o.])
-],
-[
-  AC_MSG_RESULT([no])
-])
-
-
 # does the ppc assembler support "mtocrf" et al?
 AC_MSG_CHECKING([if ppc32/64 as supports mtocrf/mfocrf])
 
@@ -1647,7 +1629,7 @@
 AC_MSG_CHECKING([for OpenMP])
 
 safe_CFLAGS=$CFLAGS
-CFLAGS="-fopenmp"
+CFLAGS="-fopenmp $mflag_primary"
 
 AC_LINK_IFELSE(
 [
@@ -1670,6 +1652,29 @@
 AM_CONDITIONAL([HAVE_OPENMP], [test x$ac_have_openmp = xyes])
 
 
+# does this compiler have built-in functions for atomic memory access ?
+AC_MSG_CHECKING([if gcc supports __sync_bool_compare_and_swap])
+
+safe_CFLAGS=$CFLAGS
+CFLAGS="$mflag_primary"
+
+AC_TRY_LINK(,
+[
+  int variable = 1;
+  return (__sync_bool_compare_and_swap(&variable, 1, 2)
+          && __sync_add_and_fetch(&variable, 1) ? 1 : 0)
+],
+[
+  AC_MSG_RESULT([yes])
+  AC_DEFINE(HAVE_BUILTIN_ATOMIC, 1, [Define to 1 if gcc supports __sync_bool_compare_and_swap() a.o.])
+],
+[
+  AC_MSG_RESULT([no])
+])
+
+CFLAGS=$safe_CFLAGS
+
+
 #----------------------------------------------------------------------------
 # Ok.  We're done checking.
 #----------------------------------------------------------------------------