In my last PPH change, I eliminated the redundancy in the preprocessor
commitffd26145521d15fd0b01f0d53b8477d1da70bbfd
authorcrowl <crowl@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 8 Apr 2011 18:42:55 +0000 (8 18:42 +0000)
committercrowl <crowl@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 8 Apr 2011 18:42:55 +0000 (8 18:42 +0000)
tree225ca189b34ee758d0f19c52c871458961b10691
parent9f93da2ba9602ec799d7488037b4b2e4135de8a2
In my last PPH change, I eliminated the redundancy in the preprocessor
identifier lookaside table by removing the name of the identifier from
the head of the macro value.  This later led to a buffer overrun in
libcpp/symtab.c cpp_lt_replay.  The buffer was allocated based on the
value string size, which is was no longer large enough to hold the
definition string.

Split cpp_idents_used.max_length and cpp_lookaside.max_length into
max_ident_len and max_value_len.  In cpp_lt_replay, allocate the
buffer based on the sum of max_ident_len and max_value_len.

The simple macro validation scheme for PTH is not sufficient for
PPH.  In particular, in libcpp, even identifiers that are skipped
in preprocessing are entered into the symbol table.  We need to
ignore these.  So, add two macro attributes, used_by_directive and
expanded_to_text.  If neither of these attributes is set, then the
macro is not used and can be ignored for validation and replay.

These changes bring the macro validation to a workable state.  There
may be some fine tuning later.

Make an inability to open a PPH file for reading a plain error rather
than a fatal error.  Fatal errors do not seem to play well with tests.

Adjust tests to reflect changes.  There is still one unexpected
failure, p1mean.cc does not compare equal in assembly.  Not yet
investigated.

Index: gcc/testsuite/ChangeLog.pph

2011-04-06  Lawrence Crowl  <crowl@google.com>

* g++.dg/pph/p1mean.cc: Now pass validation.
* g++.dg/pph/p1stdlib.cc: Likewise.
* g++.dg/pph/d1symnotinc.cc: Failure to read is now not fatal.
        * g++.dg/pph/d1chained.cc: Miscategorized as a failure, ...
        * g++.dg/pph/c1chained.cc: so it has been renamed.

Index: gcc/cp/ChangeLog.pph

2011-04-06  Lawrence Crowl  <crowl@google.com>

        * pph.c (pth_dump_identifiers):  Split cpp_idents_used::max_length
into max_ident_length and max_value_length.  Print used_by_directive
and expanded_to_text attributes of macros.
(pth_save_identifiers): Split cpp_idents_used::max_length into
max_ident_length and max_value_length.  Filter out macro that are
neither used_by_directive nor expanded_to_text, which requires
precounting the number of entries remaining.  Save used_by_directive
and expanded_to_text attributes of the macros.
(pth_load_identifiers): Split cpp_idents_used::max_length into
max_ident_length and max_value_length.  Restore used_by_directive and
expanded_to_text attributes of the macros.
(pph_read_file): Make failure to read a pph file a non-fatal error.

Index: libcpp/ChangeLog.pph

2011-04-06  Lawrence Crowl <crowl@google.com>

        * include/cpplib.h (struct cpp_hashnode): Add used_by_directive and
expanded_to_text attributes for macros.  Take their bits from
directive_index, which does not need them.
        * include/symtab.h (struct cpp_idents_used): Split max_length into
max_ident_len and max_value_len.  Reorder fields to avoid gaps.
(struct cpp_ident_use): Add used_by_directive and expanded_to_text
attributes for macros.
        * internal.h (struct cpp_lookaside): Split max_length into
        max_ident_len and max_value_len.
* macro.c (enter_macro_context): Mark expanded_to_text macro attribute.
* directives.c (DIRECTIVE_TABLE): Add sizing comment.
(do_define): Mark used_by_directive macro attribute.
(do_undef): Likewise.
(do_ifdef): Likewise.
* expr.c (parse_defined): Mark used_by_directive macro attribute.
        * symtab.c (cpp_lt_create): Split cpp_lookaside::max_length into
max_ident_len and max_value_len.
* (lt_macro_value): Likewise.
* (lt_lookup): Likewise.
        * (cpp_lt_capture): Likewise.  Also save used_by_directive and
expanded_to_text attributes of macros.
        * (cpp_lt_replay): Split cpp_idents_used::max_lenth into
        max_ident_len and max_value_len.  Allocate a buffer with the sum.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/pph@172204 138bc75d-0d04-0410-961f-82ee72b054a4
16 files changed:
gcc/cp/ChangeLog.pph
gcc/cp/pph.c
gcc/testsuite/ChangeLog.pph
gcc/testsuite/g++.dg/pph/c1chained.cc [new file with mode: 0644]
gcc/testsuite/g++.dg/pph/d1chained.cc [deleted file]
gcc/testsuite/g++.dg/pph/d1symnotinc.cc
gcc/testsuite/g++.dg/pph/p1mean.cc
gcc/testsuite/g++.dg/pph/p1stdlib.cc
libcpp/ChangeLog.pph
libcpp/directives.c
libcpp/expr.c
libcpp/include/cpplib.h
libcpp/include/symtab.h
libcpp/internal.h
libcpp/macro.c
libcpp/symtab.c