+2004-06-21 Geoffrey Keating <geoffk@apple.com>
+
+ * c-opts.c (c_common_handle_option): Handle -fpch-preprocess.
+ * c-common.h (flag_pch_preprocess): Declare.
+ (c_common_pch_pragma): Likewise.
+ * c-common.c (flag_pch_preprocess): New.
+ * c-pch.c (c_common_read_pch): Support -fpreprocess-only.
+ (c_common_pch_pragma): New.
+ * c-ppoutput.c (cb_read_pch): New.
+ (init_pp_output): Support -fpch-preprocess.
+ * c-pragma.c (init_pragma): Support #pragma GNUC pch_preprocess.
+ * c.opt (fpch-preprocess): New.
+ * gcc.c (cpp_options): When save-temps, pass -fpch-preprocess.
+ * doc/cppopts.texi: Document -fpch-preprocess.
+ * doc/invoke.texi (Precompiled Headers): Mention that
+ -fpreprocessed is safe for PCH. Mention that if an option is
+ listed as safe that doesn't mean it does what you expect.
+
2004-06-22 Ben Elliston <bje@au.ibm.com>
* tree-ssa.c (ssa_redirect_edge): Correct leading comment.
char flag_dump_includes;
+/* Nonzero means process PCH files while preprocessing. */
+
+bool flag_pch_preprocess;
+
/* The file name to which we should write a precompiled header, or
NULL if no header will be written in this compile. */
extern char flag_dump_includes;
+/* Nonzero means process PCH files while preprocessing. */
+
+extern bool flag_pch_preprocess;
+
/* The file name to which we should write a precompiled header, or
NULL if no header will be written in this compile. */
extern int c_gimplify_expr (tree *, tree *, tree *);
extern tree c_build_bind_expr (tree, tree);
+/* In c-pch.c */
extern void pch_init (void);
extern int c_common_valid_pch (cpp_reader *pfile, const char *name, int fd);
extern void c_common_read_pch (cpp_reader *pfile, const char *name, int fd,
const char *orig);
extern void c_common_write_pch (void);
extern void c_common_no_more_pch (void);
+extern void c_common_pch_pragma (cpp_reader *pfile);
+
extern void builtin_define_with_value (const char *, const char *, int);
extern void c_stddef_cpp_builtins (void);
extern void fe_file_change (const struct line_map *);
cpp_opts->restore_pch_deps = value;
break;
+ case OPT_fpch_preprocess:
+ flag_pch_preprocess = value;
+ break;
+
case OPT_fpermissive:
flag_permissive = value;
break;
{
FILE *f;
struct c_pch_header h;
- char *buf;
- unsigned long written;
struct save_macro_data *smd;
f = fdopen (fd, "rb");
return;
}
- buf = xmalloc (16384);
- for (written = 0; written < h.asm_size; )
+ if (!flag_preprocess_only)
{
- long size = h.asm_size - written;
- if (size > 16384)
- size = 16384;
- if (fread (buf, size, 1, f) != 1
- || fwrite (buf, size, 1, asm_out_file) != 1)
- cpp_errno (pfile, CPP_DL_ERROR, "reading");
- written += size;
+ unsigned long written;
+ char * buf = xmalloc (16384);
+
+ for (written = 0; written < h.asm_size; )
+ {
+ long size = h.asm_size - written;
+ if (size > 16384)
+ size = 16384;
+ if (fread (buf, size, 1, f) != 1
+ || fwrite (buf, size, 1, asm_out_file) != 1)
+ cpp_errno (pfile, CPP_DL_ERROR, "reading");
+ written += size;
+ }
+ free (buf);
+ }
+ else
+ {
+ /* If we're preprocessing, don't write to a NULL
+ asm_out_file. */
+ if (fseek (f, h.asm_size, SEEK_CUR) != 0)
+ cpp_errno (pfile, CPP_DL_ERROR, "seeking");
}
- free (buf);
cpp_prepare_state (pfile, &smd);
host_hooks.gt_pch_use_address (NULL, 0, -1, 0);
}
}
+
+/* Handle #pragma GCC pch_preprocess, to load in the PCH file. */
+
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
+void
+c_common_pch_pragma (cpp_reader *pfile)
+{
+ tree name_t;
+ const char *name;
+ int fd;
+
+ if (c_lex (&name_t) != CPP_STRING)
+ {
+ error ("malformed #pragma GCC pch_preprocess, ignored");
+ return;
+ }
+
+ if (! cpp_get_options (pfile)->preprocessed)
+ {
+ error ("pch_preprocess pragma should only be used with -fpreprocessed");
+ inform ("use #include instead");
+ return;
+ }
+
+ name = TREE_STRING_POINTER (name_t);
+
+ fd = open (name, O_RDONLY | O_BINARY, 0666);
+ if (fd == -1)
+ fatal_error ("%s: couldn't open PCH file: %m\n", name);
+
+ if (c_common_valid_pch (pfile, name, fd) != 1)
+ {
+ if (!cpp_get_options (pfile)->warn_invalid_pch)
+ inform ("use -Winvalid-pch for more information");
+ fatal_error ("%s: PCH file was invalid", name);
+ }
+
+ c_common_read_pch (pfile, name, fd, name);
+
+ close (fd);
+}
const char *, int);
static void cb_ident (cpp_reader *, fileline, const cpp_string *);
static void cb_def_pragma (cpp_reader *, fileline);
+static void cb_read_pch (cpp_reader *pfile, const char *name,
+ int fd, const char *orig_name);
/* Preprocess and output. */
void
if (flag_dump_includes)
cb->include = cb_include;
+ if (flag_pch_preprocess)
+ {
+ cb->valid_pch = c_common_valid_pch;
+ cb->read_pch = cb_read_pch;
+ }
+
if (flag_dump_macros == 'N' || flag_dump_macros == 'D')
{
cb->define = cb_define;
return 1;
}
+
+/* Load in the PCH file NAME, open on FD. It was originally searched for
+ by ORIG_NAME. Also, print out a #include command so that the PCH
+ file can be loaded when the preprocessed output is compiled. */
+
+static void
+cb_read_pch (cpp_reader *pfile, const char *name,
+ int fd, const char *orig_name ATTRIBUTE_UNUSED)
+{
+ c_common_read_pch (pfile, name, fd, orig_name);
+
+ fprintf (print.outf, "#pragma GCC pch_preprocess \"%s\"\n", name);
+ print.src_line++;
+}
c_register_pragma (0, "redefine_extname", handle_pragma_redefine_extname);
c_register_pragma (0, "extern_prefix", handle_pragma_extern_prefix);
+ c_register_pragma ("GCC", "pch_preprocess", c_common_pch_pragma);
+
#ifdef REGISTER_TARGET_PRAGMAS
REGISTER_TARGET_PRAGMAS ();
#endif
fpch-deps
C ObjC C++ ObjC++
+fpch-preprocess
+C ObjC C++ ObjC++
+Look for and use PCH files even when preprocessing
+
fpermissive
C++ ObjC++
Downgrade conformance errors to warnings
create it because those files are not consulted when a precompiled
header is used.
+@item -fpch-preprocess
+@opindex fpch-preprocess
+This option allows use of a precompiled header (@pxref{Precompiled
+Headers}) together with @option{-E}. It inserts a special @code{#pragma},
+@code{#pragma GCC pch_preprocess "<filename>"} in the output to mark
+the place where the precompiled header was found, and its filename. When
+@code{-fpreprocessed} is in use, GCC recognizes this @code{#pragma} and
+loads the PCH.
+
+This option is off by default, because the resulting preprocessed output
+is only really suitable as input to GCC. It is switched on by
+@option{-save-temps}.
+
+You should not write this @code{#pragma} in your own code, but it is
+safe to edit the filename if the PCH file is available in a different
+location. The filename may be absolute or it may be relative to GCC's
+current directory.
+
@end ifclear
@item -x c
@itemx -x c++
is to use exactly the same options when generating and using the
precompiled header. The following are known to be safe:
-@gccoptlist{-pedantic-errors}
+@gccoptlist{-fpreprocessed -pedantic-errors}
@end itemize
precompiled header to be ignored, please consider filing a bug report,
see @ref{Bugs}.
+If you do use differing options when generating and using the
+precompiled header, the actual behaviour will be a mixture of the
+behaviour for the options. For instance, if you use @option{-g} to
+generate the precompiled header but not when using it, you may or may
+not get debugging information for routines in the precompiled header.
+
@node Running Protoize
@section Running Protoize
in turn cause preprocessor symbols to be defined specially. */
static const char *cpp_options =
"%(cpp_unique_options) %1 %{m*} %{std*} %{ansi} %{W*&pedantic*} %{w} %{f*}\
- %{g*:%{!g0:%{!fno-working-directory:-fworking-directory}}} %{O*} %{undef}";
+ %{g*:%{!g0:%{!fno-working-directory:-fworking-directory}}} %{O*} %{undef}\
+ %{save-temps:-fpch-preprocess}";
/* This contains cpp options which are not passed when the preprocessor
output will be used by another program. */
+2004-06-21 Geoffrey Keating <geoffk@apple.com>
+
+ * gcc.dg/pch/save-temps-1.c: New file.
+ * gcc.dg/pch/save-temps-1.hs: New file.
+
2004-06-22 Janne Blomqvist <jblomqvi@cc.hut.fi>
* gfortran.fortran-torture/execute/iolength_1.f90: New test.
--- /dev/null
+/* { dg-options "-I. -save-temps" } */
+#include "save-temps-1.h"
+#ifndef T
+#error T not defined
+#endif
+#include <stddef.h>
+int x;
--- /dev/null
+#define T 123
+int foo (void)
+{
+ return 3;
+}
+2004-06-21 Geoffrey Keating <geoffk@apple.com>
+
+ * files.c (should_stack_file): Correct swapped parameters to call
+ to cb.read_pch.
+ * pch.c (cpp_valid_state): Handle -fpreprocessed.
+
2004-06-15 Paolo Bonzini <bonzini@gnu.org>
* Makefile.in: Regenerate with automake 1.8.5.
/* Handle PCH files immediately; don't stack them. */
if (file->pch)
{
- pfile->cb.read_pch (pfile, file->path, file->fd, file->pchname);
+ pfile->cb.read_pch (pfile, file->pchname, file->fd, file->path);
close (file->fd);
file->fd = -1;
return false;
if (m.name_length == 0)
break;
+ /* If this file is already preprocessed, there won't be any
+ macros defined, and that's OK. */
+ if (CPP_OPTION (r, preprocessed))
+ {
+ if (lseek (fd, m.definition_length, SEEK_CUR) == -1)
+ goto error;
+ continue;
+ }
+
if (m.definition_length > namebufsz)
{
free (namebuf);
namebufsz = m.definition_length + 256;
namebuf = xmalloc (namebufsz);
}
-
+
if ((size_t)read (fd, namebuf, m.definition_length)
!= m.definition_length)
goto error;