Index: configure.in
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/configure.in,v
retrieving revision 1.481
diff -u -r1.481 configure.in
--- configure.in	29 Nov 2006 04:50:43 -0000	1.481
+++ configure.in	21 Dec 2006 11:51:23 -0000
@@ -195,7 +195,7 @@
 case "$host" in
 	i*86-*-solaris2.*)	link_static_opt= ;;
 	*solaris2.10)		link_static_opt= ;;
-	*powerpc*apple*darwin*) link_static_opt= ;;
+	*apple*darwin*)		link_static_opt= ;;
 	*)			link_static_opt="--linkage static" ;;
 esac
 
@@ -2036,6 +2036,22 @@
 	AC_DEFINE(MR_BZERO_NEEDS_STRINGS_HEADER)
 fi
 AC_SUBST(MR_BZERO_NEEDS_STRINGS_HEADER)
+
+#-----------------------------------------------------------------------------#
+#
+# With some versions of gcc on Darwin __builtin_setjmp is broken.
+# (See gcc bug 22099)
+
+# XXX we should only disable the use of __builtin_setjmp for those
+# versions of gcc that are broken - the problem will be fixed in gcc 4.2
+case "$host" in
+	i*86*apple*darwin*)
+	AC_DEFINE(MR_DARWIN_SETJMP_WORKAROUND)
+	;;
+esac
+
+AC_SUBST(MR_DARWIN_SETJMP_WORKAROUND)
+
 #-----------------------------------------------------------------------------#
 #
 # On sparc, x86, and probably on other architectures,
Index: runtime/mercury.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury.h,v
retrieving revision 1.75
diff -u -r1.75 mercury.h
--- runtime/mercury.h	20 Aug 2006 05:01:48 -0000	1.75
+++ runtime/mercury.h	21 Dec 2006 11:52:11 -0000
@@ -161,9 +161,12 @@
 **	    function as the call to __builtin_setjmp().
 */
 #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
-  #define MR_builtin_setjmp(buf)	__builtin_setjmp((buf))
-  #define MR_builtin_longjmp(buf, val)	__builtin_longjmp((buf), (val))
-#else
+  #ifndef MR_DARWIN_SETJMP_WORKAROUND
+    #define MR_builtin_setjmp(buf)	__builtin_setjmp((buf))
+    #define MR_builtin_longjmp(buf, val)	__builtin_longjmp((buf), (val))
+  #endif
+#endif
+#ifndef MR_builtin_setjmp
   #define MR_builtin_setjmp(buf)	setjmp((buf))
   #define MR_builtin_longjmp(buf, val)	longjmp((buf), (val))
 #endif
Index: runtime/mercury_conf.h.in
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_conf.h.in,v
retrieving revision 1.58
diff -u -r1.58 mercury_conf.h.in
--- runtime/mercury_conf.h.in	28 Nov 2006 06:57:42 -0000	1.58
+++ runtime/mercury_conf.h.in	21 Dec 2006 11:52:12 -0000
@@ -450,6 +450,11 @@
 #undef MR_BZERO_NEEDS_STRINGS_HEADER
 
 /*
+** __builtin_setjmp is broken with some versions of gcc on Darwin.
+*/
+#undef MR_DARWIN_SETJMP_WORKAROUND
+
+/*
 ** MR_USE_EXTERNAL_DEBUGGER:
 **	Allow MR_trace() to use an external process debugger
 **	(with communication done via a socket interface)
