[m-dev.] diff: fixes for gcc-2.95

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Oct 21 00:25:22 AEST 1999


Port to gcc-2.95.2.

runtime/mercury_dummy.h:
runtime/mercury_dummy.c:
	Add a new function dummy_identity_function()
	which just returns its argument.

runtime/mercury_goto.h:
	Add a `goto *dummy_identity_function(label);' statement
	into the BEGIN_MODULE() macro, to ensure that gcc
	doesn't optimize away labels which it thinks are
	unreachable but which are actually reached via
	non-local gotos.

configure.in:
	Change the autoconf test for gcc labels, in the same way
	that runtime/mercury_goto.h was changed, so that it passes
	with gcc-2.95.2.

Workspace: /home/pgrad/fjh/mercury-compiler-rotd-1999-10-17
Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.182
diff -u -d -r1.182 configure.in
--- configure.in	1999/10/11 06:29:27	1.182
+++ configure.in	1999/10/20 14:22:00
@@ -1344,8 +1344,11 @@
 	void *entry_bar_1;
 	void *succip;
 	int global;
+	void *dummy_identity_function(void *);
 	foo() {
 		entry_foo_1 = && foo_1;
+		goto *dummy_identity_function(&&return_label);
+	return_label:
 		return;
 	foo_1:
 		if (global != 42) exit(1);
@@ -1353,6 +1356,8 @@
 	}
 	bar() {
 		entry_bar_1 = && bar_1;
+		goto *dummy_identity_function(&&return_label);
+	return_label:
 		return;
 	bar_1:
 		if (global != 42) exit(1);
@@ -1363,12 +1368,18 @@
 		foo();
 		bar();
 		succip = &&last;
+		goto *dummy_identity_function(&&return_label);
+	return_label:
 		goto *entry_foo_1;
 		exit(1);
 	last:
 		if (global != 42) exit(1);
 		exit(0);
-	}], [mercury_cv_gcc_labels=yes], [mercury_cv_gcc_labels=no],
+	}
+	void *dummy_identity_function(void *p) {
+		return p;
+	}
+	], [mercury_cv_gcc_labels=yes], [mercury_cv_gcc_labels=no],
 		[mercury_cv_gcc_labels=no])
 )
 AC_MSG_RESULT($mercury_cv_gcc_labels)
Index: runtime/mercury_dummy.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_dummy.c,v
retrieving revision 1.3
diff -u -d -r1.3 mercury_dummy.c
--- mercury_dummy.c	1997/12/05 15:56:29	1.3
+++ mercury_dummy.c	1999/10/20 14:22:00
@@ -15,7 +15,14 @@
 void	*global_pointer;
 void	*global_pointer_2;
 
-void dummy_function_call(void)
+void
+dummy_function_call(void)
 {
 	return;
+}
+
+void *
+dummy_identify_function(void *p)
+{
+	return p;
 }
Index: runtime/mercury_dummy.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_dummy.h,v
retrieving revision 1.2
diff -u -d -r1.2 mercury_dummy.h
--- mercury_dummy.h	1997/11/23 07:21:20	1.2
+++ mercury_dummy.h	1999/10/20 14:22:00
@@ -16,6 +16,7 @@
 #define	MERCURY_DUMMY_H
 
 extern	void	dummy_function_call(void);
+extern	void	*dummy_identify_function(void *);
 extern	void	*global_pointer;
 extern	void	*global_pointer_2;
 
Index: runtime/mercury_goto.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_goto.h,v
retrieving revision 1.19
diff -u -d -r1.19 mercury_goto.h
--- mercury_goto.h	1999/04/26 03:34:32	1.19
+++ mercury_goto.h	1999/10/20 14:22:00
@@ -13,6 +13,7 @@
 #include "mercury_types.h"	/* for `Code *' */
 #include "mercury_debug.h"	/* for debuggoto() */
 #include "mercury_label.h"	/* for insert_{entry,internal}_label() */
+#include "mercury_dummy.h"	/* for dummy_identify_function() */
 
 #define paste(a,b) a##b
 #define stringify(string) #string
@@ -484,13 +485,21 @@
   ** cannot be live, when in fact they really are).
   ** That is what the two occurrences of the PRETEND_ADDRESS_IS_USED
   ** macro are for.
+  ** We also need to include at least one `goto *' with an unknown
+  ** target, so that gcc doesn't optimize away all the labels
+  ** because it thinks they are unreachable.
+  ** The dummy_identify_function() function just returns the address
+  ** passed to it, so `goto *dummy_identify_function(&& dummy_label); dummy_label:'
+  ** is the same as `goto dummy_label; label:', i.e. it just falls through.
   */
-  #define BEGIN_MODULE(module_name)	\
-	MR_MODULE_STATIC_OR_EXTERN void module_name(void); \
-	MR_MODULE_STATIC_OR_EXTERN void module_name(void) { \
-		PRETEND_ADDRESS_IS_USED(module_name); \
-		PRETEND_ADDRESS_IS_USED(&& paste(module_name, _dummy_label)); \
-		paste(module_name,_dummy_label): \
+  #define BEGIN_MODULE(module_name)					\
+	MR_MODULE_STATIC_OR_EXTERN void module_name(void);		\
+	MR_MODULE_STATIC_OR_EXTERN void module_name(void) {		\
+		PRETEND_ADDRESS_IS_USED(module_name);			\
+		PRETEND_ADDRESS_IS_USED(&&paste(module_name,_dummy_label)); \
+		goto *dummy_identify_function(				\
+			&&paste(module_name,_dummy_label));		\
+		paste(module_name,_dummy_label):			\
 		{
   /* initialization code for module goes here */
   #define BEGIN_CODE } return; {

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list