Date: Tue, 30 Aug 2016 19:39:33 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r305083 - in head/contrib: gcc/doc gcclibs/libcpp Message-ID: <201608301939.u7UJdXCT024620@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Tue Aug 30 19:39:33 2016 New Revision: 305083 URL: https://svnweb.freebsd.org/changeset/base/305083 Log: libcpp: Complete the __COUNTER__ support with upstream implementation. We brought an original __COUNTER__ implementation in r228474, however, it was missing documentation and it had a different behaviour for precompiled headers with respect to the upstream version. Since the upstream version is under the same license as GCC4.2, bring the missing pieces to reduce differences against upstream. Optained from: GCC pre-4.3 (rev. 125041 ; GPLv2) Modified: head/contrib/gcc/doc/cpp.texi head/contrib/gcclibs/libcpp/ChangeLog.gcc43 head/contrib/gcclibs/libcpp/internal.h head/contrib/gcclibs/libcpp/macro.c head/contrib/gcclibs/libcpp/pch.c Modified: head/contrib/gcc/doc/cpp.texi ============================================================================== --- head/contrib/gcc/doc/cpp.texi Tue Aug 30 19:31:12 2016 (r305082) +++ head/contrib/gcc/doc/cpp.texi Tue Aug 30 19:39:33 2016 (r305083) @@ -1912,6 +1912,13 @@ underscores. @table @code +@item __COUNTER__ +This macro expands to sequential integral values starting from 0. In +conjuction with the @code{##} operator, this provides a convenient means to +generate unique identifiers. Care must be taken to ensure that +@code{__COUNTER__} is not expanded prior to inclusion of precompiled headers +which use it. Otherwise, the precompiled headers will not be used. + @item __GNUC__ @itemx __GNUC_MINOR__ @itemx __GNUC_PATCHLEVEL__ Modified: head/contrib/gcclibs/libcpp/ChangeLog.gcc43 ============================================================================== --- head/contrib/gcclibs/libcpp/ChangeLog.gcc43 Tue Aug 30 19:31:12 2016 (r305082) +++ head/contrib/gcclibs/libcpp/ChangeLog.gcc43 Tue Aug 30 19:39:33 2016 (r305083) @@ -12,6 +12,17 @@ PR preprocessor/14331 * lex.c (_cpp_get_fresh_line): Don't warn if no newline at EOF. +2007-05-24 Ollie Wild <aaw@google.com> (r125041) + + * 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. + 2007-05-21 Ian Lance Taylor <iant@google.com> (r124929) * internal.h (struct cpp_reader): Add new fields: Modified: head/contrib/gcclibs/libcpp/internal.h ============================================================================== --- head/contrib/gcclibs/libcpp/internal.h Tue Aug 30 19:31:12 2016 (r305082) +++ head/contrib/gcclibs/libcpp/internal.h Tue Aug 30 19:39:33 2016 (r305083) @@ -458,7 +458,8 @@ struct cpp_reader of precompiled headers. */ struct cpp_savedstate *savedstate; - unsigned int nextcounter; + /* Next value of __COUNTER__ macro. */ + unsigned int counter; }; /* Character classes. Based on the more primitive macros in safe-ctype.h. Modified: head/contrib/gcclibs/libcpp/macro.c ============================================================================== --- head/contrib/gcclibs/libcpp/macro.c Tue Aug 30 19:31:12 2016 (r305082) +++ head/contrib/gcclibs/libcpp/macro.c Tue Aug 30 19:39:33 2016 (r305083) @@ -268,7 +268,7 @@ _cpp_builtin_macro_text (cpp_reader *pfi if (CPP_OPTION (pfile, directives_only) && pfile->state.in_directive) cpp_error (pfile, CPP_DL_ERROR, "__COUNTER__ expanded inside directive with -fdirectives-only"); - number = pfile->nextcounter++; + number = pfile->counter++; break; } Modified: head/contrib/gcclibs/libcpp/pch.c ============================================================================== --- head/contrib/gcclibs/libcpp/pch.c Tue Aug 30 19:31:12 2016 (r305082) +++ head/contrib/gcclibs/libcpp/pch.c Tue Aug 30 19:39:33 2016 (r305083) @@ -337,6 +337,14 @@ cpp_write_pch_deps (cpp_reader *r, FILE /* 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 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 ch 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 ch } 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 cha { 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 cha 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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201608301939.u7UJdXCT024620>