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_ignores_source_dir behavior of -I-


Daniel Villeneuve wrote:

Zack Weinberg wrote:

Please resubmit the bugfix and the new option as two separate patches
(with the above suggested change, and test cases if you can hack 'em in
the dejagnu framework - see gcc.dg/cpp/ for existing examples, and note
the 'inc' subdirectory of that directory).


I'll look at this later this week.

Sorry for the other patch that I've sent yesterday, it is fragile because the handling of -I- is spread between gcc.c::process_command and c-opts.c::quote_split_chain, and the correctness of the whole relies on the magic of the specs to get things correct.

Here is a better (more complete) patch for the compatibility problem
between -I, -I- and -iquote.

The approach is an extension of the approach in the preceding patch:
process all the behaviors of -I- within gcc.c::process_command, and remove
all traces of -I- elsewhere in the code.  For this, I had to incorporate
the new option -ignore-source-dir in the patch.

As a summary:

1- A new option, -ignore-source-dir, is added to trigger the
  quote_ignores_source_dir behavior of -I- without any other effects.
2- The first pass over options in process_command detects -I-, fails if -I-
  is used more than once, and issues the warning about -I- being obsolete
  (this was all handled in c-opts.c before).
3- The second pass over options in process_command substitutes
  -ignore-source-dir for -I- and substitutes -iquote for -I when appearing
  prior to -I-.

With this patch, -I- is completely processed in a single place
(process_command) as a rewriting into other standard options.  Ordering of
-iquote and -I options before -I- is preserved. It should be easy to remove
the -I- processing later (all in one place).

2006-02-16 Daniel Villeneuve <daniel_villeneuve@sympatico.ca>

   * c.opt (-ignore-source-dir): New option, triggering the
   quote_ignores_source_dir behavior of (deprecated) -I-.

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

   * c-incpath.h (ignore_source_dir): Renamed from split_quote_chain.
   * c-inc-path.c (ignore_source_dir): Likewise.  Only keep the
   quote_ignores_source_dir behavior.

   * 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.

   * testsuite/gcc.dg/cpp/iquote.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.

--
Daniel Villeneuve

diff -N -u -p -r gcc-4.0.2/NEWS gcc-4.0.2-dv/NEWS
--- gcc-4.0.2/NEWS    2005-09-28 02:18:15.000000000 -0400
+++ gcc-4.0.2-dv/NEWS    2006-02-19 15:17:36.000000000 -0500
@@ -123,8 +123,8 @@ Caveats
       differently and doesn't need those work-arounds.
     * The  graph-coloring  register  allocator,  formerly enabled by the
       option -fnew-ra, has been discontinued.
-     * -I-  has been deprecated. -iquote is meant to replace the need for
-       this option.
+     * -I-  has been deprecated. -iquote and -ignore-source-dir are meant
+       to replace the need for this option.
     * The MIPS -membedded-pic and -mrnames options have been removed.
     * All  MIPS  targets  now  require the GNU assembler. In particular,
       IRIX  configurations  can  no  longer  use the MIPSpro assemblers,
diff -N -u -p -r gcc-4.0.2/gcc/ChangeLog gcc-4.0.2-dv/gcc/ChangeLog
--- gcc-4.0.2/gcc/ChangeLog    2005-09-20 23:56:04.000000000 -0400
+++ gcc-4.0.2-dv/gcc/ChangeLog    2006-02-19 16:00:32.000000000 -0500
@@ -1,3 +1,28 @@
+2006-02-16  Daniel Villeneuve  <daniel_villeneuve@sympatico.ca>
+
+    * c.opt (-ignore-source-dir): New option, triggering the
+    quote_ignores_source_dir behavior of (deprecated) -I-.
+
+    * c-opts.c (quote_chain_split): Removed.
+    (c_common_handle_option): No longer process -I- within OPT_I case.
+    Add case for OPT_ignore_source_dir.
+
+    * c-incpath.h (ignore_source_dir): Renamed from split_quote_chain.
+    * c-inc-path.c (ignore_source_dir): Likewise.  Only keep the
+    quote_ignores_source_dir behavior.
+
+    * 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.
+
+    * testsuite/gcc.dg/cpp/iquote.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.
+
2005-09-20  Release Manager

    * GCC 4.0.2 released.
diff -N -u -p -r gcc-4.0.2/gcc/c-incpath.c gcc-4.0.2-dv/gcc/c-incpath.c
--- gcc-4.0.2/gcc/c-incpath.c    2005-01-23 10:05:27.000000000 -0500
+++ gcc-4.0.2-dv/gcc/c-incpath.c    2006-02-19 12:09:04.000000000 -0500
@@ -296,18 +296,9 @@ 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)
+ignore_source_dir (void)
{
-  heads[QUOTE] = heads[BRACKET];
-  tails[QUOTE] = tails[BRACKET];
-  heads[BRACKET] = NULL;
-  tails[BRACKET] = NULL;
-  /* This is NOT redundant.  */
  quote_ignores_source_dir = true;
}

diff -N -u -p -r gcc-4.0.2/gcc/c-incpath.h gcc-4.0.2-dv/gcc/c-incpath.h
--- gcc-4.0.2/gcc/c-incpath.h    2005-01-23 10:05:28.000000000 -0500
+++ gcc-4.0.2-dv/gcc/c-incpath.h    2006-02-19 12:08:49.000000000 -0500
@@ -15,7 +15,7 @@ You should have received a copy of the G
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

-extern void split_quote_chain (void);
+extern void ignore_source_dir (void);
extern void add_path (char *, int, int, bool);
extern void register_include_chains (cpp_reader *, const char *,
                     const char *, int, int, int);
diff -N -u -p -r gcc-4.0.2/gcc/c-opts.c gcc-4.0.2-dv/gcc/c-opts.c
--- gcc-4.0.2/gcc/c-opts.c    2005-04-30 21:11:56.000000000 -0400
+++ gcc-4.0.2-dv/gcc/c-opts.c    2006-02-19 12:08:36.000000000 -0500
@@ -85,9 +85,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;

@@ -295,16 +292,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:
@@ -790,6 +778,10 @@ c_common_handle_option (size_t scode, co
      add_path (xstrdup (arg), AFTER, 0, true);
      break;

+    case OPT_ignore_source_dir:
+      ignore_source_dir ();
+      break;
+
    case OPT_imacros:
    case OPT_include:
      defer_opt (code, arg);
diff -N -u -p -r gcc-4.0.2/gcc/c.opt gcc-4.0.2-dv/gcc/c.opt
--- gcc-4.0.2/gcc/c.opt    2005-04-30 21:11:57.000000000 -0400
+++ gcc-4.0.2-dv/gcc/c.opt    2006-02-19 12:17:42.000000000 -0500
@@ -739,6 +739,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++
+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 -N -u -p -r gcc-4.0.2/gcc/doc/cpp.texi gcc-4.0.2-dv/gcc/doc/cpp.texi
--- gcc-4.0.2/gcc/doc/cpp.texi 2005-04-14 13:17:29.000000000 -0400
+++ gcc-4.0.2-dv/gcc/doc/cpp.texi 2006-02-19 15:27:56.000000000 -0500
@@ -898,8 +898,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{""}
@@ -4045,8 +4045,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.  @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

@@ -4140,8 +4140,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 -N -u -p -r gcc-4.0.2/gcc/doc/cppopts.texi gcc-4.0.2-dv/gcc/doc/cppopts.texi
--- gcc-4.0.2/gcc/doc/cppopts.texi 2005-04-17 07:37:51.000000000 -0400
+++ gcc-4.0.2-dv/gcc/doc/cppopts.texi 2006-02-19 15:28:48.000000000 -0500
@@ -463,6 +463,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 -N -u -p -r gcc-4.0.2/gcc/doc/invoke.texi gcc-4.0.2-dv/gcc/doc/invoke.texi
--- gcc-4.0.2/gcc/doc/invoke.texi 2005-09-02 04:12:30.000000000 -0400
+++ gcc-4.0.2-dv/gcc/doc/invoke.texi 2006-02-19 15:23:18.000000000 -0500
@@ -355,7 +355,7 @@ 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-}
+@gccoptlist{-B@var{prefix} -I@var{dir} -ignore-source-dir -iquote@var{dir} -L@var{dir} -specs=@var{file} -I-}


@item Target Options
@c I wrote this xref this way to avoid overfull hbox. -- rms
@@ -6033,6 +6033,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
@@ -6100,8 +6105,10 @@ are processed in order, from left to rig
@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 -N -u -p -r gcc-4.0.2/gcc/gcc.c gcc-4.0.2-dv/gcc/gcc.c
--- gcc-4.0.2/gcc/gcc.c 2005-06-06 15:20:29.000000000 -0400
+++ gcc-4.0.2-dv/gcc/gcc.c 2006-02-19 12:29:20.000000000 -0500
@@ -3134,6 +3134,7 @@ process_command (int argc, const char **
int last_language_n_infiles;
int have_c = 0;
int lang_n_infiles = 0;
+ int include_barrier = 0;
#ifdef MODIFY_TARGET_NAME
int is_modify_target_name;
int j;
@@ -3755,6 +3756,12 @@ 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/-ignore-source-dir instead");
+ }


n_switches++;

@@ -4006,6 +4013,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 -N -u -p -r gcc-4.0.2/gcc/testsuite/gcc.dg/cpp/inc/iquote.h gcc-4.0.2-dv/gcc/testsuite/gcc.dg/cpp/inc/iquote.h
--- gcc-4.0.2/gcc/testsuite/gcc.dg/cpp/inc/iquote.h 1969-12-31 19:00:00.000000000 -0500
+++ gcc-4.0.2-dv/gcc/testsuite/gcc.dg/cpp/inc/iquote.h 2006-02-17 15:00:49.000000000 -0500
@@ -0,0 +1 @@
+#define A 1
diff -N -u -p -r gcc-4.0.2/gcc/testsuite/gcc.dg/cpp/iquote.c gcc-4.0.2-dv/gcc/testsuite/gcc.dg/cpp/iquote.c
--- gcc-4.0.2/gcc/testsuite/gcc.dg/cpp/iquote.c 1969-12-31 19:00:00.000000000 -0500
+++ gcc-4.0.2-dv/gcc/testsuite/gcc.dg/cpp/iquote.c 2006-02-17 16:42:16.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 -N -u -p -r gcc-4.0.2/gcc/testsuite/gcc.dg/cpp/iquote.h gcc-4.0.2-dv/gcc/testsuite/gcc.dg/cpp/iquote.h
--- gcc-4.0.2/gcc/testsuite/gcc.dg/cpp/iquote.h 1969-12-31 19:00:00.000000000 -0500
+++ gcc-4.0.2-dv/gcc/testsuite/gcc.dg/cpp/iquote.h 2006-02-17 15:00:54.000000000 -0500
@@ -0,0 +1 @@
+#define A 2



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