[m-rev.] for review: fix library header files overriding system header files

Simon Taylor stayl at cs.mu.OZ.AU
Mon Sep 3 00:38:41 AEST 2001


I'm not sure whether it's a good idea to commit this change.

Simon.



Estimated hours taken: 6

scripts/mgnuc.in:
scripts/mercury_compile.m:
	Don't allow header files generated by the Mercury compiler
	to override the system header files. Unfortunately, this fix
	only works with GCC. We should avoid generating header files
	which clash with system headers.

	This fixes a problem that caused the compiler compiled with
	`--intermodule-optimization' to go into an infinite loop during
	termination analysis while compiling list.m. I think this problem
	was triggered by Tyson's change to implement exception handling
	for the .NET backend, which added a `:- pragma export' declaration
	to library/math.m. The generated library/math.h file was being
	selected in preference to /usr/include/math.h, which was causing
	compiler/term_pass1.c to be miscompiled. 

	This change shouldn't be needed at the moment. My change to improve
	error handling in the library removed the `:- pragma export'
	declaration from math.m.

Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.215
diff -u -u -r1.215 mercury_compile.m
--- compiler/mercury_compile.m	2001/08/11 14:09:45	1.215
+++ compiler/mercury_compile.m	2001/09/01 20:54:50
@@ -3387,22 +3387,28 @@
 	globals__io_lookup_accumulating_option(cflags, C_Flags_List),
 	{ join_string_list(C_Flags_List, "", "", " ", CFLAGS) },
 
-	globals__io_lookup_bool_option(use_subdirs, UseSubdirs),
-	globals__io_lookup_bool_option(split_c_files, SplitCFiles),
-	{ (UseSubdirs = yes ; SplitCFiles = yes) ->
-		% the source file (foo.c) will be compiled in a subdirectory
-		% (either Mercury/cs, foo.dir, or Mercury/dirs/foo.dir,
-		% depending on which of these two options is set)
-		% so we need to add `-I.' so it can
-		% include header files in the source directory.
-		SubDirInclOpt = "-I. "
-	;
-		SubDirInclOpt = ""
-	},
 	globals__io_lookup_accumulating_option(c_include_directory,
 	 	C_Incl_Dirs),
-	{ InclOpt = string__append_list(list__condense(list__map(
-	 	(func(C_INCL) = ["-I", C_INCL, " "]), C_Incl_Dirs))) },
+
+	% The `-I-' option stops GCC searching the current directory
+	% first, so add it back here. 
+	% It's also needed for `--use-subdirs' and `--split-c-files'.
+	% The source file (foo.c) will be compiled in a subdirectory
+	% (either Mercury/cs, foo.dir, or Mercury/dirs/foo.dir,
+	% depending on which of these two options is set)
+	% so we need to add `-I.' so it can
+	% include header files in the source directory.
+	{ InclOpt = string__append_list(
+		["-I. " | list__condense(list__map(
+	 	    (func(C_INCL) = ["-I", C_INCL, " "]), C_Incl_Dirs))]) },
+
+	% `-I-' stops GCC searching in the user's include directories 
+	% for system header files. For example, it stops GCC finding
+	% library/math.h instead of /usr/include/math.h. C compilers
+	% which don't support `-I-' should harmlessly misinterpret this
+	% as a search directory `-'.
+	{ SystemInclOpt = "-I-" },
+
 	globals__io_lookup_bool_option(split_c_files, Split_C_Files),
 	{ Split_C_Files = yes ->
 		SplitOpt = "-DSPLIT_C_FILES "
@@ -3599,7 +3605,7 @@
 	% e.g. CFLAGS_FOR_REGS must come after OptimizeOpt so that
 	% it can override -fomit-frame-pointer with -fno-omit-frame-pointer.
 	% Also be careful that each option is separated by spaces.
-	{ string__append_list([CC, " ", SubDirInclOpt, InclOpt,
+	{ string__append_list([CC, " ", InclOpt,
 		SplitOpt, OptimizeOpt,
 		HighLevelCodeOpt, NestedFunctionsOpt, HighLevelDataOpt,
 		RegOpt, GotoOpt, AsmOpt,
@@ -3610,7 +3616,7 @@
 		Target_DebugOpt, LL_DebugOpt,
 		StackTraceOpt, RequireTracingOpt,
 		UseTrailOpt, MinimalModelOpt, TypeLayoutOpt,
-		InlineAllocOpt, WarningOpt, CFLAGS,
+		InlineAllocOpt, WarningOpt, CFLAGS, SystemInclOpt,
 		" -c ", C_File, " ", NameObjectFile, O_File], Command) },
 	invoke_system_command(Command, Succeeded),
 	( { Succeeded = no } ->
Index: scripts/mgnuc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mgnuc.in,v
retrieving revision 1.82
diff -u -u -r1.82 mgnuc.in
--- scripts/mgnuc.in	2001/06/27 05:04:42	1.82
+++ scripts/mgnuc.in	2001/09/01 20:21:51
@@ -479,6 +479,13 @@
 	esac ;;
 esac
 
+# `-I-' stops GCC searching in the user's include directories
+# for system header files. For example, it stops GCC finding
+# library/math.h instead of /usr/include/math.h. C compilers
+# which don't support `-I-' should harmlessly misinterpret this
+# as a search directory `-'.
+OVERRIDE_OPTS="$OVERRIDE_OPTS -I-"
+
 #
 # On sparc-sun-solaris2, we need to use -fPIC rather than -fpic if we're
 # using grade `none', because otherwise the Mercury standard library
@@ -501,7 +508,9 @@
 esac
 
 
-ALL_CC_OPTS="$MERC_ALL_C_INCL_DIRS $ANSI_OPTS $CHECK_OPTS $OPT_OPTS \
+# The `-I-' option in $OVERRIDE_OPTS stops GCC searching the current
+# directory first, so add it back here.
+ALL_CC_OPTS="-I. $MERC_ALL_C_INCL_DIRS $ANSI_OPTS $CHECK_OPTS $OPT_OPTS \
 		$HLC_OPTS $HLD_OPTS $GCC_OPTS $GC_OPTS $DEFINE_OPTS \
 		$TRACE_OPTS $STACK_TRACE_OPTS $LLDEBUG_OPTS $C_DEBUG_OPTS \
 		$PROF_TIME_OPTS $PROF_CALLS_OPTS $PROF_MEMORY_OPTS \
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list