This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: getting back the quote_ignore_sources_dir behavior of -I-


Here are the patches for gcc-4.3-20070302.
The patches for gcc-4.2 could be applied directly.

The test results are:

xylophone[gcc/4.3] 0 $ runtest --tool gcc --srcdir /home/danielv/gcc/gcc-4.3-20070302-dv/gcc/testsuite gcc.dg/cpp/cpp.exp
WARNING: Couldn't find the global config file.
Test Run By danielv on Sun Mar 11 09:28:01 2007
Native configuration is i686-redhat-linux-gnu

                === gcc tests ===

Schedule of variations:
    unix

Running target unix
Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /home/danielv/gcc/gcc-4.3-20070302-dv/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /home/danielv/gcc/gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/cpp.exp ...

                === gcc Summary ===

# of expected passes            1147
# of expected failures          4
# of unsupported tests          3
/home/danielv/gcc/local-4.3-dv/bin/gcc  version 4.3.0 20070302 (experimental)

--
Daniel

2007-03-10  Daniel Villeneuve  <daniel_villeneuve@sympatico.ca>

	* c.opt (-ignore-source-dir): New option.

	* c-opts.c (quote_chain_split): Removed.
	(c_common_handle_option): No longer process -I- within OPT_I case.

	* c-incpath.h (split_quote_chain): Removed.
	* c-incpath.c (split_quote_chain): Removed.

	* gcc.c (process_command): Fix side-effect problems of -I- on the
	QUOTE list by transforming -I options that occur before -I- into
	-iquote. Transform -I- into -ignore-source-dir.
	(option_map): add --ignore-source-dir entry.

	* testsuite/gcc.dg/cpp/iquote1.c: New test.
	* testsuite/gcc.dg/cpp/iquote2.c: New test.
	* testsuite/gcc.dg/cpp/iquote3.c: New test.
	* testsuite/gcc.dg/cpp/iquote4.c: New test.
	* testsuite/gcc.dg/cpp/iquote5.c: New test.
	* testsuite/gcc.dg/cpp/iquote6.c: New test.
	* testsuite/gcc.dg/cpp/iquote.h: Used along with iquote?.c.
	* testsuite/gcc.dg/cpp/inc/iquote.h: Used along with iquote?.c.

	* doc/invoke.texi: Document -ignore-source-dir.
	* doc/cpp.texi: Likewise.
	* doc/cppopts.texi: Likewise.

diff -Nrup gcc-4.3-20070302/gcc/c-incpath.c gcc-4.3-20070302-dv/gcc/c-incpath.c
--- gcc-4.3-20070302/gcc/c-incpath.c	2006-12-20 17:34:14.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/c-incpath.c	2007-03-10 22:51:34.000000000 -0500
@@ -29,6 +29,7 @@ Foundation, 51 Franklin Street, Fifth Fl
 #include "prefix.h"
 #include "intl.h"
 #include "c-incpath.h"
+#include "options.h"
 #include "cppdefault.h"
 
 /* Windows does not natively support inodes, and neither does MSDOS.
@@ -59,7 +60,6 @@ static struct cpp_dir *remove_duplicates
 /* Include chains heads and tails.  */
 static struct cpp_dir *heads[4];
 static struct cpp_dir *tails[4];
-static bool quote_ignores_source_dir;
 enum { REASON_QUIET = 0, REASON_NOENT, REASON_DUP, REASON_DUP_SYS };
 
 /* Free an element of the include chain, possibly giving a reason.  */
@@ -316,21 +316,6 @@ merge_include_chains (cpp_reader *pfile,
     }
 }
 
-/* Use given -I paths for #include "..." but not #include <...>, and
-   don't search the directory of the present file for #include "...".
-   (Note that -I. -I- is not the same as the default setup; -I. uses
-   the compiler's working dir.)  */
-void
-split_quote_chain (void)
-{
-  heads[QUOTE] = heads[BRACKET];
-  tails[QUOTE] = tails[BRACKET];
-  heads[BRACKET] = NULL;
-  tails[BRACKET] = NULL;
-  /* This is NOT redundant.  */
-  quote_ignores_source_dir = true;
-}
-
 /* Add P to the chain specified by CHAIN.  */
 
 void
diff -Nrup gcc-4.3-20070302/gcc/c-incpath.h gcc-4.3-20070302-dv/gcc/c-incpath.h
--- gcc-4.3-20070302/gcc/c-incpath.h	2006-01-20 16:00:03.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/c-incpath.h	2007-03-10 22:51:34.000000000 -0500
@@ -15,7 +15,6 @@ You should have received a copy of the G
 along with this program; if not, write to the Free Software
 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-extern void split_quote_chain (void);
 extern void add_path (char *, int, int, bool);
 extern void register_include_chains (cpp_reader *, const char *,
 				     const char *, const char *,
diff -Nrup gcc-4.3-20070302/gcc/c-opts.c gcc-4.3-20070302-dv/gcc/c-opts.c
--- gcc-4.3-20070302/gcc/c-opts.c	2007-02-19 15:02:28.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/c-opts.c	2007-03-10 22:51:34.000000000 -0500
@@ -92,9 +92,6 @@ static bool std_inc = true;
 /* Zero disables the C++-specific standard directories for headers.  */
 static bool std_cxx_inc = true;
 
-/* If the quote chain has been split by -I-.  */
-static bool quote_chain_split;
-
 /* If -Wunused-macros.  */
 static bool warn_unused_macros;
 
@@ -320,16 +317,7 @@ c_common_handle_option (size_t scode, co
       break;
 
     case OPT_I:
-      if (strcmp (arg, "-"))
-	add_path (xstrdup (arg), BRACKET, 0, true);
-      else
-	{
-	  if (quote_chain_split)
-	    error ("-I- specified twice");
-	  quote_chain_split = true;
-	  split_quote_chain ();
-	  inform ("obsolete option -I- used, please use -iquote instead");
-	}
+      add_path (xstrdup (arg), BRACKET, 0, true);
       break;
 
     case OPT_M:
diff -Nrup gcc-4.3-20070302/gcc/c.opt gcc-4.3-20070302-dv/gcc/c.opt
--- gcc-4.3-20070302/gcc/c.opt	2007-02-21 10:40:29.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/c.opt	2007-03-10 22:51:34.000000000 -0500
@@ -783,6 +783,10 @@ idirafter
 C ObjC C++ ObjC++ Joined Separate
 -idirafter <dir>	Add <dir> to the end of the system include path
 
+ignore-source-dir
+C ObjC C++ ObjC++ Var(quote_ignores_source_dir)
+Ignore source file's directory when searching for #include \"...\" files
+
 imacros
 C ObjC C++ ObjC++ Joined Separate
 -imacros <file>	Accept definition of macros in <file>
diff -Nrup gcc-4.3-20070302/gcc/doc/cpp.texi gcc-4.3-20070302-dv/gcc/doc/cpp.texi
--- gcc-4.3-20070302/gcc/doc/cpp.texi	2007-02-27 01:00:47.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/doc/cpp.texi	2007-03-10 22:51:34.000000000 -0500
@@ -884,7 +884,9 @@ directories as specified by @option{-iqu
 places it would have looked for a header requested with angle
 brackets.  For example, if @file{/usr/include/sys/stat.h} contains
 @code{@w{#include "types.h"}}, GCC looks for @file{types.h} first in
-@file{/usr/include/sys}, then in its usual search path.
+@file{/usr/include/sys}, then in its usual search path.  You can prevent
+GCC from using the directory containing the current file with the
+@option{-ignore-source-dir} option.
 
 @samp{#line} (@pxref{Line Control}) does not change GCC's idea of the
 directory containing the current file.
@@ -895,8 +897,8 @@ This has two effects.  First, directorie
 quote marks.  Directories after @option{-I-} are searched for all
 headers.  Second, the directory containing the current file is not
 searched for anything, unless it happens to be one of the directories
-named by an @option{-I} switch.  @option{-I-} is deprecated, @option{-iquote}
-should be used instead.
+named by an @option{-I} switch.  @option{-I-} is deprecated,
+@option{-iquote} and @option{-ignore-source-dir} should be used instead.
 
 @option{-I. -I-} is not the same as no @option{-I} options at all, and does
 not cause the same behavior for @samp{<>} includes that @samp{""}
@@ -4105,8 +4107,8 @@ they generally represent bugs in the sna
 
 @item -I- deprecated
 
-This option has been deprecated in 4.0.  @option{-iquote} is meant to
-replace the need for this option.
+This option has been deprecated in 4.0.  Options @option{-iquote} and
+@option{-ignore-source-dir} are meant to replace the need for this option.
 
 @item Order of evaluation of @samp{#} and @samp{##} operators
 
@@ -4200,8 +4202,8 @@ without notice.
 @ignore
 @c man begin SYNOPSIS
 cpp [@option{-D}@var{macro}[=@var{defn}]@dots{}] [@option{-U}@var{macro}]
-    [@option{-I}@var{dir}@dots{}] [@option{-iquote}@var{dir}@dots{}]
-    [@option{-W}@var{warn}@dots{}]
+    [@option{-I}@var{dir}@dots{}] [@option{-ignore-source-dir}]
+    [@option{-iquote}@var{dir}@dots{}] [@option{-W}@var{warn}@dots{}]
     [@option{-M}|@option{-MM}] [@option{-MG}] [@option{-MF} @var{filename}]
     [@option{-MP}] [@option{-MQ} @var{target}@dots{}]
     [@option{-MT} @var{target}@dots{}]
diff -Nrup gcc-4.3-20070302/gcc/doc/cppopts.texi gcc-4.3-20070302-dv/gcc/doc/cppopts.texi
--- gcc-4.3-20070302/gcc/doc/cppopts.texi	2007-01-11 11:26:55.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/doc/cppopts.texi	2007-03-10 22:51:34.000000000 -0500
@@ -465,6 +465,11 @@ Search @var{dir} for header files, but d
 directories specified with @option{-I} and the standard system directories
 have been exhausted.  @var{dir} is treated as a system include directory.
 
+@item -ignore-source-dir
+@opindex ignore-source-dir
+Inhibit the use of the current directory (where the current input file
+came from) as the first search directory for @samp{#include "@var{file}"}.
+
 @item -iprefix @var{prefix}
 @opindex iprefix
 Specify @var{prefix} as the prefix for subsequent @option{-iwithprefix}
diff -Nrup gcc-4.3-20070302/gcc/doc/invoke.texi gcc-4.3-20070302-dv/gcc/doc/invoke.texi
--- gcc-4.3-20070302/gcc/doc/invoke.texi	2007-02-22 22:00:26.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/doc/invoke.texi	2007-03-10 22:51:34.000000000 -0500
@@ -385,8 +385,8 @@ Objective-C and Objective-C++ Dialects}.
 
 @item Directory Options
 @xref{Directory Options,,Options for Directory Search}.
-@gccoptlist{-B@var{prefix}  -I@var{dir}  -iquote@var{dir}  -L@var{dir}
--specs=@var{file}  -I- --sysroot=@var{dir}}
+@gccoptlist{-B@var{prefix}  -I@var{dir}  -ignore-source-dir
+-iquote@var{dir}  -L@var{dir}  -specs=@var{file}  -I-  --sysroot=@var{dir}}
 
 @item Target Options
 @c I wrote this xref this way to avoid overfull hbox. -- rms
@@ -6954,6 +6954,11 @@ the ordering for the include_next direct
 If you really need to change the search order for system directories,
 use the @option{-nostdinc} and/or @option{-isystem} options.
 
+@item -ignore-source-dir
+@opindex ignore-source-dir
+Inhibit the use of the current directory (where the current input file
+came from) as the first search directory for @samp{#include "@var{file}"}.
+
 @item -iquote@var{dir}
 @opindex iquote
 Add the directory @var{dir} to the head of the list of directories to
@@ -7037,8 +7042,10 @@ library aspect will not.
 @item -I-
 @opindex I-
 This option has been deprecated.  Please use @option{-iquote} instead for
-@option{-I} directories before the @option{-I-} and remove the @option{-I-}.
-Any directories you specify with @option{-I} options before the @option{-I-}
+@option{-I} directories before the @option{-I-}, use
+@option{-ignore-source-dir} for not using the source file's directory in
+the include path, and remove the @option{-I-}.  Any directories you
+specify with @option{-I} options before the @option{-I-}
 option are searched only for the case of @samp{#include "@var{file}"};
 they are not searched for @samp{#include <@var{file}>}.
 
diff -Nrup gcc-4.3-20070302/gcc/gcc.c gcc-4.3-20070302-dv/gcc/gcc.c
--- gcc-4.3-20070302/gcc/gcc.c	2007-02-27 15:32:13.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/gcc.c	2007-03-10 22:51:34.000000000 -0500
@@ -1087,6 +1087,7 @@ static const struct option_map option_ma
    {"--for-linker", "-Xlinker", "a"},
    {"--force-link", "-u", "a"},
    {"--coverage", "-coverage", 0},
+   {"--ignore-source-dir", "-ignore-source-dir", 0},
    {"--imacros", "-imacros", "a"},
    {"--include", "-include", "a"},
    {"--include-barrier", "-I-", 0},
@@ -3289,6 +3290,7 @@ process_command (int argc, const char **
   const char *spec_lang = 0;
   int last_language_n_infiles;
   int lang_n_infiles = 0;
+  int include_barrier = 0;
 #ifdef MODIFY_TARGET_NAME
   int is_modify_target_name;
   unsigned int j;
@@ -3923,6 +3925,15 @@ warranty; not even for MERCHANTABILITY o
 	      if (is_modify_target_name)
 		break;
 #endif
+              if (! strcmp (argv[i], "-I-"))
+                {
+                  if (include_barrier)
+                    fatal ("-I- specified twice");
+                  include_barrier = 1;
+                  error ("warning: obsolete option -I- used, "
+                         "please use -iquote and/or -ignore-source-dir "
+                         "instead");
+                }
 
 	      n_switches++;
 
@@ -4154,6 +4165,31 @@ warranty; not even for MERCHANTABILITY o
 	      continue;
 	    }
 	  switches[n_switches].part1 = p;
+
+          if (include_barrier)
+            {
+              /* Substitute -I options that precede -I- with -iquote ones.
+                 Substitute -I- with -ignore-source-dir. */
+              if (c == 'I')
+                {
+                  if (p[1] == '-')
+                    {
+                      include_barrier = 0;
+                      switches[n_switches].part1 = "ignore-source-dir";
+                    }
+                  else if (p[1] == 0)
+                    switches[n_switches].part1 = "iquote";
+                  else
+                    {
+                      int len = strlen (p);
+                      char *q = xmalloc (len + sizeof ("iquote") - 1);
+                      memcpy (q, "iquote", sizeof ("iquote") - 1);
+                      memcpy (q + sizeof ("iquote") - 1, p + 1, len);
+                      switches[n_switches].part1 = q;
+                    }
+                }
+            }
+
 	  /* Deal with option arguments in separate argv elements.  */
 	  if ((SWITCH_TAKES_ARG (c) > (p[1] != 0))
 	      || WORD_SWITCH_TAKES_ARG (p))
diff -Nrup gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/inc/iquote.h gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/inc/iquote.h
--- gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/inc/iquote.h	1969-12-31 19:00:00.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/inc/iquote.h	2007-03-10 22:51:34.000000000 -0500
@@ -0,0 +1 @@
+#define A 1
diff -Nrup gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote.h gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote.h
--- gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote.h	1969-12-31 19:00:00.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote.h	2007-03-10 22:51:34.000000000 -0500
@@ -0,0 +1 @@
+#define A 0
diff -Nrup gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote1.c gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote1.c
--- gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote1.c	1969-12-31 19:00:00.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote1.c	2007-03-10 22:51:34.000000000 -0500
@@ -0,0 +1,9 @@
+/* { dg-do preprocess } */
+/* { dg-options "-iquote $srcdir/gcc.dg/cpp/inc -I $srcdir/gcc.dg/cpp -I-" } */
+
+#include "iquote.h"
+#if A != 1
+# error -iquote was not preserved by later use of -I-
+#endif
+
+/* { dg-error "obsolete option -I- used" "warning message about deprecated -I-" { target *-*-* } 0 } */
diff -Nrup gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote2.c gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote2.c
--- gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote2.c	1969-12-31 19:00:00.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote2.c	2007-03-10 22:51:34.000000000 -0500
@@ -0,0 +1,9 @@
+/* { dg-do preprocess } */
+/* { dg-options "-I $srcdir/gcc.dg/cpp/inc -I-" } */
+
+#include "iquote.h"
+#if A != 1
+# error "-I dir" preceding -I- not transformed properly
+#endif
+
+/* { dg-error "obsolete option -I- used" "warning message about deprecated -I-" { target *-*-* } 0 } */
diff -Nrup gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote3.c gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote3.c
--- gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote3.c	1969-12-31 19:00:00.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote3.c	2007-03-10 22:51:34.000000000 -0500
@@ -0,0 +1,9 @@
+/* { dg-do preprocess } */
+/* { dg-options "-I$srcdir/gcc.dg/cpp/inc -I-" } */
+
+#include "iquote.h"
+#if A != 1
+# error "-Idir" preceding -I- not transformed properly
+#endif
+
+/* { dg-error "obsolete option -I- used" "warning message about deprecated -I-" { target *-*-* } 0 } */
diff -Nrup gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote4.c gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote4.c
--- gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote4.c	1969-12-31 19:00:00.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote4.c	2007-03-10 22:51:34.000000000 -0500
@@ -0,0 +1,7 @@
+/* { dg-do preprocess } */
+/* { dg-options "-I$srcdir/gcc.dg/cpp/inc -ignore-source-dir" } */
+
+#include "iquote.h"
+#if A != 1
+# error -ignore-source-dir not handled properly
+#endif
diff -Nrup gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote5.c gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote5.c
--- gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote5.c	1969-12-31 19:00:00.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote5.c	2007-03-10 22:51:34.000000000 -0500
@@ -0,0 +1,7 @@
+/* { dg-do preprocess } */
+/* { dg-options "-I$srcdir/gcc.dg/cpp/inc --ignore-source-dir" } */
+
+#include "iquote.h"
+#if A != 1
+# error --ignore-source-dir not handled properly
+#endif
diff -Nrup gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote6.c gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote6.c
--- gcc-4.3-20070302/gcc/testsuite/gcc.dg/cpp/iquote6.c	1969-12-31 19:00:00.000000000 -0500
+++ gcc-4.3-20070302-dv/gcc/testsuite/gcc.dg/cpp/iquote6.c	2007-03-10 22:51:34.000000000 -0500
@@ -0,0 +1,7 @@
+/* { dg-do preprocess } */
+/* { dg-options "-I$srcdir/gcc.dg/cpp/inc" } */
+
+#include "iquote.h"
+#if A != 0
+# error not using the source directory as expected
+#endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]