diff options
author | aaw <aaw@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-05-24 20:55:36 +0000 |
---|---|---|
committer | aaw <aaw@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-05-24 20:55:36 +0000 |
commit | ce079f700daa3663cfaeb8286f84ad54edee6733 (patch) | |
tree | 39f5da17b3f4b0f1ab1e9e7b4922fef43daed126 /libcpp/pch.c | |
parent | a78b652c30ccccb155dc1d9d644e8f42a53d6d19 (diff) | |
download | gcc-ce079f700daa3663cfaeb8286f84ad54edee6733.tar.gz |
* macro.c (_cpp_builtin_macro_text): Handle BT_COUNTER.
* pch.c (cpp_write_pch_deps): Save __COUNTER__ state.
(cpp_write_pch_state): Save __COUNTER__ state.
(cpp_valid_state): Check valid __COUNTER__ state.
(cpp_read_state): Read new __COUNTER__ state.
* include/cpplib.h (enum builtin_type): Add BT_COUNTER enumerator.
* init.c (builtin_array): Add __COUNTER__/BT_COUNTER.
* internal.h (struct cpp_reader): Add counter member.
* gcc.dg/cpp/counter-1.c: New test.
* gcc.dg/pch/counter-1.c: New test.
* gcc.dg/pch/counter-1.hs: New file.
* gcc.dg/pch/counter-2.c: New test.
* gcc.dg/pch/counter-2.hs: New file.
* gcc.dg/pch/counter-3.c: New test.
* gcc.dg/pch/counter-3.hs: New file.
* doc/cpp.texi (Common Predefined Macros): Add __COUNTER__
description.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@125041 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp/pch.c')
-rw-r--r-- | libcpp/pch.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/libcpp/pch.c b/libcpp/pch.c index cc23b4ee908..09373a2fd4e 100644 --- a/libcpp/pch.c +++ b/libcpp/pch.c @@ -337,6 +337,14 @@ cpp_write_pch_deps (cpp_reader *r, FILE *f) /* Free the saved state. */ free (ss); r->savedstate = NULL; + + /* Save the next value of __COUNTER__. */ + if (fwrite (&r->counter, sizeof (r->counter), 1, f) != 1) + { + cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header"); + return -1; + } + return 0; } @@ -361,6 +369,15 @@ cpp_write_pch_state (cpp_reader *r, FILE *f) return -1; } + /* Save the next __COUNTER__ value. When we include a precompiled header, + we need to start at the offset we would have if the header had been + included normally. */ + if (fwrite (&r->counter, sizeof (r->counter), 1, f) != 1) + { + cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header"); + return -1; + } + return 0; } @@ -423,6 +440,7 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd) struct ht_node_list nl = { 0, 0, 0 }; unsigned char *first, *last; unsigned int i; + unsigned int counter; /* Read in the list of identifiers that must be defined Check that they are defined in the same way. */ @@ -524,7 +542,23 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd) } free(nl.defs); + nl.defs = NULL; free (undeftab); + undeftab = NULL; + + /* Read in the next value of __COUNTER__. + Check that (a) __COUNTER__ was not used in the pch or (b) __COUNTER__ + has not been used in this translation unit. */ + if (read (fd, &counter, sizeof (counter)) != sizeof (counter)) + goto error; + if (counter && r->counter) + { + if (CPP_OPTION (r, warn_invalid_pch)) + cpp_error (r, CPP_DL_WARNING_SYSHDR, + "%s: not used because `__COUNTER__' is invalid", + name); + goto fail; + } /* We win! */ return 0; @@ -631,6 +665,7 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f, { size_t i; struct lexer_state old_state; + unsigned int counter; /* Restore spec_nodes, which will be full of references to the old hashtable entries and so will now be invalid. */ @@ -690,6 +725,12 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f, if (! _cpp_read_file_entries (r, f)) goto error; + if (fread (&counter, sizeof (counter), 1, f) != 1) + goto error; + + if (!r->counter) + r->counter = counter; + return 0; error: |