public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Backport 'cpp include directory search order warning' patch to 3.2.1?
@ 2002-09-29 18:42 Zack Weinberg
  2002-09-29 19:09 ` John David Anglin
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Zack Weinberg @ 2002-09-29 18:42 UTC (permalink / raw)
  To: gcc; +Cc: Mark Mitchell, John David Anglin, Neil Booth

I'd like to propose John's patch to squelch the 'cpp: changing search
order...' warnings be backported to 3.2.1.  The warnings can be
considered a regression from 3.0, and cause autoconf scripts to break,
which makes them more than just a nuisance.  If this is okay with the
release manager, I'll do the legwork.

The patch is at http://gcc.gnu.org/ml/gcc-patches/2002-08/msg00924.html,
but was modified slightly before being committed; I'm proposing the
patch as actually committed to mainline, not the version in that
document.  See my comments at
http://gcc.gnu.org/ml/gcc-patches/2002-08/msg01251.html.

zw

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Backport 'cpp include directory search order warning' patch to 3.2.1?
  2002-09-29 18:42 Backport 'cpp include directory search order warning' patch to 3.2.1? Zack Weinberg
@ 2002-09-29 19:09 ` John David Anglin
  2002-09-29 23:04 ` Fergus Henderson
  2002-10-04 12:32 ` Neil Booth
  2 siblings, 0 replies; 7+ messages in thread
From: John David Anglin @ 2002-09-29 19:09 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: gcc, mark, neil

> I'd like to propose John's patch to squelch the 'cpp: changing search
> order...' warnings be backported to 3.2.1.  The warnings can be
> considered a regression from 3.0, and cause autoconf scripts to break,
> which makes them more than just a nuisance.  If this is okay with the
> release manager, I'll do the legwork.

The last version of the patch that I had for 3.2.1 is below.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)

Index: cppinit.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.202.2.5.2.2
diff -u -3 -p -r1.202.2.5.2.2 cppinit.c
--- cppinit.c	18 Aug 2002 06:24:13 -0000	1.202.2.5.2.2
+++ cppinit.c	21 Aug 2002 16:29:31 -0000
@@ -103,9 +103,13 @@ static void mark_named_operators	PARAMS 
 static void append_include_chain	PARAMS ((cpp_reader *,
 						 char *, int, int));
 static struct search_path * remove_dup_dir	PARAMS ((cpp_reader *,
+						 struct search_path *,
+						 struct search_path **));
+static struct search_path * remove_dup_nonsys_dirs PARAMS ((cpp_reader *,
+						 struct search_path **,
 						 struct search_path *));
 static struct search_path * remove_dup_dirs PARAMS ((cpp_reader *,
-						 struct search_path *));
+						 struct search_path **));
 static void merge_include_chains	PARAMS ((cpp_reader *));
 static bool push_include		PARAMS ((cpp_reader *,
 						 struct pending_option *));
@@ -272,55 +276,98 @@ append_include_chain (pfile, dir, path, 
 }
 
 /* Handle a duplicated include path.  PREV is the link in the chain
-   before the duplicate.  The duplicate is removed from the chain and
-   freed.  Returns PREV.  */
+   before the duplicate, or NULL if the duplicate is at the head of
+   the chain.  The duplicate is removed from the chain and freed.
+   Returns PREV.  */
 static struct search_path *
-remove_dup_dir (pfile, prev)
+remove_dup_dir (pfile, prev, head_ptr)
      cpp_reader *pfile;
      struct search_path *prev;
+     struct search_path **head_ptr;
 {
-  struct search_path *cur = prev->next;
+  struct search_path *cur;
+
+  if (prev != NULL)
+    {
+      cur = prev->next;
+      prev->next = cur->next;
+    }
+  else
+    {
+      cur = *head_ptr;
+      *head_ptr = cur->next;
+    }
 
   if (CPP_OPTION (pfile, verbose))
     fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), cur->name);
 
-  prev->next = cur->next;
   free ((PTR) cur->name);
   free (cur);
 
   return prev;
 }
 
+/* Remove duplicate non-system directories for which there is an equivalent
+   system directory latter in the chain.  The range for removal is between
+   *HEAD_PTR and END.  Returns the directory before END, or NULL if none.
+   This algorithm is quadratic in the number of system directories, which is
+   acceptable since there aren't usually that many of them.  */
+static struct search_path *
+remove_dup_nonsys_dirs (pfile, head_ptr, end)
+     cpp_reader *pfile;
+     struct search_path **head_ptr;
+     struct search_path *end;
+{
+  int sysdir = 0;
+  struct search_path *prev = NULL, *cur, *other;
+
+  for (cur = *head_ptr; cur; cur = cur->next)
+    {
+      if (cur->sysp)
+	{
+	  sysdir = 1;
+	  for (other = *head_ptr, prev = NULL;
+	       other != end;
+	       other = other ? other->next : *head_ptr)
+	    {
+	      if (!other->sysp
+		  && INO_T_EQ (cur->ino, other->ino)
+		  && cur->dev == other->dev)
+		{
+		  other = remove_dup_dir (pfile, prev, head_ptr);
+		  if (CPP_OPTION (pfile, verbose))
+		    fprintf (stderr,
+  _("  as it is a non-system directory that duplicates a system directory\n"));
+		}
+	      prev = other;
+	    }
+	}
+    }
+
+  if (!sysdir)
+    for (cur = *head_ptr; cur != end; cur = cur->next)
+      prev = cur;
+
+  return prev;
+}
+
 /* Remove duplicate directories from a chain.  Returns the tail of the
    chain, or NULL if the chain is empty.  This algorithm is quadratic
    in the number of -I switches, which is acceptable since there
    aren't usually that many of them.  */
 static struct search_path *
-remove_dup_dirs (pfile, head)
+remove_dup_dirs (pfile, head_ptr)
      cpp_reader *pfile;
-     struct search_path *head;
+     struct search_path **head_ptr;
 {
   struct search_path *prev = NULL, *cur, *other;
 
-  for (cur = head; cur; cur = cur->next)
+  for (cur = *head_ptr; cur; cur = cur->next)
     {
-      for (other = head; other != cur; other = other->next)
-        if (INO_T_EQ (cur->ino, other->ino) && cur->dev == other->dev)
+      for (other = *head_ptr; other != cur; other = other->next)
+	if (INO_T_EQ (cur->ino, other->ino) && cur->dev == other->dev)
 	  {
-	    if (cur->sysp && !other->sysp)
-	      {
-		cpp_warning (pfile,
-			     "changing search order for system directory \"%s\"",
-			     cur->name);
-		if (strcmp (cur->name, other->name))
-		  cpp_warning (pfile, 
-			       "  as it is the same as non-system directory \"%s\"",
-			       other->name);
-		else
-		  cpp_warning (pfile, 
-			       "  as it has already been specified as a non-system directory");
-	      }
-	    cur = remove_dup_dir (pfile, prev);
+	    cur = remove_dup_dir (pfile, prev, head_ptr);
 	    break;
 	  }
       prev = cur;
@@ -358,28 +405,33 @@ merge_include_chains (pfile)
   else
     brack = systm;
 
-  /* This is a bit tricky.  First we drop dupes from the quote-include
-     list.  Then we drop dupes from the bracket-include list.
-     Finally, if qtail and brack are the same directory, we cut out
-     brack and move brack up to point to qtail.
+  /* This is a bit tricky.  First we drop non-system dupes of system
+     directories from the merged bracket-include list.  Next we drop
+     dupes from the bracket and quote include lists.  Then we drop
+     non-system dupes from the merged quote-include list.  Finally,
+     if qtail and brack are the same directory, we cut out brack and
+     move brack up to point to qtail.
 
      We can't just merge the lists and then uniquify them because
      then we may lose directories from the <> search path that should
-     be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
+     be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux.  It is however
      safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written
      -Ibar -I- -Ifoo -Iquux.  */
 
-  remove_dup_dirs (pfile, brack);
-  qtail = remove_dup_dirs (pfile, quote);
+  remove_dup_nonsys_dirs (pfile, &brack, systm);
+  remove_dup_dirs (pfile, &brack);
 
   if (quote)
     {
+      qtail = remove_dup_dirs (pfile, &quote);
       qtail->next = brack;
 
+      qtail = remove_dup_nonsys_dirs (pfile, &quote, brack);
+
       /* If brack == qtail, remove brack as it's simpler.  */
-      if (brack && INO_T_EQ (qtail->ino, brack->ino)
+      if (qtail && brack && INO_T_EQ (qtail->ino, brack->ino)
 	  && qtail->dev == brack->dev)
-	brack = remove_dup_dir (pfile, qtail);
+	brack = remove_dup_dir (pfile, qtail, &quote);
     }
   else
     quote = brack;
Index: doc/cpp.texi
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/doc/cpp.texi,v
retrieving revision 1.24.2.3.4.1
diff -u -3 -p -r1.24.2.3.4.1 cpp.texi
--- doc/cpp.texi	15 Aug 2002 19:46:42 -0000	1.24.2.3.4.1
+++ doc/cpp.texi	21 Aug 2002 16:29:37 -0000
@@ -830,11 +830,22 @@ version of GCC in use.
 
 You can add to this list with the @option{-I@var{dir}} command line
 option.  All the directories named by @option{-I} are searched, in
-left-to-right order, @emph{before} the default directories.  You can
-also prevent GCC from searching any of the default directories with the
-@option{-nostdinc} option.  This is useful when you are compiling an
+left-to-right order, @emph{before} the default directories.  The only
+exception is when @file{dir} is already searched by default.  In
+this case, the option is ignored and the search order for system
+directories remains unchanged.
+
+Duplicate directories are removed from the quote and bracket search
+chains before the two chains are merged to make the final search chain.
+Thus, it is possible for a directory to occur twice in the final search
+chain if it was specified in both the quote and bracket chains.
+
+You can prevent GCC from searching any of the default directories with
+the @option{-nostdinc} option.  This is useful when you are compiling an
 operating system kernel or some other program that does not use the
 standard C library facilities, or the standard C library itself.
+@option{-I} options are not ignored as described above when
+@option{-nostdinc} is in effect.
 
 GCC looks for headers requested with @code{@w{#include "@var{file}"}}
 first in the directory containing the current file, then in the same
@@ -843,12 +854,6 @@ For example, if @file{/usr/include/sys/s
 @code{@w{#include "types.h"}}, GCC looks for @file{types.h} first in
 @file{/usr/include/sys}, then in its usual search path.
 
-If you name a search directory with @option{-I@var{dir}} that is also a
-system include directory, the @option{-I} wins; the directory will be
-searched according to the @option{-I} ordering, and it will not be
-treated as a system include directory. GCC will warn you when a system
-include directory is hidden in this way.
-
 @samp{#line} (@pxref{Line Control}) does not change GCC's idea of the
 directory containing the current file.
 
@@ -1081,8 +1086,8 @@ found in that directory will be consider
 All directories named by @option{-isystem} are searched @emph{after} all
 directories named by @option{-I}, no matter what their order was on the
 command line.  If the same directory is named by both @option{-I} and
-@option{-isystem}, @option{-I} wins; it is as if the @option{-isystem} option
-had never been specified at all. GCC warns you when this happens.
+@option{-isystem}, the @option{-I} option is ignored.  GCC provides an
+informative message when this occurs if @option{-v} is used.
 
 @findex #pragma GCC system_header
 There is also a directive, @code{@w{#pragma GCC system_header}}, which
@@ -1815,9 +1820,7 @@ conformance to the C Standard.  GNU CPP 
 processing system header files, but when processing user files
 @code{__STDC__} is always 1.  This has been reported to cause problems;
 for instance, some versions of Solaris provide X Windows headers that
-expect @code{__STDC__} to be either undefined or 1.  You may be able to
-work around this sort of problem by using an @option{-I} option to
-cancel treatment of those headers as system headers.  @xref{Invocation}.
+expect @code{__STDC__} to be either undefined or 1.  @xref{Invocation}.
 
 @item __STDC_VERSION__
 This macro expands to the C Standard's version number, a long integer
Index: doc/cppopts.texi
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/doc/cppopts.texi,v
retrieving revision 1.1.2.1
diff -u -3 -p -r1.1.2.1 cppopts.texi
--- doc/cppopts.texi	11 Mar 2002 19:59:58 -0000	1.1.2.1
+++ doc/cppopts.texi	21 Aug 2002 16:29:37 -0000
@@ -51,16 +51,14 @@ for header files.
 @xref{Search Path}.
 @end ifset
 Directories named by @option{-I} are searched before the standard
-system include directories.
-
-It is dangerous to specify a standard system include directory in an
-@option{-I} option.  This defeats the special treatment of system
-headers
+system include directories.  If the directory @var{dir} is a standard
+system include directory, the option is ignored to ensure that the
+default search order for system directories and the special treatment
+of system headers are not defeated
 @ifset cppmanual
 (@pxref{System Headers})
 @end ifset
-.  It can also defeat the repairs to buggy system headers which GCC
-makes when it is installed.
+.
 
 @item -o @var{file}
 @opindex o
Index: doc/install.texi
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/doc/install.texi,v
retrieving revision 1.92.2.29.2.3
diff -u -3 -p -r1.92.2.29.2.3 install.texi
--- doc/install.texi	19 Aug 2002 17:00:21 -0000	1.92.2.29.2.3
+++ doc/install.texi	21 Aug 2002 16:29:45 -0000
@@ -460,6 +460,43 @@ any in that directory---are not part of 
 programs---perhaps many others.  (GCC installs its own header files in
 another directory which is based on the @option{--prefix} value.)
 
+Both the local-prefix include directory and the GCC-prefix include
+directory are part of GCC's "system include" directories.  Although these
+two directories are not fixed, they need to be searched in the proper
+order for the correct processing of the include_next directive.  The
+local-prefix include directory is searched before the GCC-prefix
+include directory.  Another characteristic of system include directories
+is that pedantic warnings are turned off for headers in these directories.
+
+Some autoconf macros add @option{-I @var{directory}} options to the
+compiler command line, to ensure that directories containing installed
+packages' headers are searched.  When @var{directory} is one of GCC's
+system include directories, GCC will ignore the option so that system
+directories continue to be processed in the correct order.  This
+may result in a search order different from what was specified but the
+directory will still be searched.
+
+GCC automatically searches for ordinary libraries using
+@env{GCC_EXEC_PREFIX}.  Thus, when the same installation prefix is
+used for both GCC and packages, GCC will automatically search for
+both headers and libraries.  This provides a configuration that is
+easy to use.  GCC behaves in a manner similar to that when it is
+installed as a system compiler in @file{/usr}.
+
+Sites that need to install multiple versions of GCC may not want to
+use the above simple configuration.  It is possible to use the
+@option{--program-prefix}, @option{--program-suffix} and
+@option{--program-transform-name} options to install multiple versions
+into a single directory, but it may be simpler to use different prefixes
+and the @option{--with-local-prefix} option to specify the location of the
+site-specific files for each version.  It will then be necessary for
+users to specify explicitly the location of local site libraries
+(e.g., with @env{LIBRARY_PATH}).
+
+The same value can be used for both @option{--with-local-prefix} and
+@option{--prefix} provided it is not @file{/usr}.  This can be used
+to avoid the default search of @file{/usr/local/include}.
+
 @strong{Do not} specify @file{/usr} as the @option{--with-local-prefix}!
 The directory you use for @option{--with-local-prefix} @strong{must not}
 contain any of the system's standard header files.  If it did contain
Index: doc/invoke.texi
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.119.2.12.4.1
diff -u -3 -p -r1.119.2.12.4.1 invoke.texi
--- doc/invoke.texi	20 Aug 2002 07:04:36 -0000	1.119.2.12.4.1
+++ doc/invoke.texi	21 Aug 2002 16:30:12 -0000
@@ -4200,15 +4200,13 @@ one @option{-I} option, the directories 
 order; the standard system directories come after.
 
 If a standard system include directory, or a directory specified with
-@option{-isystem}, is also specified with @option{-I}, it will be
-searched only in the position requested by @option{-I}.  Also, it will
-not be considered a system include directory.  If that directory really
-does contain system headers, there is a good chance that they will
-break.  For instance, if GCC's installation procedure edited the headers
-in @file{/usr/include} to fix bugs, @samp{-I/usr/include} will cause the
-original, buggy headers to be found instead of the corrected ones.  GCC
-will issue a warning when a system include directory is hidden in this
-way.
+@option{-isystem}, is also specified with @option{-I}, the @option{-I}
+option will be ignored.  The directory will still be searched but as a
+system directory at its normal position in the system include chain.
+This is to ensure that GCC's procedure to fix buggy system headers and
+the ordering for the include_next directive are not inadvertantly changed.
+If you really need to change the search order for system directories,
+use the @option{-nostdinc} and/or @option{-isystem} options.
 
 @item -I-
 @opindex I-

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Backport 'cpp include directory search order warning' patch to 3.2.1?
  2002-09-29 18:42 Backport 'cpp include directory search order warning' patch to 3.2.1? Zack Weinberg
  2002-09-29 19:09 ` John David Anglin
@ 2002-09-29 23:04 ` Fergus Henderson
  2002-09-29 23:07   ` Mark Mitchell
  2002-10-04 12:32 ` Neil Booth
  2 siblings, 1 reply; 7+ messages in thread
From: Fergus Henderson @ 2002-09-29 23:04 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: gcc, Mark Mitchell

On 29-Sep-2002, Zack Weinberg <zack@codesourcery.com> wrote:
> I'd like to propose John's patch to squelch the 'cpp: changing search
> order...' warnings be backported to 3.2.1.

I'd just like to express my support for this proposal.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Backport 'cpp include directory search order warning' patch to 3.2.1?
  2002-09-29 23:04 ` Fergus Henderson
@ 2002-09-29 23:07   ` Mark Mitchell
  2002-09-30  3:57     ` Gerald Pfeifer
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Mitchell @ 2002-09-29 23:07 UTC (permalink / raw)
  To: Fergus Henderson, Zack Weinberg; +Cc: gcc



--On Monday, September 30, 2002 11:42:22 AM +1000 Fergus Henderson 
<fjh@cs.mu.OZ.AU> wrote:

> On 29-Sep-2002, Zack Weinberg <zack@codesourcery.com> wrote:
>> I'd like to propose John's patch to squelch the 'cpp: changing search
>> order...' warnings be backported to 3.2.1.
>
> I'd just like to express my support for this proposal.

I agree that this is a good idea.  Zack, thanks for volunteering.

-- 
Mark Mitchell                mark@codesourcery.com
CodeSourcery, LLC            http://www.codesourcery.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Backport 'cpp include directory search order warning' patch to 3.2.1?
  2002-09-29 23:07   ` Mark Mitchell
@ 2002-09-30  3:57     ` Gerald Pfeifer
  2002-09-30 10:48       ` Zack Weinberg
  0 siblings, 1 reply; 7+ messages in thread
From: Gerald Pfeifer @ 2002-09-30  3:57 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: Fergus Henderson, Zack Weinberg, gcc

On Sun, 29 Sep 2002, Mark Mitchell wrote:
> I agree that this is a good idea.  Zack, thanks for volunteering.

Absolutely!  Zack, could you please also update
htdocs/gcc-3.2/changes.html accordingly (adding a new section
for 3.2.1 similiar to what we did for 3.1.1)?

Thanks,
Gerald
-- 
Gerald "Jerry" pfeifer@dbai.tuwien.ac.at http://www.dbai.tuwien.ac.at/~pfeifer/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Backport 'cpp include directory search order warning' patch to 3.2.1?
  2002-09-30  3:57     ` Gerald Pfeifer
@ 2002-09-30 10:48       ` Zack Weinberg
  0 siblings, 0 replies; 7+ messages in thread
From: Zack Weinberg @ 2002-09-30 10:48 UTC (permalink / raw)
  To: Gerald Pfeifer; +Cc: Mark Mitchell, Fergus Henderson, gcc

On Mon, Sep 30, 2002 at 11:53:53AM +0200, Gerald Pfeifer wrote:
> On Sun, 29 Sep 2002, Mark Mitchell wrote:
> > I agree that this is a good idea.  Zack, thanks for volunteering.
> 
> Absolutely!  Zack, could you please also update
> htdocs/gcc-3.2/changes.html accordingly (adding a new section
> for 3.2.1 similiar to what we did for 3.1.1)?

Check.  I copied the text from the 3.3 changes.html.

Here's the patch I'm about to check in.  It's passed bootstrap on
i686-linux and I've verified that the search path behavior is as
desired.

zw

2002-08-21  John David Anglin  <dave@hiauly1.hia.nrc.ca>

	* cppinit.c (remove_dup_nonsys_dirs): Fix warning and return value.

2002-08-20  John David Anglin  <dave@hiauly1.hia.nrc.ca>

	* cppinit.c (remove_dup_dir): Add head_ptr argument to handle removal
	at head.
	(remove_dup_nonsys_dirs): New function.
	(remove_dup_dirs): Change argument head to head_ptr.  Remove warnings.
	(merge_include_chains): Remove non-system include directories from
	quote and bracket include chains when they duplicate equivalent system
	directories.
	* doc/cpp.texi (-I): Update.
	* doc/cppopts.texi (-I): Update.
	* doc/install.texi (--with-local-prefix): Further document usage of
	this option.
	* doc/invoke.texi (-I): Update.

===================================================================
Index: gcc-3.2/changes.html
--- gcc-3.2/changes.html	16 Aug 2002 18:23:10 -0000	1.29
+++ gcc-3.2/changes.html	30 Sep 2002 17:04:31 -0000
@@ -11,11 +11,26 @@
 <body>
 <h1>GCC 3.2 Changes, New Features, and Fixes</h1>
 
-<h2>Relase Notes</h2>
+<!-- Changes for later point releases should be added at the top. -->
+
+<h2>Additional changes in GCC 3.2.1</h2>
+
+<h3>C/ObjC/C++</h3>
+
+ <ul>
+    <li>The method of constructing the list of directories to be searched
+	for header files has been revised.  If a directory named by a
+	<code>-I</code> option is a standard system include directory,
+	the option is ignored to ensure that the default search order
+	for system directories and the special treatment of system header
+	files are not defeated.</li>
+ </ul>
+
+<h2>Bug Fixes</h2>
 
 <p>See <a
 href="http://gcc.gnu.org/ml/gcc/2002-08/msg00405.html">this message</a> for 
-a list of bugs fixed in this released.</p>
+a list of bugs fixed in this release.</p>
 
 <h2>Caveats</h2>
 
===================================================================
Index: cppinit.c
--- cppinit.c	18 Aug 2002 06:24:13 -0000	1.202.2.5.2.2
+++ cppinit.c	30 Sep 2002 17:26:19 -0000
@@ -103,9 +103,13 @@ static void mark_named_operators	PARAMS 
 static void append_include_chain	PARAMS ((cpp_reader *,
 						 char *, int, int));
 static struct search_path * remove_dup_dir	PARAMS ((cpp_reader *,
+						 struct search_path *,
+						 struct search_path **));
+static struct search_path * remove_dup_nonsys_dirs PARAMS ((cpp_reader *,
+						 struct search_path **,
 						 struct search_path *));
 static struct search_path * remove_dup_dirs PARAMS ((cpp_reader *,
-						 struct search_path *));
+						 struct search_path **));
 static void merge_include_chains	PARAMS ((cpp_reader *));
 static bool push_include		PARAMS ((cpp_reader *,
 						 struct pending_option *));
@@ -272,55 +276,98 @@ append_include_chain (pfile, dir, path, 
 }
 
 /* Handle a duplicated include path.  PREV is the link in the chain
-   before the duplicate.  The duplicate is removed from the chain and
-   freed.  Returns PREV.  */
+   before the duplicate, or NULL if the duplicate is at the head of
+   the chain.  The duplicate is removed from the chain and freed.
+   Returns PREV.  */
 static struct search_path *
-remove_dup_dir (pfile, prev)
+remove_dup_dir (pfile, prev, head_ptr)
      cpp_reader *pfile;
      struct search_path *prev;
+     struct search_path **head_ptr;
 {
-  struct search_path *cur = prev->next;
+  struct search_path *cur;
+
+  if (prev != NULL)
+    {
+      cur = prev->next;
+      prev->next = cur->next;
+    }
+  else
+    {
+      cur = *head_ptr;
+      *head_ptr = cur->next;
+    }
 
   if (CPP_OPTION (pfile, verbose))
     fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), cur->name);
 
-  prev->next = cur->next;
   free ((PTR) cur->name);
   free (cur);
 
   return prev;
 }
 
+/* Remove duplicate non-system directories for which there is an equivalent
+   system directory later in the chain.  The range for removal is between
+   *HEAD_PTR and END.  Returns the directory before END, or NULL if none.
+   This algorithm is quadratic in the number of system directories, which is
+   acceptable since there aren't usually that many of them.  */
+static struct search_path *
+remove_dup_nonsys_dirs (pfile, head_ptr, end)
+     cpp_reader *pfile;
+     struct search_path **head_ptr;
+     struct search_path *end;
+{
+  int sysdir = 0;
+  struct search_path *prev = NULL, *cur, *other;
+
+  for (cur = *head_ptr; cur; cur = cur->next)
+    {
+      if (cur->sysp)
+	{
+	  sysdir = 1;
+	  for (other = *head_ptr, prev = NULL;
+	       other != end;
+	       other = other ? other->next : *head_ptr)
+	    {
+	      if (!other->sysp
+		  && INO_T_EQ (cur->ino, other->ino)
+		  && cur->dev == other->dev)
+		{
+		  other = remove_dup_dir (pfile, prev, head_ptr);
+		  if (CPP_OPTION (pfile, verbose))
+		    fprintf (stderr,
+  _("  as it is a non-system directory that duplicates a system directory\n"));
+		}
+	      prev = other;
+	    }
+	}
+    }
+
+  if (!sysdir)
+    for (cur = *head_ptr; cur != end; cur = cur->next)
+      prev = cur;
+
+  return prev;
+}
+
 /* Remove duplicate directories from a chain.  Returns the tail of the
    chain, or NULL if the chain is empty.  This algorithm is quadratic
    in the number of -I switches, which is acceptable since there
    aren't usually that many of them.  */
 static struct search_path *
-remove_dup_dirs (pfile, head)
+remove_dup_dirs (pfile, head_ptr)
      cpp_reader *pfile;
-     struct search_path *head;
+     struct search_path **head_ptr;
 {
   struct search_path *prev = NULL, *cur, *other;
 
-  for (cur = head; cur; cur = cur->next)
+  for (cur = *head_ptr; cur; cur = cur->next)
     {
-      for (other = head; other != cur; other = other->next)
+      for (other = *head_ptr; other != cur; other = other->next)
         if (INO_T_EQ (cur->ino, other->ino) && cur->dev == other->dev)
 	  {
-	    if (cur->sysp && !other->sysp)
-	      {
-		cpp_warning (pfile,
-			     "changing search order for system directory \"%s\"",
-			     cur->name);
-		if (strcmp (cur->name, other->name))
-		  cpp_warning (pfile, 
-			       "  as it is the same as non-system directory \"%s\"",
-			       other->name);
-		else
-		  cpp_warning (pfile, 
-			       "  as it has already been specified as a non-system directory");
-	      }
-	    cur = remove_dup_dir (pfile, prev);
+	    cur = remove_dup_dir (pfile, prev, head_ptr);
 	    break;
 	  }
       prev = cur;
@@ -358,28 +405,33 @@ merge_include_chains (pfile)
   else
     brack = systm;
 
-  /* This is a bit tricky.  First we drop dupes from the quote-include
-     list.  Then we drop dupes from the bracket-include list.
-     Finally, if qtail and brack are the same directory, we cut out
-     brack and move brack up to point to qtail.
+  /* This is a bit tricky.  First we drop non-system dupes of system
+     directories from the merged bracket-include list.  Next we drop
+     dupes from the bracket and quote include lists.  Then we drop
+     non-system dupes from the merged quote-include list.  Finally,
+     if qtail and brack are the same directory, we cut out brack and
+     move brack up to point to qtail.
 
      We can't just merge the lists and then uniquify them because
      then we may lose directories from the <> search path that should
-     be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
+     be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux.  It is however
      safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written
      -Ibar -I- -Ifoo -Iquux.  */
 
-  remove_dup_dirs (pfile, brack);
-  qtail = remove_dup_dirs (pfile, quote);
+  remove_dup_nonsys_dirs (pfile, &brack, systm);
+  remove_dup_dirs (pfile, &brack);
 
   if (quote)
     {
+      qtail = remove_dup_dirs (pfile, &quote);
       qtail->next = brack;
 
+      qtail = remove_dup_nonsys_dirs (pfile, &quote, brack);
+
       /* If brack == qtail, remove brack as it's simpler.  */
-      if (brack && INO_T_EQ (qtail->ino, brack->ino)
+      if (qtail && brack && INO_T_EQ (qtail->ino, brack->ino)
 	  && qtail->dev == brack->dev)
-	brack = remove_dup_dir (pfile, qtail);
+	brack = remove_dup_dir (pfile, qtail, &quote);
     }
   else
     quote = brack;
===================================================================
Index: doc/cpp.texi
--- doc/cpp.texi	15 Aug 2002 19:46:42 -0000	1.24.2.3.4.1
+++ doc/cpp.texi	30 Sep 2002 17:26:20 -0000
@@ -830,11 +830,22 @@ version of GCC in use.
 
 You can add to this list with the @option{-I@var{dir}} command line
 option.  All the directories named by @option{-I} are searched, in
-left-to-right order, @emph{before} the default directories.  You can
-also prevent GCC from searching any of the default directories with the
-@option{-nostdinc} option.  This is useful when you are compiling an
+left-to-right order, @emph{before} the default directories.  The only
+exception is when @file{dir} is already searched by default.  In
+this case, the option is ignored and the search order for system
+directories remains unchanged.
+
+Duplicate directories are removed from the quote and bracket search
+chains before the two chains are merged to make the final search chain.
+Thus, it is possible for a directory to occur twice in the final search
+chain if it was specified in both the quote and bracket chains.
+
+You can prevent GCC from searching any of the default directories with
+the @option{-nostdinc} option.  This is useful when you are compiling an
 operating system kernel or some other program that does not use the
 standard C library facilities, or the standard C library itself.
+@option{-I} options are not ignored as described above when
+@option{-nostdinc} is in effect.
 
 GCC looks for headers requested with @code{@w{#include "@var{file}"}}
 first in the directory containing the current file, then in the same
@@ -843,12 +854,6 @@ For example, if @file{/usr/include/sys/s
 @code{@w{#include "types.h"}}, GCC looks for @file{types.h} first in
 @file{/usr/include/sys}, then in its usual search path.
 
-If you name a search directory with @option{-I@var{dir}} that is also a
-system include directory, the @option{-I} wins; the directory will be
-searched according to the @option{-I} ordering, and it will not be
-treated as a system include directory. GCC will warn you when a system
-include directory is hidden in this way.
-
 @samp{#line} (@pxref{Line Control}) does not change GCC's idea of the
 directory containing the current file.
 
@@ -1081,8 +1086,8 @@ found in that directory will be consider
 All directories named by @option{-isystem} are searched @emph{after} all
 directories named by @option{-I}, no matter what their order was on the
 command line.  If the same directory is named by both @option{-I} and
-@option{-isystem}, @option{-I} wins; it is as if the @option{-isystem} option
-had never been specified at all. GCC warns you when this happens.
+@option{-isystem}, the @option{-I} option is ignored.  GCC provides an
+informative message when this occurs if @option{-v} is used.
 
 @findex #pragma GCC system_header
 There is also a directive, @code{@w{#pragma GCC system_header}}, which
@@ -1815,9 +1820,7 @@ conformance to the C Standard.  GNU CPP 
 processing system header files, but when processing user files
 @code{__STDC__} is always 1.  This has been reported to cause problems;
 for instance, some versions of Solaris provide X Windows headers that
-expect @code{__STDC__} to be either undefined or 1.  You may be able to
-work around this sort of problem by using an @option{-I} option to
-cancel treatment of those headers as system headers.  @xref{Invocation}.
+expect @code{__STDC__} to be either undefined or 1.  @xref{Invocation}.
 
 @item __STDC_VERSION__
 This macro expands to the C Standard's version number, a long integer
===================================================================
Index: doc/install.texi
--- doc/install.texi	11 Sep 2002 16:40:28 -0000	1.92.2.29.2.6
+++ doc/install.texi	30 Sep 2002 17:26:22 -0000
@@ -460,6 +460,43 @@ any in that directory---are not part of 
 programs---perhaps many others.  (GCC installs its own header files in
 another directory which is based on the @option{--prefix} value.)
 
+Both the local-prefix include directory and the GCC-prefix include
+directory are part of GCC's "system include" directories.  Although these
+two directories are not fixed, they need to be searched in the proper
+order for the correct processing of the include_next directive.  The
+local-prefix include directory is searched before the GCC-prefix
+include directory.  Another characteristic of system include directories
+is that pedantic warnings are turned off for headers in these directories.
+
+Some autoconf macros add @option{-I @var{directory}} options to the
+compiler command line, to ensure that directories containing installed
+packages' headers are searched.  When @var{directory} is one of GCC's
+system include directories, GCC will ignore the option so that system
+directories continue to be processed in the correct order.  This
+may result in a search order different from what was specified but the
+directory will still be searched.
+
+GCC automatically searches for ordinary libraries using
+@env{GCC_EXEC_PREFIX}.  Thus, when the same installation prefix is
+used for both GCC and packages, GCC will automatically search for
+both headers and libraries.  This provides a configuration that is
+easy to use.  GCC behaves in a manner similar to that when it is
+installed as a system compiler in @file{/usr}.
+
+Sites that need to install multiple versions of GCC may not want to
+use the above simple configuration.  It is possible to use the
+@option{--program-prefix}, @option{--program-suffix} and
+@option{--program-transform-name} options to install multiple versions
+into a single directory, but it may be simpler to use different prefixes
+and the @option{--with-local-prefix} option to specify the location of the
+site-specific files for each version.  It will then be necessary for
+users to specify explicitly the location of local site libraries
+(e.g., with @env{LIBRARY_PATH}).
+
+The same value can be used for both @option{--with-local-prefix} and
+@option{--prefix} provided it is not @file{/usr}.  This can be used
+to avoid the default search of @file{/usr/local/include}.
+
 @strong{Do not} specify @file{/usr} as the @option{--with-local-prefix}!
 The directory you use for @option{--with-local-prefix} @strong{must not}
 contain any of the system's standard header files.  If it did contain
===================================================================
Index: doc/invoke.texi
--- doc/invoke.texi	11 Sep 2002 16:40:28 -0000	1.119.2.12.4.3
+++ doc/invoke.texi	30 Sep 2002 17:26:25 -0000
@@ -4246,15 +4246,13 @@ one @option{-I} option, the directories 
 order; the standard system directories come after.
 
 If a standard system include directory, or a directory specified with
-@option{-isystem}, is also specified with @option{-I}, it will be
-searched only in the position requested by @option{-I}.  Also, it will
-not be considered a system include directory.  If that directory really
-does contain system headers, there is a good chance that they will
-break.  For instance, if GCC's installation procedure edited the headers
-in @file{/usr/include} to fix bugs, @samp{-I/usr/include} will cause the
-original, buggy headers to be found instead of the corrected ones.  GCC
-will issue a warning when a system include directory is hidden in this
-way.
+@option{-isystem}, is also specified with @option{-I}, the @option{-I}
+option will be ignored.  The directory will still be searched but as a
+system directory at its normal position in the system include chain.
+This is to ensure that GCC's procedure to fix buggy system headers and
+the ordering for the include_next directive are not inadvertantly changed.
+If you really need to change the search order for system directories,
+use the @option{-nostdinc} and/or @option{-isystem} options.
 
 @item -I-
 @opindex I-

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Backport 'cpp include directory search order warning' patch to 3.2.1?
  2002-09-29 18:42 Backport 'cpp include directory search order warning' patch to 3.2.1? Zack Weinberg
  2002-09-29 19:09 ` John David Anglin
  2002-09-29 23:04 ` Fergus Henderson
@ 2002-10-04 12:32 ` Neil Booth
  2 siblings, 0 replies; 7+ messages in thread
From: Neil Booth @ 2002-10-04 12:32 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: gcc, Mark Mitchell, John David Anglin

Zack Weinberg wrote:-

> I'd like to propose John's patch to squelch the 'cpp: changing search
> order...' warnings be backported to 3.2.1.  The warnings can be
> considered a regression from 3.0, and cause autoconf scripts to break,
> which makes them more than just a nuisance.  If this is okay with the
> release manager, I'll do the legwork.

Sounds worthwhile to me.

Neil.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-10-04 18:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-29 18:42 Backport 'cpp include directory search order warning' patch to 3.2.1? Zack Weinberg
2002-09-29 19:09 ` John David Anglin
2002-09-29 23:04 ` Fergus Henderson
2002-09-29 23:07   ` Mark Mitchell
2002-09-30  3:57     ` Gerald Pfeifer
2002-09-30 10:48       ` Zack Weinberg
2002-10-04 12:32 ` Neil Booth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).