summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog13
-rw-r--r--gcc/c-pch.c41
-rw-r--r--gcc/doc/invoke.texi70
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-1.c5
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-1.hs3
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-1b.c5
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-1b.hs3
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-2.c5
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-2.hs1
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-3.c5
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-3.hs3
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-4.c6
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-4.hs1
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-5.c5
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-5.hs1
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-6.c5
-rw-r--r--gcc/testsuite/gcc.dg/pch/valid-6.hs1
18 files changed, 160 insertions, 21 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 331aefdf888..faf7f1c9c20 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,18 @@
2004-04-08 Geoffrey Keating <geoffk@apple.com>
+ PR pch/13419
+ PR pch/14137
+ Radar #: 3315288
+ * doc/invoke.texi (Precompiled Headers): Suggest -o
+ to put an output file in a particular place. Be more detailed
+ about which options affect PCH validity and which options
+ might not work.
+ * c-pch.c (pch_matching): New.
+ (MATCH_SIZE): New.
+ (struct c_pch_validity): New field 'match'.
+ (pch_init): Handle pch_matching.
+ (c_common_valid_pch): Check pch_matching.
+
* explow.c: Fix typo defining default of PROMOTE_FUNCTION_MODE.
2004-04-08 Mark Mitchell <mark@codesourcery.com>
diff --git a/gcc/c-pch.c b/gcc/c-pch.c
index 61418afaf49..8e2e6f126fa 100644
--- a/gcc/c-pch.c
+++ b/gcc/c-pch.c
@@ -35,6 +35,23 @@ Boston, MA 02111-1307, USA. */
#include "hosthooks.h"
#include "target.h"
+/* This is a list of flag variables that must match exactly, and their
+ names for the error message. The possible values for *flag_var must
+ fit in a 'signed char'. */
+
+static const struct c_pch_matching
+{
+ int *flag_var;
+ const char *flag_name;
+} pch_matching[] = {
+ { &flag_exceptions, "-fexceptions" },
+ { &flag_unit_at_a_time, "-funit-at-a-time" }
+};
+
+enum {
+ MATCH_SIZE = ARRAY_SIZE (pch_matching)
+};
+
/* This structure is read very early when validating the PCH, and
might be read for a PCH which is for a completely different compiler
for a different operating system. Thus, it should really only contain
@@ -52,6 +69,7 @@ struct c_pch_validity
unsigned char target_machine_length;
unsigned char version_length;
unsigned char debug_info_type;
+ signed char match[MATCH_SIZE];
void (*pch_init) (void);
size_t target_data_length;
};
@@ -120,6 +138,15 @@ pch_init (void)
v.target_machine_length = strlen (target_machine);
v.version_length = strlen (version_string);
v.debug_info_type = write_symbols;
+ {
+ size_t i;
+ for (i = 0; i < MATCH_SIZE; i++)
+ {
+ v.match[i] = *pch_matching[i].flag_var;
+ if (v.match[i] != *pch_matching[i].flag_var)
+ abort ();
+ }
+ }
v.pch_init = &pch_init;
target_validity = targetm.get_pch_validity (&v.target_data_length);
@@ -302,6 +329,20 @@ c_common_valid_pch (cpp_reader *pfile, const char *name, int fd)
return 2;
}
+ /* Check flags that must match exactly. */
+ {
+ size_t i;
+ for (i = 0; i < MATCH_SIZE; i++)
+ if (*pch_matching[i].flag_var != v.match[i])
+ {
+ if (cpp_get_options (pfile)->warn_invalid_pch)
+ cpp_error (pfile, CPP_DL_WARNING,
+ "%s: settings for %s do not match", name,
+ pch_matching[i].flag_name);
+ return 2;
+ }
+ }
+
/* If the text segment was not loaded at the same address as it was
when the PCH file was created, function pointers loaded from the
PCH will not be valid. We could in theory remap all the function
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 8c12a8b158a..2812bf97c8a 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -11380,11 +11380,11 @@ they've already been included (in the precompiled header).
If you need to precompile the same header file for different
languages, targets, or compiler options, you can instead make a
@emph{directory} named like @file{all.h.gch}, and put each precompiled
-header in the directory. (It doesn't matter what you call the files
-in the directory, every precompiled header in the directory will be
-considered.) The first precompiled header encountered in the
-directory that is valid for this compilation will be used; they're
-searched in no particular order.
+header in the directory, perhaps using @option{-o}. It doesn't matter
+what you call the files in the directory, every precompiled header in
+the directory will be considered. The first precompiled header
+encountered in the directory that is valid for this compilation will
+be used; they're searched in no particular order.
There are many other possibilities, limited only by your imagination,
good sense, and the constraints of your build system.
@@ -11394,40 +11394,68 @@ A precompiled header file can be used only when these conditions apply:
@itemize
@item
Only one precompiled header can be used in a particular compilation.
+
@item
A precompiled header can't be used once the first C token is seen. You
can have preprocessor directives before a precompiled header; you can
even include a precompiled header from inside another header, so long as
there are no C tokens before the @code{#include}.
+
@item
The precompiled header file must be produced for the same language as
the current compilation. You can't use a C precompiled header for a C++
compilation.
+
@item
The precompiled header file must be produced by the same compiler
version and configuration as the current compilation is using.
The easiest way to guarantee this is to use the same compiler binary
for creating and using precompiled headers.
+
@item
-Any macros defined before the precompiled header (including with
-@option{-D}) must either be defined in the same way as when the
-precompiled header was generated, or must not affect the precompiled
-header, which usually means that the they don't appear in the
-precompiled header at all.
+Any macros defined before the precompiled header is included must
+either be defined in the same way as when the precompiled header was
+generated, or must not affect the precompiled header, which usually
+means that the they don't appear in the precompiled header at all.
+
+The @option{-D} option is one way to define a macro before a
+precompiled header is included; using a @code{#define} can also do it.
+There are also some options that define macros implicitly, like
+@option{-O} and @option{-Wdeprecated}; the same rule applies to macros
+defined this way.
+
+@item If debugging information is output when using the precompiled
+header, using @option{-g} or similar, the same kind of debugging information
+must have been output when building the precompiled header. However,
+a precompiled header built using @option{-g} can be used in a compilation
+when no debugging information is being output.
+
+@item The same @option{-m} options must generally be used when building
+and using the precompiled header. @xref{Submodel Options},
+for any cases where this rule is relaxed.
+
+@item Each of the following options must be the same when building and using
+the precompiled header:
+
+@gccoptlist{-fexceptions -funit-at-a-time}
+
@item
-Certain command-line options must be defined in the same way as when the
-precompiled header was generated. At present, it's not clear which
-options are safe to change and which are not; the safest choice is to
-use exactly the same options when generating and using the precompiled
-header.
+Some other command-line options starting with @option{-f},
+@option{-p}, or @option{-O} must be defined in the same way as when
+the precompiled header was generated. At present, it's not clear
+which options are safe to change and which are not; the safest choice
+is to use exactly the same options when generating and using the
+precompiled header. The following are known to be safe:
+
+@gccoptlist{-pedantic-errors}
+
@end itemize
-For all of these but the last, the compiler will automatically ignore
-the precompiled header if the conditions aren't met. For the last item,
-some option changes will cause the precompiled header to be rejected,
-but not all incompatible option combinations have yet been found. If
-you find a new incompatible combination, please consider filing a bug
-report, see @ref{Bugs}.
+For all of these except the last, the compiler will automatically
+ignore the precompiled header if the conditions aren't met. If you
+find an option combination that doesn't work and doesn't cause the
+precompiled header to be ignored, please consider filing a bug report,
+see @ref{Bugs}.
@node Running Protoize
@section Running Protoize
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d714f2ef3d1..65dfd9e4ff6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2004-04-08 Geoffrey Keating <geoffk@apple.com>
+
+ * gcc.dg/pch/valid-1.c, gcc.dg/pch/valid-2.c, gcc.dg/pch/valid-3.c,
+ gcc.dg/pch/valid-4.c, gcc.dg/pch/valid-5.c, gcc.dg/pch/valid-6.c,
+ gcc.dg/pch/valid-1.hs, gcc.dg/pch/valid-2.hs, gcc.dg/pch/valid-3.hs,
+ gcc.dg/pch/valid-4.hs, gcc.dg/pch/valid-5.hs, gcc.dg/pch/valid-6.hs:
+ New tests.
+
2004-04-08 Paul Brook <paul@codesourcery.com>
* gcc.dg/spill-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/pch/valid-1.c b/gcc/testsuite/gcc.dg/pch/valid-1.c
new file mode 100644
index 00000000000..ebfa85a9949
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-1.c
@@ -0,0 +1,5 @@
+/* { dg-options "-I. -Winvalid-pch -g" } */
+
+#include "valid-1.h"/* { dg-error "created with -gnone, but used with -g|No such file|they were invalid" } */
+
+int x;
diff --git a/gcc/testsuite/gcc.dg/pch/valid-1.hs b/gcc/testsuite/gcc.dg/pch/valid-1.hs
new file mode 100644
index 00000000000..e1ed11df4cc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-1.hs
@@ -0,0 +1,3 @@
+/* { dg-options "-I. -Winvalid-pch -g0" } */
+
+extern int x;
diff --git a/gcc/testsuite/gcc.dg/pch/valid-1b.c b/gcc/testsuite/gcc.dg/pch/valid-1b.c
new file mode 100644
index 00000000000..a2709967c07
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-1b.c
@@ -0,0 +1,5 @@
+/* { dg-options "-I. -Winvalid-pch -g0" } */
+
+#include "valid-1b.h"
+
+int x;
diff --git a/gcc/testsuite/gcc.dg/pch/valid-1b.hs b/gcc/testsuite/gcc.dg/pch/valid-1b.hs
new file mode 100644
index 00000000000..6dc358735a7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-1b.hs
@@ -0,0 +1,3 @@
+/* { dg-options "-I. -Winvalid-pch -g" } */
+
+extern int x;
diff --git a/gcc/testsuite/gcc.dg/pch/valid-2.c b/gcc/testsuite/gcc.dg/pch/valid-2.c
new file mode 100644
index 00000000000..52a2e35a441
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-2.c
@@ -0,0 +1,5 @@
+/* { dg-options "-I. -Winvalid-pch -fexceptions" } */
+
+#include "valid-2.h"/* { dg-error "settings for -fexceptions do not match|No such file|they were invalid" } */
+
+int x;
diff --git a/gcc/testsuite/gcc.dg/pch/valid-2.hs b/gcc/testsuite/gcc.dg/pch/valid-2.hs
new file mode 100644
index 00000000000..2497af651c2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-2.hs
@@ -0,0 +1 @@
+extern int x;
diff --git a/gcc/testsuite/gcc.dg/pch/valid-3.c b/gcc/testsuite/gcc.dg/pch/valid-3.c
new file mode 100644
index 00000000000..741a917df5d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-3.c
@@ -0,0 +1,5 @@
+/* { dg-options "-I. -Winvalid-pch -fno-unit-at-a-time" } */
+
+#include "valid-3.h"/* { dg-error "settings for -funit-at-a-time do not match|No such file|they were invalid" } */
+
+int x;
diff --git a/gcc/testsuite/gcc.dg/pch/valid-3.hs b/gcc/testsuite/gcc.dg/pch/valid-3.hs
new file mode 100644
index 00000000000..2a0af94c9f7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-3.hs
@@ -0,0 +1,3 @@
+/* { dg-options "-I. -Winvalid-pch -funit-at-a-time" } */
+
+extern int x;
diff --git a/gcc/testsuite/gcc.dg/pch/valid-4.c b/gcc/testsuite/gcc.dg/pch/valid-4.c
new file mode 100644
index 00000000000..1249531ef67
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-4.c
@@ -0,0 +1,6 @@
+/* { dg-options "-I. -Winvalid-pch -Wtrigraphs" } */
+
+#include "valid-4.h"
+
+char * x = "??/"; /* { dg-error "trigraph" } */
+
diff --git a/gcc/testsuite/gcc.dg/pch/valid-4.hs b/gcc/testsuite/gcc.dg/pch/valid-4.hs
new file mode 100644
index 00000000000..051c720ee3f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-4.hs
@@ -0,0 +1 @@
+extern char * x;
diff --git a/gcc/testsuite/gcc.dg/pch/valid-5.c b/gcc/testsuite/gcc.dg/pch/valid-5.c
new file mode 100644
index 00000000000..4022d0458f2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-5.c
@@ -0,0 +1,5 @@
+/* { dg-options "-I. -Winvalid-pch -pedantic-errors" } */
+
+#include "valid-5.h"
+
+int x;
diff --git a/gcc/testsuite/gcc.dg/pch/valid-5.hs b/gcc/testsuite/gcc.dg/pch/valid-5.hs
new file mode 100644
index 00000000000..2497af651c2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-5.hs
@@ -0,0 +1 @@
+extern int x;
diff --git a/gcc/testsuite/gcc.dg/pch/valid-6.c b/gcc/testsuite/gcc.dg/pch/valid-6.c
new file mode 100644
index 00000000000..f111c31ae99
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-6.c
@@ -0,0 +1,5 @@
+/* { dg-options "-I. -Winvalid-pch -dH -pipe -fcond-mismatch" } */
+
+#include "valid-6.h"
+
+int x;
diff --git a/gcc/testsuite/gcc.dg/pch/valid-6.hs b/gcc/testsuite/gcc.dg/pch/valid-6.hs
new file mode 100644
index 00000000000..2497af651c2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pch/valid-6.hs
@@ -0,0 +1 @@
+extern int x;
OpenPOWER on IntegriCloud