Re: [pph] Make libcpp symbol validation a warning (issue5235061)

2011-10-14 Thread Gabriel Charette
Yes, I understand that.

But when the second 2.pph is skipped when reading foo.pph, the reading
of its line_table is also skipped (as foo.pph doesn't contain the
line_table information for 2.h, 2.pph does and adds it when its
included as a child, but if it's skipped, the line_table info for 2.h
should never make it in the line_table), so I don't see why this is an
issue for the line_table (other than the assert about the number of
line table entries read). What I was suggesting is that as far as the
assert is concerned it would be stronger to count the number of
skipped child headers on read and assert num_read+num_skipped ==
num_expected_childs basically (it is still only an assert so no big
deal I guess).

Essentially this patch fixes the last bug we had in the line_table
merging (i.e. that guarded out headers in the non-pph version weren't
guarded out in the pph version) and this is a good thing. I'm just
being picky about weakening asserts!


I still think it would be nice to have a way to test constructs like
the line_table at the end of parsing (maybe a new flag, as I was
suggesting in my previous email, as gcc doesn't allow for modular
testing) and compare pph and non-pph versions. Testing at this level
would potentially be much better than trying to understand tricky test
failures from the ground up. This is beyond the scope of this patch of
course, but something to keep in mind I think.

Gab

On Fri, Oct 14, 2011 at 8:16 AM, Diego Novillo  wrote:
>
> On 11-10-13 17:55 , Gabriel Charette wrote:
>
>> I'm not sure exactly how you skip headers already parsed now (we
>> didn't used to when I wrote this code and that was the only problem
>> remaining in the line_table (i.e. duplicate entries for guarded
>> headers in the non-pph compile)), but couldn't you count the number of
>> skipped entries and assert (line_table->used - used_before) +
>> numSkipped == expected_in) ?
>
> The problem is that the compilation process of foo.h -> foo.pph may generate 
> different line tables than a compile that includes foo.pph. For instance,
>
> foo.h:
> #include "1.pph"
> #include "2.pph"
> #include "3.pph"
>
> foo.cc:
> #include "2.pph"
> #include "foo.pph"
>
>
> When we compile foo.h, the line table incorporates the effects of including 
> 2.pph, and that's what we save to foo.pph.  However, when compiling foo.cc, 
> the first thing we do is include 2.pph, so when processing the include for 
> foo.pph, we will completely skip over 2.pph.
>
> That's why we cannot really have the same line table that we had when we 
> generated foo.pph.
>
>
> Diego.


Re: [pph] Make libcpp symbol validation a warning (issue5235061)

2011-10-20 Thread Gabriel Charette
I just thought about something..

Earlier I said that ALL line_table issues were resolved after this
patch (as it ignores the re-included headers that were guarded, as the
non-pph compiler does naturally).

One problem remains however, I'm pretty sure that re-included
non-pph'ed header's line_table entries are still showing up multiple
times (as the direct non-pph childs of a given pph_include have their
line_table entries copied one by one from the pph file).

I think we were talking about somehow remembering guards context in
which DECLs were declared and then ignoring DECLs streamed in if they
belong to a given "header guard type" that was previously seen in a
prior include using the same non-pph header, allowing us to ignore
those DECLs that are re-declared when they should have been guarded
out the second time.

I'm not sure whether there is machinery to handle non-pph re-includes
yet... but... at the very least, I'm pretty sure those non-pph entries
still show up multiple times in the line_table.

Now, we can't just remove/ignore those entries either... doing so
would alter the expected location offset (pph_loc_offset) applied to
all tokens streamed in directly from the pph header.

What we could potentially do is:
- ignore the repeated non-pph entry
- remember the number of locations this entry was "supposed" to take
(call that pph_loc_ignored_offset)
- then for DECLs imported after it we would then need an offset of
pph_loc_offset - pph_loc_ignored_offset, to compensate for the missing
entries in the line_table

The problem here obviously is that I don't think we have a way of
knowing which DECLs come before, inside, and after a given non-pph
header included in the parent pph header which we are currently
reading.

Furthermore, a DECL coming after the non-pph header could potentially
refer to something inside the ignored non-pph header and the
source_location of the referred token would now be invalid (although
that might already be fixed by the cache hit which would redirect that
token reference to the same token in the first included copy of that
same header which wasn't actually skipped as it was first and which is
valid)


On Tue, Oct 11, 2011 at 4:26 PM, Diego Novillo  wrote:
> @@ -328,8 +327,6 @@ pph_in_line_table_and_includes (pph_stream *stream)
>   int entries_offset = line_table->used - PPH_NUM_IGNORED_LINE_TABLE_ENTRIES;
>   enum pph_linetable_marker next_lt_marker = pph_in_linetable_marker (stream);
>
> -  pph_reading_includes++;
> -
>   for (first = true; next_lt_marker != PPH_LINETABLE_END;
>        next_lt_marker = pph_in_linetable_marker (stream))
>     {
> @@ -373,19 +370,33 @@ pph_in_line_table_and_includes (pph_stream *stream)
>          else
>            lm->included_from += entries_offset;
>

Also, if we do ignore some non-pph entries, the included_from
calculation is going to need some trickier logic as well (it's fine
for the pph includes though as each child calculates it's own offset)

> - gcc_assert (lm->included_from < (int) line_table->used);
> -

Also, I think this slipped in my previous comment, but I don't see how
this assert could trigger in the current code. If it did trigger
something was definitely wrong as it asserts the offseted
included_from is referring to an entry that is actually in the
line_table...

>  lm->start_location += pph_loc_offset;

Cheers,
Gab


> --
> This patch is available for review at http://codereview.appspot.com/5235061
>


Re: [pph] Free buffers used during tree encoding/decoding

2011-08-03 Thread Gabriel Charette
My linemap implementation just caught a very important failure due to
this patch (because of it's massive use of pph_in_string for
filenames).

We CANNOT free stream->encoder.r.file_data this early as it contains
all of the strings streamed in (which are refered to directly from all
over the place (pointers passed back by lto_input_string).

We will probably need the strings in here until the end of the
compilation, so we could either just not free it (i.e. memory leak,
but allow important when program is over...)

Or we could strcpy the strings pph'ed in, but that involves
duplication of identical strings, unless we use a cache-like trick for
this.

Or we could put it in a side table that we free at the end of the
compilation (or whenever the strings are no longer needed, but I was
getting some seg faults deep down in the compilation because of this
memory issue).

On a positive note: with this fixed (I just commented out the free
line (pph-streamer.c:179) for now to try it), my linemap
implementation is now complete and makes c1eabi1.cc pass (and
p4eabi1's asm diff has changed, I'll look into that now).

Gab

On Fri, Jul 29, 2011 at 4:16 PM, Lawrence Crowl  wrote:
> I removed the build directories and rebuilt.  Everything worked.
> There are gremlins in the machine.
>
> On 7/29/11, Gabriel Charette  wrote:
>> I just stashed all my changes and pulled in the latest svn HEAD this
>> morning to check if I was seeing these failures:
>>
>> Repository Root: svn+ssh://gcc.gnu.org/svn/gcc
>> Repository UUID: 138bc75d-0d04-0410-961f-82ee72b054a4
>> Revision: 176906
>> Node Kind: directory
>> Schedule: normal
>> Last Changed Author: crowl
>> Last Changed Rev: 176906
>> Last Changed Date: 2011-07-28 16:18:55 -0700 (Thu, 28 Jul 2011)
>>
>> I did a successful build + pph check of both debug and opt builds
>> (incremental build only, I didn't actually need to start from scratch;
>> however I was stashing changes to some headers in libcpp, so
>> potentially that rebuilt somethings that weren't rebuilt in a smaller
>> incremental build if there is a missing dependency..?)
>>
>> Gab
>>
>> On Thu, Jul 28, 2011 at 10:01 PM, Diego Novillo  wrote:
>>> On Thu, Jul 28, 2011 at 16:30, Lawrence Crowl  wrote:
>>>> I'm getting massive failures after incorporating this change:
>>>>
>>>>   bytecode stream: trying to read 1735 bytes after the end of the
>>>>   input buffer
>>>>
>>>> where the number of bytes changes.  Suggestions?
>>>
>>> Odd.  I'm getting the usual results with:
>>>
>>> $ git svn info
>>> Path: .
>>> URL: svn+ssh://gcc.gnu.org/svn/gcc/branches/pph/gcc
>>> Repository Root: svn+ssh://gcc.gnu.org/svn/gcc
>>> Repository UUID: 138bc75d-0d04-0410-961f-82ee72b054a4
>>> Revision: 176671
>>> Node Kind: directory
>>> Schedule: normal
>>> Last Changed Author: gchare
>>> Last Changed Rev: 176671
>>> Last Changed Date: 2011-07-22 21:04:48 -0400 (Fri, 22 Jul 2011)
>>>
>>> Perhaps a file did not get rebuilt after you updated your tree?  That
>>> may point to a Makefile dependency bug.  Or maybe you have some local
>>> patch?
>>>
>>>
>>> Diego.
>>>
>>
>
>
> --
> Lawrence Crowl
>


[pph] Stream and merge line table. (issue4836050)

2011-08-04 Thread Gabriel Charette
IMPORTANT this patch goes on top of trunk patch issue4835047, which has yet to 
be approved (I included the change as part of this patch for pph for now).

We now stream out the line_table from the pph'ed header and merge it back in 
when compiling reading a pph.

All of the source_location's read from the pph are then applied an offset for 
them to match their expected source_location in the compiled file (except for 
builtins, we should not be streaming builtins, but as the FIXME comment in 
pph_write_location mentions, it appears we are; I will look at that in another 
patch).

This fixes the asm diff c1eabi1.cc and modifies the one in p4eabi1.cc (in the 
good compile the unique ID's go from $12, before this patch incorrectly from 
$185, and now incorrectly from $611). I will look into fixing this last asm 
diff, but I don't think it should hold this check-in.

Also, if we can omit the pph_trace or change the way the trace works, we could 
avoid calling pph_out/in_location only for it to call lto_input/output_location 
which calls back pph_read/write_location

Added lto streamer hooks to do this, but Cary (ccoutant) was saying he'd want 
it directly in lto.

Do we want to apply the changes to libcpp to trunk now or wait??

Tested with bootstrap and pph regression testing.

Gab

2011-08-04  Gabriel Charette  

* decl.c (finish_function): Remove line 0 hack.

* pph-streamer-in.c (pph_loc_offset): New global variable.
(pph_read_location): New.
(pph_in_linenum_type): New.
(pph_in_source_location): New.
(pph_in_line_map): New.
(pph_in_and_merge_line_table): New.
(pph_read_file_contents): Call pph_in_and_merge_line_table.
* pph-streamer-out.c (pph_write_location): New.
(pph_out_linenum_type): New.
(pph_out_source_location): New.
(pph_out_line_map): New.
(pph_out_line_table): New.
(pph_write_file_contents): Call pph_out_line_table.
* pph-streamer.c (pph_hooks_init): Init input_location
and output_location hooks.
* pph-streamer.h (PPH_NUM_IGNORED_LINE_TABLE_ENTRIES): Define.

* lto-streamer-in.c (lto_input_location): Handle input_location
streamer hook.
* lto-streamer-out.c (lto_output_location): Handle output_location
streamer hook.
* lto-streamer.h (streamer_hooks): Add input_location and
output_location hooks.

* include/line-map.h (LC_REASON_BIT): Define as CHAR_BIT.
(COLUMN_BITS_BIT): Define as 8.
(struct line_map): Use LC_REASON_BIT and COLUMN_BITS_BIT to represent
field specific bit requirements.
* line-map.c (linemap_ensure_extra_space_available): New.
(linemap_add): Call linemap_ensure_extra_space_available.
(linemap_line_start): Fixed missing space.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 3b312d3..8097cd3 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13232,22 +13232,13 @@ finish_function (int flags)
 {
   if (DECL_MAIN_P (current_function_decl))
{
- tree stmt;
-
  /* Make it so that `main' always returns 0 by default (or
 1 for VMS).  */
 #if VMS_TARGET
- stmt = finish_return_stmt (integer_one_node);
+ finish_return_stmt (integer_one_node);
 #else
- stmt = finish_return_stmt (integer_zero_node);
+ finish_return_stmt (integer_zero_node);
 #endif
- /* Hack.  We don't want the middle-end to warn that this
-return is unreachable, so put the statement on the
-special line 0.  */
- {
-   location_t linezero = linemap_line_start (line_table, 0, 1);
-   SET_EXPR_LOCATION (stmt, linezero);
- }
}
 
   if (use_eh_spec_block (current_function_decl))
diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index e57e1e7..6e2e79b 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -68,6 +68,10 @@ static VEC(char_p,heap) *string_tables = NULL;
   pph_register_shared_data (STREAM, ALT_DATA, IX); \
 } while (0)
 
+/* Set in pph_in_and_merge_line_table. Represents the source_location offset
+   which every streamed in token must add to it's serialized source_location. 
*/
+int pph_loc_offset;
+
 /* Callback for unpacking value fields in ASTs.  BP is the bitpack 
we are unpacking from.  EXPR is the tree to unpack.  */
 
@@ -238,6 +242,32 @@ pph_register_shared_data (pph_stream *stream, void *data, 
unsigned ix)
 }
 
 
+/* Callback for streamer_hooks.input_location.  An offset is applied to
+   the location_t read in according to the properties of the merged
+   line_table.  IB and DATA_IN are as in lto_input_location.  This function
+   should only be called after pph_in_and_merge_line_table was called as
+   we expect pph_loc_offset to be set.  */
+
+location_t
+pph_read_location (struct lto_input_block *ib,
+  

Re: [pph] Stream and merge line table. (issue4836050)

2011-08-05 Thread Gabriel Charette
[+ccoutant]

>> Added lto streamer hooks to do this, but Cary (ccoutant) was saying he'd
>> want it directly in lto.
>>
>> Do we want to apply the changes to libcpp to trunk now or wait??
>
> How urgent is the merge?  It wouldn't hurt to run a few more test
> cases.  I have some hidden in my client


Neither the merge to lto (Cary said he'd like that), nor the libcpp
merge to trunk are required (libcpp changes are trivial, just pulling
out some inline code into a function for re-use and defined some
constants to avoid "magic numbers" in the code, but there is not much
point for them without the pph code (i.e. they'll only be used once
each, where they were originally pulled out from)).

Gab
We can definitely keep it in pph for a little while until it's stable.


Re: [pph] Add initial support for including nested pph images (issue4847044)

2011-08-05 Thread Gabriel Charette
On Fri, Aug 5, 2011 at 9:42 AM, Diego Novillo  wrote:
> On Thu, Aug 4, 2011 at 17:47,   wrote:
>> So if I understand correctly, the reference system doesn't work yet, you
>> just put out the design in this patch and you'll fill up functionality
>> in an upcoming patch so that's it's clearer what you're adding?
>
> Right, the 'if (0)' in pph_in_includes() disables support for it.
>
>> http://codereview.appspot.com/4847044/diff/1/gcc/cp/pph-streamer-in.c
>> File gcc/cp/pph-streamer-in.c (right):
>>
>> http://codereview.appspot.com/4847044/diff/1/gcc/cp/pph-streamer-in.c#newcode1491
>> gcc/cp/pph-streamer-in.c:1491: pph_add_include (stream);
>> does this mean the included pph has the include information for all of
>> the headers in it's transitive closure? i.e. we don't need to load child
>> information of a child? if so, isn't this bad from a dependency point of
>> view?
>
> Hmm?  Each header knows what other images it includes, so before
> reading its own content it reads the contents from the others.  The
> dependencies don't change.  The parent will not have the physical
> representation of the ASTs from the children, just references to them.
>

What I mean is if you have the following include structure A.c -> B.h
-> C.h -> D.h

Would B.h hold references to both C.h and D.h or only to C which in
turn knows about D?

From what I understood it seemed like all of the children in the
transitive closure of B will be referenced in B and that B will not
need to look at references in C when we read it (which is great from
an I/O standpoint, but maybe not from a dependency point of view? just
trying to understand the design)


>> http://codereview.appspot.com/4847044/diff/1/gcc/cp/pph.c
>> File gcc/cp/pph.c (right):
>>
>> http://codereview.appspot.com/4847044/diff/1/gcc/cp/pph.c#newcode164
>> gcc/cp/pph.c:164: if (pph_out_file != NULL)
>> shouldn't you use your new pph_enabled_p function here?
>
> No.  I need to know whether we are *creating* a PPH image.  Perhaps I
> should add a different predicate.
>

Ah ok I see, ya perhaps another inline function could clarify..

>> http://codereview.appspot.com/4847044/diff/1/gcc/testsuite/g++.dg/pph/c1pr44948-1a.cc
>> File gcc/testsuite/g++.dg/pph/c1pr44948-1a.cc (right):
>>
>> http://codereview.appspot.com/4847044/diff/1/gcc/testsuite/g++.dg/pph/c1pr44948-1a.cc#newcode1
>> gcc/testsuite/g++.dg/pph/c1pr44948-1a.cc:1: /* { dg-options "-O
>> -Wno-psabi -mtune=generic" } */
>> Is this related to the rest of the changes in this patch? I don't see it
>> mentioned in your patch comments
>
> Gah.  I was going to commit this separately but forgot.  Sorry about that.
>
K, why does this fix the test? seems weird that we had an infinite
loop before and changing the flags gets rid of it?

Thanks,
Gab


Re: Remove line 0 hack in cp/decl.c (issue4835047)

2011-08-05 Thread Gabriel Charette
On Fri, Aug 5, 2011 at 10:37 AM, Tom Tromey  wrote:
>>>>>> "Gabriel" == Gabriel Charette  writes:
>
> Gabriel> This hack, has described in more details in the email labeled
> Gabriel> "Line 0 Hack??", was now causing problem when serializing the
> Gabriel> line_table in pph.
>
> I think you do have to handle location 0 somehow.
> This is UNKNOWN_LOCATION, referred to widely in the sources.
>

I do handle location 0, the problem is that this specific call to
linemap_line_start was made late, after all linemap entries had exited
(LC_LEAVE), and thus this would create a new LC_ENTER in the table and
the parsing would finish with line_table->depth == 1 (instead of 0 as
expected)... This bug never really showed up because at that point no
one is trying to add new entries to the line_table, it only shows up
now that we're trying to serialize the line_table.

> Gabriel> 2011-08-01  Gabriel Charette  
> Gabriel>        * decl.c (finish_function): Remove unecessary line 0 hack.
>
> Now that -Wunreachable-code is gone, I doubt this code is even
> theoretically relevant.  So, while I can't approve or reject this patch,
> it seems reasonable to me.
>

Ok Thanks,
Gabriel


Re: [pph] small multi-pph tests (issue4810074)

2011-08-05 Thread Gabriel Charette
I now get the following test failure output after pulling this patch
(potentially from the almost concurrent checkin of my linetable
patch?)

I can send you my diff's if you need to compare.

FAIL: g++.dg/pph/c4inline.cc  (assembly comparison, sums 46031=>36250)
FAIL: g++.dg/pph/x1keyed.cc  (assembly comparison, sums 17458=>63070)
FAIL: g++.dg/pph/x1keyno.cc  (assembly comparison, sums 20949=>46318)
XPASS: g++.dg/pph/x4keyed.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
XPASS: g++.dg/pph/x4keyed.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
FAIL: g++.dg/pph/x4keyno.cc  (assembly comparison, sums 64958=>17472)
FAIL: g++.dg/pph/x4template.cc  (assembly comparison, sums 23306=>52012)
XPASS: g++.dg/pph/x6rtti.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
XPASS: g++.dg/pph/x6rtti.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
messages, line )
# of expected passes277
# of unexpected failures5
# of unexpected successes   45
# of expected failures  42

Gab

On Fri, Aug 5, 2011 at 11:15 AM, Lawrence Crowl  wrote:
> This patch ads a bunch of small tests for multi-pph includes.
>
> Tested on x64.
>
>
> Index: gcc/testsuite/ChangeLog.pph
>
> 2011-08-04  Lawrence Crowl  
>
>        * g++.dg/pph/README: Add new file types.
>        * g++.dg/pph/a0expinstinl.h: New.
>        * g++.dg/pph/a0expinstnin.h: New.
>        * g++.dg/pph/a0inline.h: New.
>        * g++.dg/pph/a0keyed.h: New.
>        * g++.dg/pph/a0keyno.h: New.
>        * g++.dg/pph/a0noninline.h: New.
>        * g++.dg/pph/a0nontrivinit.h: New.
>        * g++.dg/pph/a0rawstruct.h: New.
>        * g++.dg/pph/a0rtti.h: New.
>        * g++.dg/pph/a0template.h: New.
>        * g++.dg/pph/a0tmplclass.h: New.
>        * g++.dg/pph/a0typedef.h: New.
>        * g++.dg/pph/a0variables1.h: New.
>        * g++.dg/pph/a0variables2.h: New.
>        * g++.dg/pph/c0inline1.h: New.
>        * g++.dg/pph/c0inline2.h: New.
>        * g++.dg/pph/c0rawstruct1.h: New.
>        * g++.dg/pph/c0rawstruct2.h: New.
>        * g++.dg/pph/c0typedef1.h: New.
>        * g++.dg/pph/c0typedef2.h: New.
>        * g++.dg/pph/c0variables.h: Contents to a0variables.h.
>        Renamed to c0variables1.h.
>        * g++.dg/pph/c0variables1.h: New.
>        * g++.dg/pph/c0variables2.h: New.
>        * g++.dg/pph/c0variables3.h: New.
>        * g++.dg/pph/c0variables4.h: New.
>        * g++.dg/pph/c1variables.cc: Handle renaming.
>        * g++.dg/pph/c3rawstruct.cc: New.
>        * g++.dg/pph/c3rawstruct.s: New.
>        * g++.dg/pph/c3typedef.cc: New.
>        * g++.dg/pph/c3variables.cc: New.
>        * g++.dg/pph/c4inline.cc: New.
>        * g++.dg/pph/e0noninline1.h: New.
>        * g++.dg/pph/e0noninline2.h: New.
>        * g++.dg/pph/e4noninline.cc: New.
>        * g++.dg/pph/e4variables.cc: New.
>        * g++.dg/pph/pph.exp: Add FIXME.
>        * g++.dg/pph/x0keyed1.h: New.
>        * g++.dg/pph/x0keyed2.h: New.
>        * g++.dg/pph/x0keyno1.h: New.
>        * g++.dg/pph/x0keyno2.h: New.
>        * g++.dg/pph/x0nontrivinit.h: Contents to a0nontrivinit.h.
>        Renamed to x0nontrivinit1.h.
>        * g++.dg/pph/x0nontrivinit1.h: Renamed from x0nontrivinit.h.
>        * g++.dg/pph/x0nontrivinit2.h: New.
>        * g++.dg/pph/x0template.h: Contents to a0template.h.
>        Renamed to x0template1.h.
>        * g++.dg/pph/x0template1.h: Renamed from x0template.
>        * g++.dg/pph/x0template2.h: New.
>        * g++.dg/pph/x0tmplclass.h: Contents to a0tmplclass.h.
>        Renamed to x0tmplclass1.h.
>        * g++.dg/pph/x0tmplclass1.h: Renamed from x0tmplclass.h.
>        * g++.dg/pph/x0tmplclass2.h: New.
>        * g++.dg/pph/x1keyed.cc: New.
>        * g++.dg/pph/x1keyno.cc: New.
>        * g++.dg/pph/x1nontrivinit.cc: Handle renaming.
>        * g++.dg/pph/x1template.cc: Handle renaming.
>        * g++.dg/pph/x1tmplclass.cc: Handle renaming.
>        * g++.dg/pph/x1variables.h: Handle renaming.
>        * g++.dg/pph/x4keyed.cc: New.
>        * g++.dg/pph/x4keyno.cc: New.
>        * g++.dg/pph/x4templ

[pph] Adding one hard and failing ordering test (issue4854042)

2011-08-05 Thread Gabriel Charette
This is the test I was talking would potentially fail with our current 
implementation.

And it does.

It has an assembly difference in the order of the global variables, like we 
used to have in simpler tests.

Gab

2011-08-05  Gabriel Charette  

* (x0hardorder1.h): New.
* (x3hardorder2.h): New.
* (x3hardorder.cc): New.

diff --git a/gcc/testsuite/g++.dg/pph/x0hardorder1.h 
b/gcc/testsuite/g++.dg/pph/x0hardorder1.h
new file mode 100644
index 000..bfb547e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pph/x0hardorder1.h
@@ -0,0 +1,13 @@
+#ifndef HARD_ORDER_1_H
+#define HARD_ORDER_1_H
+
+int a1 = 1;
+
+namespace N {
+int n1 = 1;
+int m1 = 2;
+}
+
+float b1 = 1.1;
+
+#endif
diff --git a/gcc/testsuite/g++.dg/pph/x3hardorder.cc 
b/gcc/testsuite/g++.dg/pph/x3hardorder.cc
new file mode 100644
index 000..8f62539
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pph/x3hardorder.cc
@@ -0,0 +1,8 @@
+//pph asm xdiff 28345
+//Ordering of globals is different
+
+#include "x3hardorder2.h"
+
+int test () {
+  return a1 + a2 - b1 + b2 * N::n1 + N::n2 - N::m1 + N::m2;
+}
diff --git a/gcc/testsuite/g++.dg/pph/x3hardorder2.h 
b/gcc/testsuite/g++.dg/pph/x3hardorder2.h
new file mode 100644
index 000..d534ae4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pph/x3hardorder2.h
@@ -0,0 +1,18 @@
+#ifndef HARD_ORDER_2_H
+#define HARD_ORDER_2_H
+
+int a2 = 2;
+
+namespace N {
+int n2 = 3;
+}
+
+#include "x0hardorder1.h"
+
+float b2 = 2.2;
+
+namespace N {
+int m2 = 3;
+}
+
+#endif

--
This patch is available for review at http://codereview.appspot.com/4854042


Re: [pph] Add initial support for including nested pph images (issue4847044)

2011-08-09 Thread Gabriel Charette
>>> Gah.  I was going to commit this separately but forgot.  Sorry about that.
>>>
>> K, why does this fix the test? seems weird that we had an infinite
>> loop before and changing the flags gets rid of it?
>
> It wasn't an infinite loop but an ICE in the tree caches.  The
> different options were producing different ASTs, so the tree cache had
> different trees on write-out and read-in.
>

Ah ok I see, this is actually the test I was aiming at fixing next, nice.

I remember we were discussing it was the build system's job to ensure
flags matched. In this case however it's much worse then the asm diff
we were getting before in the c1builtin-integral test when using
different flags, which was fine as the assembly was still valid and
was just adapting to the behavior wanted by the user.

An ICE in lto_streamer_cache_get is not very intuitive to point out
the problem to the user in this case imo

I'm thinking we should at least warn when some flags like this one
differ and when that difference has an impact on the internal
representation and can produce ICEs.

Gab


[pph] Version 2: Clear test commit conflicts (issue4844060)

2011-08-10 Thread Gabriel Charette
Here is what it takes, on top of Lawrence's first patch, to clear new test 
errors on my end.

Not sure what fixed the common removal of
// { dg-bogus "unistd.h:1144:34: error: declaration of .* ctermid.* has a 
different exception specifier" "" { xfail *-*-* } 0 }
// { dg-bogus "stdio.h:858:14: error: from previous declaration .* ctermid.*" 
"" { xfail *-*-* } 0 }
maybe the trunk merge??

Seems like x6dynarray6 now has the same errors x6dynarray5 already had, don't 
know why this only shows up now...?

Also, since the trunk merge, `make check-c++ RUNTESTFLAGS=pph.exp` ran from 
bld/ now also runs c++0x tests it seems.
Diego said we don't care about those yet, so I changed my test run to be `make 
check-g++ RUNTESTFLAGS=pph.exp` ran from bld/gcc/

Gab

2011-08-10  Gabriel Charette  

* g++.dg/pph/x5dynarray7.h: Remove 2 bogus errors.
* g++.dg/pph/x6dynarray6.h: Remove 2 bogus errors.
Add 2 bogus errors.
* g++.dg/pph/x7dynarray5.cc: Remove 2 bogus errors.
* g++.dg/pph/x7dynarray6.cc: Remove 2 bogus errors.
* g++.dg/pph/x7dynarray7.cc: Remove 2 bogus errors.

diff --git a/gcc/testsuite/g++.dg/pph/x5dynarray7.h 
b/gcc/testsuite/g++.dg/pph/x5dynarray7.h
index 7aae396..5ee5d8c 100644
--- a/gcc/testsuite/g++.dg/pph/x5dynarray7.h
+++ b/gcc/testsuite/g++.dg/pph/x5dynarray7.h
@@ -1,7 +1,5 @@
 // { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
 // { dg-bogus "wchar.h:1:0: error: PPH file stdio.pph fails macro validation, 
_WCHAR_H" "" { xfail *-*-* } 0 }
-// { dg-bogus "unistd.h:1144:34: error: declaration of .* ctermid.* has a 
different exception specifier" "" { xfail *-*-* } 0 }
-// { dg-bogus "stdio.h:858:14: error: from previous declaration .* ctermid.*" 
"" { xfail *-*-* } 0 }
 
 #ifndef X5DYNARRAY7_H
 #define X5DYNARRAY7_H
diff --git a/gcc/testsuite/g++.dg/pph/x6dynarray6.h 
b/gcc/testsuite/g++.dg/pph/x6dynarray6.h
index a8e48c1..497eb46 100644
--- a/gcc/testsuite/g++.dg/pph/x6dynarray6.h
+++ b/gcc/testsuite/g++.dg/pph/x6dynarray6.h
@@ -1,7 +1,7 @@
 // { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
 // { dg-bogus "wchar.h:1:0: error: PPH file stdio.pph fails macro validation, 
_WCHAR_H" "" { xfail *-*-* } 0 }
-// { dg-bogus "unistd.h:1144:34: error: declaration of .* ctermid.* has a 
different exception specifier" "" { xfail *-*-* } 0 }
-// { dg-bogus "stdio.h:858:14: error: from previous declaration .* ctermid.*" 
"" { xfail *-*-* } 0 }
+// { dg-bogus "a0dynarray-dfn1b.hi:3:19: error: there are no arguments to 
.alloc. that depend on a template parameter, so a declaration of .alloc. must 
be available" "" { xfail *-*-* } 0 }
+// { dg-bogus "a0dynarray-dfn3c.hi:2:36: error: no .void 
tst::dynarray::check.tst::dynarray::size_type.. member function declared 
in class .tst::dynarray." "" { xfail *-*-* } 0 }
 
 #ifndef X6DYNARRAY6_H
 #define X6DYNARRAY6_H
diff --git a/gcc/testsuite/g++.dg/pph/x7dynarray5.cc 
b/gcc/testsuite/g++.dg/pph/x7dynarray5.cc
index f512bad..d7b17a3 100644
--- a/gcc/testsuite/g++.dg/pph/x7dynarray5.cc
+++ b/gcc/testsuite/g++.dg/pph/x7dynarray5.cc
@@ -1,7 +1,5 @@
 // { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
 // { dg-bogus "wchar.h:1:0: error: PPH file stdio.pph fails macro validation, 
_WCHAR_H" "" { xfail *-*-* } 0 }
-// { dg-bogus "unistd.h:1144:34: error: declaration of .* ctermid.* has a 
different exception specifier" "" { xfail *-*-* } 0 }
-// { dg-bogus "stdio.h:858:14: error: from previous declaration .* ctermid.*" 
"" { xfail *-*-* } 0 }
 
 #include "x0dynarray4.h"
 #include "x6dynarray5.h"
diff --git a/gcc/testsuite/g++.dg/pph/x7dynarray6.cc 
b/gcc/testsuite/g++.dg/pph/x7dynarray6.cc
index 1585be0..0292890 100644
--- a/gcc/testsuite/g++.dg/pph/x7dynarray6.cc
+++ b/gcc/testsuite/g++.dg/pph/x7dynarray6.cc
@@ -1,7 +1,5 @@
 // { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
 // { dg-bogus "wchar.h:1:0: error: PPH file stdio.pph fails macro validation, 
_WCHAR_H" "" { xfail *-*-* } 0 }
-// { dg-bogus "unistd.h:1144:34: error: declaration of .* ctermid.* has a 
different exception specifier" "" { xfail *-*-* } 0 }
-// { dg-bogus "stdio.h:858:14: error: from previous declaration .* ctermid.*" 
"" { xfail *-*-* } 0 }
 
 #include 
 #include 
diff --git a/gcc/testsuite/g++.dg/pph/x7dynarray7.cc 
b/gcc/testsuite/g++.dg/pph/x7dynarray7.cc
index bf0a047..08398be 100644
--- a/gcc/testsuite/g++.dg/pph/x7dynarray7.cc
+++ b/gcc/testsuite/g++.dg/pph/x7dynarray7.cc
@@ -1,7 +1,5 @@
 // { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
 // { dg-bogus "wchar.h:1:0: error: PPH file stdio.pph fails macro validation, 
_WCHAR_H" "" { xfail *-*-* } 0 }
-// { dg-bogus "unistd.h:1144:34: error: declaration of .* ctermid.* has a 
different exception specifier" "" { xfail *-*-* } 0 }
-// { dg-bogus "stdio.h:858:14: error: from previous declaration .* ctermid.*" 
"" { xfail *-*-* } 0 }
 
 #include 
 #include 

--
This patch is available for review at http://codereview.appspot.com/4844060


Re: [pph] small multi-pph tests (issue4810074)

2011-08-10 Thread Gabriel Charette
It didn't fix everything.

Potentially another commit conflict with Diego's trunk merge from yesterday?

I just sent out another patch that fixes everything that was left on
my end. Let me know if it works on your end.

Cheers,
Gab

On Tue, Aug 9, 2011 at 7:26 PM, Lawrence Crowl  wrote:
> Let me know if my recent push has not solved this problem.
>
> On 8/5/11, Gabriel Charette  wrote:
>> I now get the following test failure output after pulling this patch
>> (potentially from the almost concurrent checkin of my linetable
>> patch?)
>>
>> I can send you my diff's if you need to compare.
>>
>> FAIL: g++.dg/pph/c4inline.cc  (assembly comparison, sums 46031=>36250)
>> FAIL: g++.dg/pph/x1keyed.cc  (assembly comparison, sums 17458=>63070)
>> FAIL: g++.dg/pph/x1keyno.cc  (assembly comparison, sums 20949=>46318)
>> XPASS: g++.dg/pph/x4keyed.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> XPASS: g++.dg/pph/x4keyed.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> FAIL: g++.dg/pph/x4keyno.cc  (assembly comparison, sums 64958=>17472)
>> FAIL: g++.dg/pph/x4template.cc  (assembly comparison, sums 23306=>52012)
>> XPASS: g++.dg/pph/x6rtti.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> XPASS: g++.dg/pph/x6rtti.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> XPASS: g++.dg/pph/x7rtti.cc  -fpph-map=pph.map -I.  (test for bogus
>> messages, line )
>> # of expected passes          277
>> # of unexpected failures      5
>> # of unexpected successes     45
>> # of expected failures                42
>>
>> Gab
>>
>> On Fri, Aug 5, 2011 at 11:15 AM, Lawrence Crowl  wrote:
>>> This patch ads a bunch of small tests for multi-pph includes.
>>>
>>> Tested on x64.
>>>
>>>
>>> Index: gcc/testsuite/ChangeLog.pph
>>>
>>> 2011-08-04  Lawrence Crowl  
>>>
>>>        * g++.dg/pph/README: Add new file types.
>>>        * g++.dg/pph/a0expinstinl.h: New.
>>>        * g++.dg/pph/a0expinstnin.h: New.
>>>        * g++.dg/pph/a0inline.h: New.
>>>        * g++.dg/pph/a0keyed.h: New.
>>>        * g++.dg/pph/a0keyno.h: New.
>>>        * g++.dg/pph/a0noninline.h: New.
>>>        * g++.dg/pph/a0nontrivinit.h: New.
>>>        * g++.dg/pph/a0rawstruct.h: New.
>>>        * g++.dg/pph/a0rtti.h: New.
>>>        * g++.dg/pph/a0template.h: New.
>>>        * g++.dg/pph/a0tmplclass.h: New.
>>>        * g++.dg/pph/a0typedef.h: New.
>>>        * g++.dg/pph/a0variables1.h: New.
>>>        * g++.dg/pph/a0variables2.h: New.
>>>        * g++.dg/pph/c0inline1.h: New.
>>>        * g++.dg/pph/c0inline2.h: New.
>>>        * g++.dg/pph/c0rawstruct1.h: New.
>>>        * g++.dg/pph/c0rawstruct2.h: New.
>>>        * g++.dg/pph/c0typedef1.h: New.
>>>        * g++.dg/pph/c0typedef2.h: New.
>>>        * g++.dg/pph/c0variables.h: Contents to a0variables.h.
>>>        Renamed to c0variables1.h.
>>>        * g++.dg/pph/c0variables1.h: New.
>>>        * g++.dg/pph/c0variables2.h: New.
>>>        * g++.dg/pph/c0variables3.h: New.
>>>        * g++.dg/pph/c0variables4.h: New.
>>>        * g++.dg/pph/c1variables.cc: Handle renaming.
>>>        * g++.dg/pph/c3rawstruct.cc: New.
>>>        * g++.dg/pph/c3rawstruct.s: New.
>>>        * g++.dg/pph/c3typedef.cc: New.
>>>        * g++.dg/pph/c3variables.cc: New.
>>>        * g++.dg/pph/c4inline.cc: New.
>>>        * g++.dg/pph/e0noninline1.h: New.
>>>   

Linemap force location and remove LINEMAP_POSITION_FOR_COLUMN (issue4801090)

2011-08-10 Thread Gabriel Charette
There was a bug where c_finish_options would create some builtins and assign 
them source_locations in the linemap other than BUILTINS_LOCATION == 1.

Thus, when calling DECL_IS_BUILTIN to know if a decl is a builtin, some of them 
would return false as they had a source_location other than BUILTINS_LOCATION 
within the line_map entry that was incorrectly created in c_finish_options.

The problem to fix this is that _cpp_lex_direct just gets the location of the 
currently lexed token by calling linemap_position_for_column. It has no notion 
of whether this token is a builtin or whatever else it may be.

My solution is to add a forced_location field to the line_table which when set 
is returned by default by linemap_position_for_column instead of getting a new 
loc from the line_table.

Furthermore, this mechanism will allow us to inject locations for a similar 
problem we have in pph when lexing replayed pre-processor definitions (which as 
it is now are getting assigned new source_locations which is creating problems 
for us).

I'm open to other solutions if anyone sees another way to do it. We could also 
leave linemap_position_for_column as is and have a separate inline function, 
say linemap_pos_for_col_or_forced, which makes the forced_location check and 
simply calls linemap_position_for_column when no forced_location.

I also removed LINEMAP_POSITION_FOR_COLUMN, it did the EXACT same thing as 
linemap_position_for_column, so maintaining both in parallel seems like 
overkill to me. The only thing I can think of is that it's more optimal as it's 
inlined (but if that's really needed we can always make 
linemap_position_for_column an inline function).

Gabriel

2011-08-10  Gabriel Charette  

* c-opts.c (c_finish_options): Don't create built-in line_table entry;
instead force BUILTINS_LOCATION when creating builtins.

* include/line-map.h (struct line_maps): Add field forced_location.
(LINEMAP_POSITION_FOR_COLUMN): Remove.
* line-map.c (linemap_init): Init forced_location to 0.
(linemap_position_for_column): Return forced_location by default if set

diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 3227f7b..1af8e7b 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -1306,13 +1306,15 @@ c_finish_options (void)
 {
   size_t i;
 
-  cb_file_change (parse_in,
- linemap_add (line_table, LC_RENAME, 0,
-  _(""), 0));
+  /* Make sure all of the builtins about to be declared have
+ BUILTINS_LOCATION has their source_location.  */
+  line_table->forced_location = BUILTINS_LOCATION;
 
   cpp_init_builtins (parse_in, flag_hosted);
   c_cpp_builtins (parse_in);
 
+  line_table->forced_location = 0;
+
   /* We're about to send user input to cpplib, so make it warn for
 things that we previously (when we sent it internal definitions)
 told it to not warn.
diff --git a/gcc/go/gofrontend/lex.cc b/gcc/go/gofrontend/lex.cc
index 9f26911..167c7dd 100644
--- a/gcc/go/gofrontend/lex.cc
+++ b/gcc/go/gofrontend/lex.cc
@@ -518,9 +518,7 @@ Lex::require_line()
 source_location
 Lex::location() const
 {
-  source_location location;
-  LINEMAP_POSITION_FOR_COLUMN(location, line_table, this->lineoff_ + 1);
-  return location;
+  return linemap_position_for_column (line_table, this->lineoff_ + 1);
 }
 
 // Get a location slightly before the current one.  This is used for
@@ -529,9 +527,7 @@ Lex::location() const
 source_location
 Lex::earlier_location(int chars) const
 {
-  source_location location;
-  LINEMAP_POSITION_FOR_COLUMN(location, line_table, this->lineoff_ + 1 - 
chars);
-  return location;
+  return linemap_position_for_column (line_table, this->lineoff_ + 1 - chars);
 }
 
 // Get the next token.
diff --git a/libcpp/directives-only.c b/libcpp/directives-only.c
index e19f806..c6772af 100644
--- a/libcpp/directives-only.c
+++ b/libcpp/directives-only.c
@@ -142,7 +142,7 @@ _cpp_preprocess_dir_only (cpp_reader *pfile,
flags |= DO_LINE_COMMENT;
  else if (!(flags & DO_SPECIAL))
/* Mark the position for possible error reporting. */
-   LINEMAP_POSITION_FOR_COLUMN (loc, pfile->line_table, col);
+   loc = linemap_position_for_column (pfile->line_table, col);
 
  break;
 
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index f1d5bee..d14528e 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -95,6 +95,11 @@ struct GTY(()) line_maps {
   /* If non-null, the allocator to use when resizing 'maps'.  If null,
  xrealloc is used.  */
   line_map_realloc reallocator;
+
+  /* If non-zero, linemap_position_for_column automatically returns
+ the value stored at this memory location, instead of caclulating
+ a new source_location.  */
+  source_location forced_locati

Re: Linemap force location and remove LINEMAP_POSITION_FOR_COLUMN (issue4801090)

2011-08-10 Thread Gabriel Charette
Tested with bootstrap and full regression testing on x64.

On Wed, Aug 10, 2011 at 11:22 AM, Gabriel Charette  wrote:
> There was a bug where c_finish_options would create some builtins and assign 
> them source_locations in the linemap other than BUILTINS_LOCATION == 1.
>
> Thus, when calling DECL_IS_BUILTIN to know if a decl is a builtin, some of 
> them would return false as they had a source_location other than 
> BUILTINS_LOCATION within the line_map entry that was incorrectly created in 
> c_finish_options.
>
> The problem to fix this is that _cpp_lex_direct just gets the location of the 
> currently lexed token by calling linemap_position_for_column. It has no 
> notion of whether this token is a builtin or whatever else it may be.
>
> My solution is to add a forced_location field to the line_table which when 
> set is returned by default by linemap_position_for_column instead of getting 
> a new loc from the line_table.
>
> Furthermore, this mechanism will allow us to inject locations for a similar 
> problem we have in pph when lexing replayed pre-processor definitions (which 
> as it is now are getting assigned new source_locations which is creating 
> problems for us).
>
> I'm open to other solutions if anyone sees another way to do it. We could 
> also leave linemap_position_for_column as is and have a separate inline 
> function, say linemap_pos_for_col_or_forced, which makes the forced_location 
> check and simply calls linemap_position_for_column when no forced_location.
>
> I also removed LINEMAP_POSITION_FOR_COLUMN, it did the EXACT same thing as 
> linemap_position_for_column, so maintaining both in parallel seems like 
> overkill to me. The only thing I can think of is that it's more optimal as 
> it's inlined (but if that's really needed we can always make 
> linemap_position_for_column an inline function).
>
> Gabriel
>
> 2011-08-10  Gabriel Charette  
>
>        * c-opts.c (c_finish_options): Don't create built-in line_table entry;
>        instead force BUILTINS_LOCATION when creating builtins.
>
>        * include/line-map.h (struct line_maps): Add field forced_location.
>        (LINEMAP_POSITION_FOR_COLUMN): Remove.
>        * line-map.c (linemap_init): Init forced_location to 0.
>        (linemap_position_for_column): Return forced_location by default if set
>
> diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
> index 3227f7b..1af8e7b 100644
> --- a/gcc/c-family/c-opts.c
> +++ b/gcc/c-family/c-opts.c
> @@ -1306,13 +1306,15 @@ c_finish_options (void)
>     {
>       size_t i;
>
> -      cb_file_change (parse_in,
> -                     linemap_add (line_table, LC_RENAME, 0,
> -                                  _(""), 0));
> +      /* Make sure all of the builtins about to be declared have
> +         BUILTINS_LOCATION has their source_location.  */
> +      line_table->forced_location = BUILTINS_LOCATION;
>
>       cpp_init_builtins (parse_in, flag_hosted);
>       c_cpp_builtins (parse_in);
>
> +      line_table->forced_location = 0;
> +
>       /* We're about to send user input to cpplib, so make it warn for
>         things that we previously (when we sent it internal definitions)
>         told it to not warn.
> diff --git a/gcc/go/gofrontend/lex.cc b/gcc/go/gofrontend/lex.cc
> index 9f26911..167c7dd 100644
> --- a/gcc/go/gofrontend/lex.cc
> +++ b/gcc/go/gofrontend/lex.cc
> @@ -518,9 +518,7 @@ Lex::require_line()
>  source_location
>  Lex::location() const
>  {
> -  source_location location;
> -  LINEMAP_POSITION_FOR_COLUMN(location, line_table, this->lineoff_ + 1);
> -  return location;
> +  return linemap_position_for_column (line_table, this->lineoff_ + 1);
>  }
>
>  // Get a location slightly before the current one.  This is used for
> @@ -529,9 +527,7 @@ Lex::location() const
>  source_location
>  Lex::earlier_location(int chars) const
>  {
> -  source_location location;
> -  LINEMAP_POSITION_FOR_COLUMN(location, line_table, this->lineoff_ + 1 - 
> chars);
> -  return location;
> +  return linemap_position_for_column (line_table, this->lineoff_ + 1 - 
> chars);
>  }
>
>  // Get the next token.
> diff --git a/libcpp/directives-only.c b/libcpp/directives-only.c
> index e19f806..c6772af 100644
> --- a/libcpp/directives-only.c
> +++ b/libcpp/directives-only.c
> @@ -142,7 +142,7 @@ _cpp_preprocess_dir_only (cpp_reader *pfile,
>            flags |= DO_LINE_COMMENT;
>          else if (!(flags & DO_SPECIAL))
>            /* Mark the position for possible error reporting. */
> -           LINEMAP_POSITION_FOR_COLUMN (loc, pfile->line_table, col);
> +           loc = linemap_p

Re: Linemap force location and remove LINEMAP_POSITION_FOR_COLUMN (issue4801090)

2011-08-11 Thread Gabriel Charette
On Thu, Aug 11, 2011 at 7:22 AM, Dodji Seketeli  wrote:
> Hello,
>
> gch...@google.com (Gabriel Charette) a écrit:
>
>> diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
>> index 3227f7b..1af8e7b 100644
>> --- a/gcc/c-family/c-opts.c
>> +++ b/gcc/c-family/c-opts.c
>> @@ -1306,13 +1306,15 @@ c_finish_options (void)
>>      {
>>        size_t i;
>>
>> -      cb_file_change (parse_in,
>> -                   linemap_add (line_table, LC_RENAME, 0,
>> -                                _(""), 0));
>> +      /* Make sure all of the builtins about to be declared have
>> +         BUILTINS_LOCATION has their source_location.  */
>> +      line_table->forced_location = BUILTINS_LOCATION;
>>
>>        cpp_init_builtins (parse_in, flag_hosted);
>>        c_cpp_builtins (parse_in);
>>
>> +      line_table->forced_location = 0;
>> +
>
> FWIW, Since libcpp already knows about the concept of a builtin macro,
> maybe we could add a "builtin_location" member to cpp_reader, as well as
> "builtin_location" parameter to cpp_init_builtins.  cpp_init_builtin
> would then set pfile->builtin_location and _cpp_define_builtin would
> then make sure the builtins have that builtin_location.
>
> That way, each FE would just have to call
>
>    cpp_init_builtins (parse_i, flasg_hosted, BUILTIN_LOCATION);
>
> for their builtin macros have the proper location.  And the semantics
> would be clearer than what we'd get by setting a "magical"
> line_table->forced_location at that point.
>
> Just my 2 euro cents (that aren't worth much these days)
>

That could work given _cpp_lex_direct does receive a cpp_reader as a
parameter. We would need to add logic in _cpp_lex_direct to support
this new field.

As I mentioned, we have the same problem in pph where we need to force
a location (i.e. the lexer is assigning new locations, but we don't
want it to when we are replaying pre-processor tokens), so just a
"builtin_location" field is potentially insufficient.

Either way, a "magic" field in cpp_reader  handled with logic in
_cpp_lex_direct, or a "magic" field in line_table handled in
linemap_position_for_column.

I agree that the field in cpp_reader might be clearer as the logic is
handled in _cpp_lex_direct, where we want the change to occur, not in
some dark corner of libcpp (linemap_position_for_column).

Gabriel


Re: Linemap force location and remove LINEMAP_POSITION_FOR_COLUMN (issue4801090)

2011-08-11 Thread Gabriel Charette
On Thu, Aug 11, 2011 at 12:27 AM, Richard Guenther
 wrote:
> On Wed, Aug 10, 2011 at 8:22 PM, Gabriel Charette  wrote:
>> There was a bug where c_finish_options would create some builtins and assign 
>> them source_locations in the linemap other than BUILTINS_LOCATION == 1.
>>
>> Thus, when calling DECL_IS_BUILTIN to know if a decl is a builtin, some of 
>> them would return false as they had a source_location other than 
>> BUILTINS_LOCATION within the line_map entry that was incorrectly created in 
>> c_finish_options.
>
> DECL_IS_BUILTIN is almost never the appropriate thing to use, instead
> you should use DECL_BUILT_IN (and grepping, I see some suspicious uses
> ...).

Why don't all builtins have BUILTINS_LOCATION as their location? It
doesn't make sense to me that we need to create a line_table entry for
builtins as they don't have line/col information.

Gabriel


Re: Linemap force location and remove LINEMAP_POSITION_FOR_COLUMN (issue4801090)

2011-08-11 Thread Gabriel Charette
On Thu, Aug 11, 2011 at 10:14 AM, Richard Guenther
 wrote:
> On Thu, Aug 11, 2011 at 6:54 PM, Gabriel Charette  wrote:
>> On Thu, Aug 11, 2011 at 12:27 AM, Richard Guenther
>>  wrote:
>>> On Wed, Aug 10, 2011 at 8:22 PM, Gabriel Charette  wrote:
>>>> There was a bug where c_finish_options would create some builtins and 
>>>> assign them source_locations in the linemap other than BUILTINS_LOCATION 
>>>> == 1.
>>>>
>>>> Thus, when calling DECL_IS_BUILTIN to know if a decl is a builtin, some of 
>>>> them would return false as they had a source_location other than 
>>>> BUILTINS_LOCATION within the line_map entry that was incorrectly created 
>>>> in c_finish_options.
>>>
>>> DECL_IS_BUILTIN is almost never the appropriate thing to use, instead
>>> you should use DECL_BUILT_IN (and grepping, I see some suspicious uses
>>> ...).
>>
>> Why don't all builtins have BUILTINS_LOCATION as their location? It
>> doesn't make sense to me that we need to create a line_table entry for
>> builtins as they don't have line/col information.
>
> Because we want the source location of the actual declaration if there was 
> any,
> like when including math.h.
>

Ah ok in this case I could see why a builtin would have a
source_location other than BUILTINS_LOCATION, but I don't think that
justifies having a  entry in the line_table (which was only
used by the builtins created in cpp_init_builtins which is what I'm
patching as I think those builtins should also have
BUILTINS_LOCATION).

The builtins created in math.h I would assume are associated with a
source_location in math.h, and that's OK I think (although this might
be harder for us to handle in pph, I don't think we want to change
this behavior in trunk, Diego?)

In pph we probably still want to serialize those builtins that are
instantiated from includes and not by default anyways. The only
builtins that are constant across every compilation from my
understanding are those which have BUILTINS_LOCATION has their
source_location (and the ones instantiated by cpp_init_builtins should
be part of this set I think).

Gabriel


Re: Linemap force location and remove LINEMAP_POSITION_FOR_COLUMN (issue4801090)

2011-08-11 Thread Gabriel Charette
On Thu, Aug 11, 2011 at 10:45 AM, Dodji Seketeli  wrote:
>> As I mentioned, we have the same problem in pph where we need to force
>> a location (i.e. the lexer is assigning new locations, but we don't
>> want it to when we are replaying pre-processor tokens), so just a
>> "builtin_location" field is potentially insufficient.
>
> I see.  So maybe a cpp_reader::forced_token_location, initialized to -1
> rather than 0 (in case someone wants to force a location to
> UNKNOWN_LOCATION, which is zero for the C/C++ FE at least).  There would
> then still be a new parm added to cpp_init_builtins, that would be the
> value of the location of the builtin macros to build.  cpp_init_builtins
> would then just set cpp_reader::force_token_location to that value.
>

Yes, I did think about using -1 to represent no-force. The problem is,
source_location is defined as unsigned int... So my solution was to
use a source_location* which when non-null means you want to force the
location to the referenced source_location. For some reason however
when I add a simple field `source_location *forced_location` to struct
line_maps I get the following compile error:

libcpp/include/line-map.h:99: field `(*x).forced_location' is pointer
to unimplemented type

Adding a source_location* to cpp_reader compiles fine however. This
must be a tricky corner of the C syntax I'm not aware of...?

Gabriel


Remove LINEMAP_POSITION_FOR_COLUMN macro (issue4874043)

2011-08-11 Thread Gabriel Charette
Removed LINEMAP_POSITION_FOR_COLUMN, it did the EXACT same thing as 
linemap_position_for_column, so maintaining both in parallel seems like 
overkill to me. The only thing I can think of is that it's more optimal as it's 
inlined (but if that's really needed we can always make 
linemap_position_for_column an inline function directly).

Tested with full boostrap and regression testing with all+go language 
configuration.

Ok for trunk?

Gabriel

2011-08-11  Gabriel Charette  

* include/line-map.h (LINEMAP_POSITION_FOR_COLUMN): Remove.
Update all users to use linemap_position_for_column instead.

diff --git a/gcc/go/gofrontend/lex.cc b/gcc/go/gofrontend/lex.cc
index 9f26911..167c7dd 100644
--- a/gcc/go/gofrontend/lex.cc
+++ b/gcc/go/gofrontend/lex.cc
@@ -518,9 +518,7 @@ Lex::require_line()
 source_location
 Lex::location() const
 {
-  source_location location;
-  LINEMAP_POSITION_FOR_COLUMN(location, line_table, this->lineoff_ + 1);
-  return location;
+  return linemap_position_for_column (line_table, this->lineoff_ + 1);
 }
 
 // Get a location slightly before the current one.  This is used for
@@ -529,9 +527,7 @@ Lex::location() const
 source_location
 Lex::earlier_location(int chars) const
 {
-  source_location location;
-  LINEMAP_POSITION_FOR_COLUMN(location, line_table, this->lineoff_ + 1 - 
chars);
-  return location;
+  return linemap_position_for_column (line_table, this->lineoff_ + 1 - chars);
 }
 
 // Get the next token.
diff --git a/libcpp/directives-only.c b/libcpp/directives-only.c
index e19f806..c6772af 100644
--- a/libcpp/directives-only.c
+++ b/libcpp/directives-only.c
@@ -142,7 +142,7 @@ _cpp_preprocess_dir_only (cpp_reader *pfile,
flags |= DO_LINE_COMMENT;
  else if (!(flags & DO_SPECIAL))
/* Mark the position for possible error reporting. */
-   LINEMAP_POSITION_FOR_COLUMN (loc, pfile->line_table, col);
+   loc = linemap_position_for_column (pfile->line_table, col);
 
  break;
 
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index f1d5bee..3c84035 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -165,23 +165,6 @@ extern const struct line_map *linemap_lookup
 /* Nonzero if the map is at the bottom of the include stack.  */
 #define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)
 
-/* Set LOC to a source position that is the same line as the most recent
-   linemap_line_start, but with the specified TO_COLUMN column number.  */
-
-#define LINEMAP_POSITION_FOR_COLUMN(LOC, SET, TO_COLUMN) do { \
-  unsigned int to_column = (TO_COLUMN); \
-  struct line_maps *set = (SET); \
-  if (__builtin_expect (to_column >= set->max_column_hint, 0)) \
-(LOC) = linemap_position_for_column (set, to_column); \
-  else { \
-source_location r = set->highest_line; \
-r = r + to_column; \
-if (r >= set->highest_location) \
-  set->highest_location = r; \
-(LOC) = r;  \
-  }} while (0)
-
-
 extern source_location
 linemap_position_for_column (struct line_maps *set, unsigned int to_column);
 
diff --git a/libcpp/lex.c b/libcpp/lex.c
index d29f36d..d460b98 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -1975,8 +1975,8 @@ _cpp_lex_direct (cpp_reader *pfile)
 }
   c = *buffer->cur++;
 
-  LINEMAP_POSITION_FOR_COLUMN (result->src_loc, pfile->line_table,
-  CPP_BUF_COLUMN (buffer, buffer->cur));
+  result->src_loc = linemap_position_for_column (pfile->line_table,
+   CPP_BUF_COLUMN 
(buffer, buffer->cur));
 
   switch (c)
 {

--
This patch is available for review at http://codereview.appspot.com/4874043


Re: Linemap force location and remove LINEMAP_POSITION_FOR_COLUMN (issue4801090)

2011-08-11 Thread Gabriel Charette
> I also removed LINEMAP_POSITION_FOR_COLUMN, it did the EXACT same thing as 
> linemap_position_for_column, so maintaining both in parallel seems like 
> overkill to me. The only thing I can think of is that it's more optimal as 
> it's inlined (but if that's really needed we can always make 
> linemap_position_for_column an inline function).
>

This section of the patch is somewhat independent and has not been
discussed in this thread, I pulled it out and submitted a separate
patch (issue4874043) while I'm working on making this patch force
location from cpp_reader.

Gabriel


Re: Remove LINEMAP_POSITION_FOR_COLUMN macro (issue4874043)

2011-08-15 Thread Gabriel Charette
[+iant]

Ian: can you approve the go changes in this patch?

It's a change in the linemap that reflects in functions used by go,
but that shouldn't have any effect on the go compiler's behaviour.

As a side thought, I'm getting random failures in the go test suite,
in my last run the difference was that
go.go-torture/execute/select-1.go failed in the clean build test and
passed in the patched build...

Every full test run I do I get different sets of differences, I've had
identical runs too, I highly doubt this is due to my patch.

On Fri, Aug 12, 2011 at 11:27 AM, Tom Tromey  wrote:
>>>>>> "Gabriel" == Gabriel Charette  writes:
>
> Gabriel> Removed LINEMAP_POSITION_FOR_COLUMN, it did the EXACT same
> Gabriel> thing as linemap_position_for_column, so maintaining both in
> Gabriel> parallel seems like overkill to me. The only thing I can think
> Gabriel> of is that it's more optimal as it's inlined (but if that's
> Gabriel> really needed we can always make linemap_position_for_column an
> Gabriel> inline function directly).
>
> I am sympathetic to this, but nobody is likely to do the performance
> tests post-patch.
>
> The libcpp parts are ok if it doesn't cause a noticeable slowdown in the
> GCC bootstrap.
>

I just did performance test and the results were identical before and after.

> I can't approve the changes outside of libcpp.
> Also, you didn't write a ChangeLog entry for those.
>

Here is the ChangeLog including gcc/go changes, added iant to get
approval for the go changes:

2011-08-11  Gabriel Charette  

libcpp/ChangeLog
* include/line-map.h (LINEMAP_POSITION_FOR_COLUMN): Remove.
Update all users to use linemap_position_for_column instead.

gcc/go/ChangeLog
* gofrontend/lex.cc (Lex::location): Update to use
linemap_position_for_column instead.
(Lex::earlier_location): Likewise.


Thanks,
Gabriel


Re: Remove LINEMAP_POSITION_FOR_COLUMN macro (issue4874043)

2011-08-15 Thread Gabriel Charette
On Mon, Aug 15, 2011 at 1:39 PM, Ian Lance Taylor  wrote:
> Gabriel Charette  writes:
>
>> Ian: can you approve the go changes in this patch?
>
> The changes to the Go frontend are fine, but they need to be applied to
> the master repository for the Go frontend.  I can take care of that when
> you are ready to commit the patch.  Note that changes to the files in
> gcc/go/gofrontend do not get ChangeLog entries.
>

The patch has been committed to trunk.

I did also provide a ChangeLog for the gcc/go/gofrontend change, want
me to remove it?

>
>> As a side thought, I'm getting random failures in the go test suite,
>> in my last run the difference was that
>> go.go-torture/execute/select-1.go failed in the clean build test and
>> passed in the patched build...
>>
>> Every full test run I do I get different sets of differences, I've had
>> identical runs too, I highly doubt this is due to my patch.
>
> I'm sure it has nothing to do with your patch.  I have not seen other
> people report this, though.  Some of the tests in the Go testsuite use a
> lot of threads, like thousands.  It's possible that that is running into
> some limit on your machine.  This would be particularly applicable if
> you are running the testsuite with make -j.
>

Ok (and yes I am using make -j)

Gabriel


[pph] Forwarding trunk linemap changes (issue4898050)

2011-08-15 Thread Gabriel Charette
Forwarding this patch to pph (which was just committed to trunk in 
issue4874043).

Committed to pph branch.

2011-08-11  Gabriel Charette  

libcpp/ChangeLog
* include/line-map.h (LINEMAP_POSITION_FOR_COLUMN): Remove.
Update all users to use linemap_position_for_column instead.

gcc/go/ChangeLog
* gofrontend/lex.cc (Lex::location): Update to use
linemap_position_for_column instead.
(Lex::earlier_location): Likewise.

diff --git a/gcc/go/gofrontend/lex.cc b/gcc/go/gofrontend/lex.cc
index 9f26911..167c7dd 100644
--- a/gcc/go/gofrontend/lex.cc
+++ b/gcc/go/gofrontend/lex.cc
@@ -518,9 +518,7 @@ Lex::require_line()
 source_location
 Lex::location() const
 {
-  source_location location;
-  LINEMAP_POSITION_FOR_COLUMN(location, line_table, this->lineoff_ + 1);
-  return location;
+  return linemap_position_for_column (line_table, this->lineoff_ + 1);
 }
 
 // Get a location slightly before the current one.  This is used for
@@ -529,9 +527,7 @@ Lex::location() const
 source_location
 Lex::earlier_location(int chars) const
 {
-  source_location location;
-  LINEMAP_POSITION_FOR_COLUMN(location, line_table, this->lineoff_ + 1 - 
chars);
-  return location;
+  return linemap_position_for_column (line_table, this->lineoff_ + 1 - chars);
 }
 
 // Get the next token.
diff --git a/libcpp/directives-only.c b/libcpp/directives-only.c
index e19f806..c6772af 100644
--- a/libcpp/directives-only.c
+++ b/libcpp/directives-only.c
@@ -142,7 +142,7 @@ _cpp_preprocess_dir_only (cpp_reader *pfile,
flags |= DO_LINE_COMMENT;
  else if (!(flags & DO_SPECIAL))
/* Mark the position for possible error reporting. */
-   LINEMAP_POSITION_FOR_COLUMN (loc, pfile->line_table, col);
+   loc = linemap_position_for_column (pfile->line_table, col);
 
  break;
 
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index f1d5bee..3c84035 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -165,23 +165,6 @@ extern const struct line_map *linemap_lookup
 /* Nonzero if the map is at the bottom of the include stack.  */
 #define MAIN_FILE_P(MAP) ((MAP)->included_from < 0)
 
-/* Set LOC to a source position that is the same line as the most recent
-   linemap_line_start, but with the specified TO_COLUMN column number.  */
-
-#define LINEMAP_POSITION_FOR_COLUMN(LOC, SET, TO_COLUMN) do { \
-  unsigned int to_column = (TO_COLUMN); \
-  struct line_maps *set = (SET); \
-  if (__builtin_expect (to_column >= set->max_column_hint, 0)) \
-(LOC) = linemap_position_for_column (set, to_column); \
-  else { \
-source_location r = set->highest_line; \
-r = r + to_column; \
-if (r >= set->highest_location) \
-  set->highest_location = r; \
-(LOC) = r;  \
-  }} while (0)
-
-
 extern source_location
 linemap_position_for_column (struct line_maps *set, unsigned int to_column);
 
diff --git a/libcpp/lex.c b/libcpp/lex.c
index d29f36d..d460b98 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -1975,8 +1975,8 @@ _cpp_lex_direct (cpp_reader *pfile)
 }
   c = *buffer->cur++;
 
-  LINEMAP_POSITION_FOR_COLUMN (result->src_loc, pfile->line_table,
-  CPP_BUF_COLUMN (buffer, buffer->cur));
+  result->src_loc = linemap_position_for_column (pfile->line_table,
+   CPP_BUF_COLUMN 
(buffer, buffer->cur));
 
   switch (c)
 {

--
This patch is available for review at http://codereview.appspot.com/4898050


Linemap force location and remove LINEMAP_POSITION_FOR_COLUMN (issue4801090)

2011-08-15 Thread Gabriel Charette
Here is the updated patch.

It nows exposes two libcpp functions to force the source_location for tokens 
when desired.

The lexer then checks for a value set by these functions in cpp_reader and acts 
accordingly when needing a location for a new token (either using the 
forced_location or calling the linemap as it used to).

It turns out the fortran library made the same mistake of creating a line_table 
entry for builtins, I fixed it as well in this patch.

Tested on x64 for c++,fortran.

(fyi: I moved the removal of LINEMAP_POSITION_FOR_COLUMN to a separate patch 
which is checked-in already; thus it doesn't show up in this updated patch 
obviously.
)

Ok for trunk?

Gabriel

2011-08-15  Gabriel Charette  

gcc/c-family/ChangeLog
* c-opts.c (c_finish_options): Force BUILTINS_LOCATION for tokens
defined in cpp_init_builtins and c_cpp_builtins.

gcc/fortran/ChangeLog
* cpp.c (gfc_cpp_init): Force BUILTINS_LOCATION for tokens
defined in cpp_define_builtins.

libcpp/ChangeLog
* init.c (cpp_create_reader): Inititalize forced_token_location_p.
* internal.h (struct cpp_reader): Add field forced_token_location_p.
* lex.c (_cpp_lex_direct): Use forced_token_location_p.
(cpp_force_token_locations): New.
(cpp_stop_forcing_token_locations): New.

diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 3227f7b..49ff80d 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -1306,12 +1306,17 @@ c_finish_options (void)
 {
   size_t i;
 
-  cb_file_change (parse_in,
- linemap_add (line_table, LC_RENAME, 0,
-  _(""), 0));
+  {
+   /* Make sure all of the builtins about to be declared have
+ BUILTINS_LOCATION has their source_location.  */
+   source_location builtins_loc = BUILTINS_LOCATION;
+   cpp_force_token_locations (parse_in, &builtins_loc);
 
-  cpp_init_builtins (parse_in, flag_hosted);
-  c_cpp_builtins (parse_in);
+   cpp_init_builtins (parse_in, flag_hosted);
+   c_cpp_builtins (parse_in);
+
+   cpp_stop_forcing_token_locations (parse_in);
+  }
 
   /* We're about to send user input to cpplib, so make it warn for
 things that we previously (when we sent it internal definitions)
diff --git a/gcc/fortran/cpp.c b/gcc/fortran/cpp.c
index a40442e..9368d89 100644
--- a/gcc/fortran/cpp.c
+++ b/gcc/fortran/cpp.c
@@ -565,9 +565,17 @@ gfc_cpp_init (void)
   if (gfc_option.flag_preprocessed)
 return;
 
-  cpp_change_file (cpp_in, LC_RENAME, _(""));
   if (!gfc_cpp_option.no_predefined)
-cpp_define_builtins (cpp_in);
+{
+  /* Make sure all of the builtins about to be declared have
+   BUILTINS_LOCATION has their source_location.  */
+  source_location builtins_loc = BUILTINS_LOCATION;
+  cpp_force_token_locations (cpp_in, &builtins_loc);
+
+  cpp_define_builtins (cpp_in);
+
+  cpp_stop_forcing_token_locations (cpp_in);
+}
 
   /* Handle deferred options from command-line.  */
   cpp_change_file (cpp_in, LC_RENAME, _(""));
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 55b0f1b..6ad0345 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -985,4 +985,8 @@ extern void cpp_prepare_state (cpp_reader *, struct 
save_macro_data **);
 extern int cpp_read_state (cpp_reader *, const char *, FILE *,
   struct save_macro_data *);
 
+/* In lex.c */
+extern void cpp_force_token_locations (cpp_reader *, source_location *);
+extern void cpp_stop_forcing_token_locations (cpp_reader *);
+
 #endif /* ! LIBCPP_CPPLIB_H */
diff --git a/libcpp/init.c b/libcpp/init.c
index 5ba..b3d4c8c 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -221,6 +221,9 @@ cpp_create_reader (enum c_lang lang, hash_table *table,
   /* Initialize table for push_macro/pop_macro.  */
   pfile->pushed_macros = 0;
 
+  /* Do not force token locations by default.  */
+  pfile->forced_token_location_p = NULL;
+
   /* The expression parser stack.  */
   _cpp_expand_op_stack (pfile);
 
diff --git a/libcpp/internal.h b/libcpp/internal.h
index d2872c4..6c423f0 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -499,6 +499,10 @@ struct cpp_reader
 
   /* List of saved macros by push_macro.  */
   struct def_pragma_macro *pushed_macros;
+
+  /* If non-null, the lexer will use this location for the next token
+ instead of getting a location from the linemap.  */
+  source_location *forced_token_location_p;
 };
 
 /* Character classes.  Based on the more primitive macros in safe-ctype.h.
diff --git a/libcpp/lex.c b/libcpp/lex.c
index d460b98..244b14d 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -1975,8 +1975,11 @@ _cpp_lex_direct (cpp_reader *pfile)
 }
   c = *buffer->cur++;
 
-  result->src_loc = linemap_position_for_column (pfile->line_table,
-  

Re: [pph] Support for references to symbols in other PPH images (issue4873051)

2011-08-16 Thread Gabriel Charette
I really like the way this is implemented! In particular having our
own cache is so great!

A few comments inline below.

Cheers,
Gab

On Mon, Aug 15, 2011 at 8:05 PM, Diego Novillo  wrote:
> This patch finishes the support for external references to symbols in
> other PPH files.
>
> This is used when one PPH image includes another.  The symbols in
> the included image should not be emitted from the parent, and references
> to them should go to the correct location in the child's pickle cache.
>
> The main change is the addition of two kinds of references.  We used
> to mark references to already pickled nodes with PPH_RECORD_SHARED.
> We now distinguish internal (PPH_RECORD_IREF) and external
> (PPH_RECORD_XREF) references.
>
> In the first variant, only one index is written as reference: the slot
> into the pickle cache.  In the second variant, two indices are
> written: an index into the include table specifying which child image
> contains the data, and an index into the child's pickle cache.
>
> When writing PPH images, we also need to make sure that we do not
> write any symbols in the file bindings that belong to included images.
> Otherwise, we will emit the same symbol twice.  This is implemented by
> a new filter PPHF_NO_XREFS, which is used when writing the current
> image's global bindings.
>
> Tested on x86_64.  Committed to branch.
>
>
> Diego.
>
>
> cp/ChangeLog.pph
>        * name-lookup.c (pph_out_binding_table): Call
>        pph_out_record_marker instead of pph_out_uchar.
>        (pph_in_binding_table): Call pph_in_record_marker instead of
>        pph_in_uchar.
>        * pph-streamer-in.c (pph_read_images): Declare.
>        (pph_is_reference_marker): New.  Update all previous users of
>        PPH_RECORD_SHARED.
>        (pph_in_start_record): Add argument INCLUDE_IX.  Update all
>        users.
>        Handle PPH_RECORD_XREF markers.
>        (pph_in_includes): After reading INCLUDE_NAME, call
>        pph_add_include.
>        (pph_read_file_contents): Move debugging output from ...
>        (pph_read_file): ... here.
>        Change it to return the opened stream.
>        Add STREAM to pph_read_images.
>        (pph_reader_finish): New.
>        (pph_read_file_1): Rename from pph_read_file_contents.  Update
>        all users.
>        * pph-streamer-out.c (pph_out_start_record): Re-write to
>        handle PPH_RECORD_IREF and PPH_RECORD_XREF.
>        (pph_write_file_contents): Embed ...
>        (pph_write_file): ... here.
>        (pph_add_include): Add new argument INCLUDE.  Update all
>        users.
>        (pph_writer_finish): Do nothing if pph_out_stream is NULL.
>        (pph_tree_matches): New.
>        (pph_out_tree_vec_filtered): New.
>        (pph_out_binding_level): Add new argument FILTER.  Update all users.
>        * pph-streamer.c (pph_stream_close_1): Embed ...
>        (pph_stream_close): ... here.
>        Do not traverse the list of includes.
>        (pph_cache_lookup): Factor out of ...
>        (pph_cache_add): ... here.
>        (pph_cache_lookup_in_includes): New.
>        (pph_cache_get): Add new argument INCLUDE_IX.  Update all users.
>        * pph-streamer.h (enum pph_record_marker): Add PPH_RECORD_IREF
>        and PPH_RECORD_XREF.  Remove PPH_RECORD_SHARED.  Update all users.
>        (struct pph_stream): Remove field open_p and nested_p.  Update
>        all users.
>        (enum chain_filter): Remove.  Change values to #define constants.
>        Update all users.
>        (PPHF_NO_XREFS): Define.
>        (pph_out_record_marker): New.
>        (pph_in_record_marker): New.
>        * pph.c (pph_finish): Always call pph_writer_finish.
>        Call pph_reader_finish.
>
> testsuite/ChangeLog.pph
>        * g++.dg/pph/x1tmplclass2.cc: Update expected ICE.
>        * g++.dg/pph/x4tmplclass2.cc: Update expected ICE.
>        * g++.dg/pph/z4tmplclass2.cc: Update expected ICE.
>
> diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
> index 50c6b66..7798f24 100644
> --- a/gcc/cp/name-lookup.c
> +++ b/gcc/cp/name-lookup.c
> @@ -6002,12 +6002,12 @@ pph_out_binding_table (pph_stream *stream, 
> binding_table bt)
>     {
>       if (bt->chain[i])
>        {
> -         pph_out_uchar (stream, PPH_RECORD_START);
> +         pph_out_record_marker (stream, PPH_RECORD_START);
>          pph_out_tree_or_ref (stream, bt->chain[i]->name);
>          pph_out_tree_or_ref (stream, bt->chain[i]->type);
>        }
>       else
> -       pph_out_uchar (stream, PPH_RECORD_END);
> +       pph_out_record_marker (stream, PPH_RECORD_END);
>     }
>   pph_out_uint (stream, bt->entry_count);
>  }
> @@ -6025,13 +6025,15 @@ pph_in_binding_table (pph_stream *stream)
>   bt = binding_table_new (chain_count);
>   for (i = 0; i < chain_count; i++)
>     {
> -      unsigned char record_marker = pph_in_uchar (stream);
> -      if (record_marker == PPH_RECORD_START)
> +      enum pph_record_marker marker = pph_in_record_marker (stream);
> +      if (marker == PPH_RECORD_START)
> 

[pph] Forwarding force

2011-08-16 Thread Gabriel Charette
This patch has yet to be committed to trunk, but I need it in pph.

This doesn't change anything (except that we now removed the built-in entry in 
the line_table, so there are now only 2 ignored line table entries).

Tested with bootstrap and pph regression testing (full testing done with trunk 
patch pending review).

Gab

2011-08-16  Gabriel Charette  

gcc/c-family/ChangeLog.pph
* c-opts.c (c_finish_options): Force BUILTINS_LOCATION for tokens
defined in cpp_init_builtins and c_cpp_builtins.

libcpp/ChangeLog.pph
* init.c (cpp_create_reader): Inititalize forced_token_location_p.
* internal.h (struct cpp_reader): Add field forced_token_location_p.
* lex.c (_cpp_lex_direct): Use forced_token_location_p.
(cpp_force_token_locations): New.
(cpp_stop_forcing_token_locations): New.

gcc/cp/ChangeLog.pph
* pph-streamer-out.c (pph_write_location): Better asserts.
* pph-streamer.h (PPH_NUM_IGNORED_LINE_TABLE_ENTRIES): Set to 2.

diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 8c8627e..3ee5860 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -1419,12 +1419,17 @@ c_finish_options (void)
 {
   size_t i;
 
-  cb_file_change (parse_in,
- linemap_add (line_table, LC_RENAME, 0,
-  _(""), 0));
+  {
+   /* Make sure all of the builtins about to be declared have
+ BUILTINS_LOCATION has their source_location.  */
+   source_location builtins_loc = BUILTINS_LOCATION;
+   cpp_force_token_locations (parse_in, &builtins_loc);
 
-  cpp_init_builtins (parse_in, flag_hosted);
-  c_cpp_builtins (parse_in);
+   cpp_init_builtins (parse_in, flag_hosted);
+   c_cpp_builtins (parse_in);
+
+   cpp_stop_forcing_token_locations (parse_in);
+  }
 
   /* We're about to send user input to cpplib, so make it warn for
 things that we previously (when we sent it internal definitions)
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index b7a965c..1c5c5d4 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -94,11 +94,19 @@ pph_write_location (struct output_block *ob, location_t loc)
  streaming some builtins, we probably want to figure out what those are and
  simply add them to the cache in the preload.  */
   struct bitpack_d bp;
-  location_t highest_builtin_loc = line_table->maps[2].start_location - 1;
+  location_t first_non_builtin_loc =
+line_table->maps[PPH_NUM_IGNORED_LINE_TABLE_ENTRIES].start_location;
 
   bp = bitpack_create (ob->main_stream);
-  if (loc < highest_builtin_loc)
-bp_pack_value (&bp, true, 1);
+  if (loc < first_non_builtin_loc)
+{
+  /* We should never stream out trees with locations between builtins
+and user locations (e.g. ).  */
+  if (loc > BUILTINS_LOCATION)
+gcc_unreachable ();
+
+  bp_pack_value (&bp, true, 1);
+}
   else
 {
   gcc_assert (loc >=
diff --git a/gcc/cp/pph-streamer.h b/gcc/cp/pph-streamer.h
index 19578fd..415995b 100644
--- a/gcc/cp/pph-streamer.h
+++ b/gcc/cp/pph-streamer.h
@@ -72,13 +72,13 @@ enum pph_symtab_marker {
exactly 8 bytes in the file.  */
 static const char pph_id_str[] = "PPH0x42";
 
-/* When streaming out the line_table we will ignore the first 3 entries.
-   The first one is the entrance in the header, the second one is for
-   builtins, the third one is the command line, the fourth one is finally
-   the LC_RENAME back to the header file, we want to stream out starting at
-   that one, changing it's reason to LC_ENTER (as we ignored the original
-   entrance), and then streaming every other entry as is from that point on.  
*/
-#define PPH_NUM_IGNORED_LINE_TABLE_ENTRIES 3
+/* When streaming out the line_table we will ignore the first 2 entries.
+   The first one is the entrance in the header, the second one is the command
+   line, the third one is the LC_RENAME back to the header file: we want to
+   stream out starting at that one, changing it's reason to LC_ENTER (as we
+   ignored the original entrance), and then streaming every other entry as is
+   from that point on.  */
+#define PPH_NUM_IGNORED_LINE_TABLE_ENTRIES 2
 
 /* Structure of the header of a PPH file.  */
 typedef struct pph_file_header {
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 97df9bb..06623fe 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -1043,4 +1043,8 @@ extern void cpp_prepare_state (cpp_reader *, struct 
save_macro_data **);
 extern int cpp_read_state (cpp_reader *, const char *, FILE *,
   struct save_macro_data *);
 
+/* In lex.c */
+extern void cpp_force_token_locations (cpp_reader *, source_location *);
+extern void cpp_stop_forcing_token_locations (cpp_reader *);
+
 #endif /* ! LIBCPP_CPPLIB_H */
diff 

[pph] Force token location for replayed macro definitions (issue4905050)

2011-08-16 Thread Gabriel Charette
This patch follows issue4907044.

Replayed definitions were given new source locations in the lexer. This would 
shift all of the locations assigned later and since this replay is absent in 
the non-pph, we get different source_locations for the tokens following the 
replay in pph.

This improves the quality of the pph line_table (closer and closer to the 
non-pph line_table, but not perfect yet).

Tested with bootstrap and pph regression testing.

Gab

2011-08-16  Gabriel Charette  

gcc/cp/ChangeLog.pph
* pph-streamer-in.c (pph_read_file_1): Set location of replayed
tokens to column 0 of the line the pph file was included on.

libcpp/ChangeLog.pph
* include/symtab.h (line-map.h): Add dependency.
* symtab.c (cpp_lt_replay): Add LOC parameter and force locations
of tokens replayed to *LOC if non-null.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index f87e6a5..8d25de8 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -1485,6 +1485,7 @@ pph_read_file_1 (pph_stream *stream)
   tree t, file_keyed_classes, file_static_aggregates;
   unsigned i;
   VEC(tree,gc) *file_unemitted_tinfo_decls;
+  source_location cpp_token_replay_loc;
 
   if (flag_pph_debug >= 1)
 fprintf (pph_logfile, "PPH: Reading %s\n", stream->name);
@@ -1502,8 +1503,13 @@ pph_read_file_1 (pph_stream *stream)
 report_validation_error (stream->name, bad_use->ident_str, cur_def,
  bad_use->before_str, bad_use->after_str);
 
-  /* Re-instantiate all the pre-processor symbols defined by STREAM.  */
-  cpp_lt_replay (parse_in, &idents_used);
+  /* Re-instantiate all the pre-processor symbols defined by STREAM.  Force
+ their source_location to column 0 of the line the include occured on,
+ this avoids shifting all of the line_table's location as we would by 
adding
+ locations which wouldn't be there in the non-pph compile; thus working
+ towards an identical line_table in pph and non-pph.  */
+  cpp_token_replay_loc = linemap_position_for_column (line_table, 0);
+  cpp_lt_replay (parse_in, &idents_used, &cpp_token_replay_loc);
 
   /* Read in STREAM's line table and merge it in the current line table.  */
   pph_in_and_merge_line_table (stream, line_table);
diff --git a/libcpp/include/symtab.h b/libcpp/include/symtab.h
index b5d6492..c39fa26 100644
--- a/libcpp/include/symtab.h
+++ b/libcpp/include/symtab.h
@@ -20,6 +20,7 @@ along with this program; see the file COPYING3.  If not see
 #define LIBCPP_SYMTAB_H
 
 #include "obstack.h"
+#include "line-map.h"
 
 #ifndef GTY
 #define GTY(x) /* nothing */
@@ -167,7 +168,8 @@ cpp_lt_verify (struct cpp_reader *reader, cpp_idents_used* 
identifiers,
 /* Replay the macro definitions captured by the table of IDENTIFIERS
into the READER state.  */
 void
-cpp_lt_replay (struct cpp_reader *reader, cpp_idents_used* identifiers);
+cpp_lt_replay (struct cpp_reader *reader, cpp_idents_used* identifiers,
+   source_location *loc);
 
 /* Destroy IDENTIFIERS captured.  */
 void
diff --git a/libcpp/symtab.c b/libcpp/symtab.c
index aad7277..b2e72f1 100644
--- a/libcpp/symtab.c
+++ b/libcpp/symtab.c
@@ -818,10 +818,12 @@ cpp_lt_define_syntax (char *needed, const char *ident, 
const char *given)
 }
 
 /* Replay the macro definitions captured by the table of IDENTIFIERS
-   into the READER state.  */
+   into the READER state.  If LOC is non-null, assign *LOC as the
+   source_location to all macro definitions replayed.  */
 
 void
-cpp_lt_replay (cpp_reader *reader, cpp_idents_used* identifiers)
+cpp_lt_replay (cpp_reader *reader, cpp_idents_used* identifiers,
+   source_location *loc)
 {
   unsigned int i;
   unsigned int num_entries = identifiers->num_entries;
@@ -832,6 +834,9 @@ cpp_lt_replay (cpp_reader *reader, cpp_idents_used* 
identifiers)
   /* Prevent the lexer from invalidating the tokens we've read so far.  */
   reader->keep_tokens++;
 
+  if (loc)
+cpp_force_token_locations (reader, loc);
+
   for (i = 0; i < num_entries; ++i)
 {
   cpp_ident_use *entry = entries + i;
@@ -865,6 +870,9 @@ cpp_lt_replay (cpp_reader *reader, cpp_idents_used* 
identifiers)
 
   reader->keep_tokens--;
 
+  if (loc)
+cpp_stop_forcing_token_locations (reader);
+
   free (buffer);
 }
 

--
This patch is available for review at http://codereview.appspot.com/4905050


[pph] New test - highlights issue with loading of pph child references (issue4898054)

2011-08-16 Thread Gabriel Charette
I noticed an issue while reading the code the child referencing code more in 
depth and wrote the following tests which exposes that issue.

We are loading every single header in the translation unit (not only the direct 
children) when doing pph_in_includes, but the children themselves correctly 
load their children; thus we end up with multiple instances of the same things.

I think this is due to the fact that everytime we call pph_read_file we add the 
file read to the list of includes (i.e. this also adds children of children to 
the includes list when the children itself is read and reads its children...).

I'm working on a better linemap streaming, but I must rely on the list of 
includes consisting only of the top-level includes (direct children) for the 
current pph.

Committed to pph.

Gab

2011-08-16  Gabriel Charette  

* g++.dg/pph/c0deepincl1.h: New.
* g++.dg/pph/c1deepincl2.h: New.
* g++.dg/pph/c2deepincl3.h: New.
* g++.dg/pph/c2deepincl.cc: New asm xdiff.

diff --git a/gcc/testsuite/g++.dg/pph/c0deepincl1.h 
b/gcc/testsuite/g++.dg/pph/c0deepincl1.h
new file mode 100644
index 000..4360163
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pph/c0deepincl1.h
@@ -0,0 +1,6 @@
+#ifndef C0DEEPINCL1_H
+#define C0DEEPINCL1_H
+
+int a = 0;
+
+#endif
diff --git a/gcc/testsuite/g++.dg/pph/c1deepincl2.h 
b/gcc/testsuite/g++.dg/pph/c1deepincl2.h
new file mode 100644
index 000..4861064
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pph/c1deepincl2.h
@@ -0,0 +1,8 @@
+#ifndef C1DEEPINCL2_H
+#define C1DEEPINCL2_H
+
+#include "c0deepincl1.h"
+
+int b = 1;
+
+#endif
diff --git a/gcc/testsuite/g++.dg/pph/c2deepincl.cc 
b/gcc/testsuite/g++.dg/pph/c2deepincl.cc
new file mode 100644
index 000..da56b1e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pph/c2deepincl.cc
@@ -0,0 +1,7 @@
+// pph asm xdiff 00611
+
+#include "c2deepincl3.h"
+
+int test() {
+return a + b + c;
+}
diff --git a/gcc/testsuite/g++.dg/pph/c2deepincl3.h 
b/gcc/testsuite/g++.dg/pph/c2deepincl3.h
new file mode 100644
index 000..d3a1522
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pph/c2deepincl3.h
@@ -0,0 +1,8 @@
+#ifndef C2DEEPINCL3_H
+#define C2DEEPINCL3_H
+
+#include "c1deepincl2.h"
+
+int c = 2;
+
+#endif

--
This patch is available for review at http://codereview.appspot.com/4898054


[pph] Fix child references being included multiple times (issue4904050)

2011-08-17 Thread Gabriel Charette
This patch fixes the fact that referenced child includes were read more then 
once before as stream->includes would contain too much.

This refactors the include structure.

pph_read_images now contains a flat vector of the pph_streams of all images 
read so far.

pph_out_stream->encoder.w.includes now contains a list of the streams of the 
includes coming directly from the file we are currently pph'ing (NOT their 
references)

Only the main stream (pph_out_stream) has such a list, we do not need to keep 
track of the include hiearchy of the non-direct includes as it is only needed 
on read and is already saved in the included pphs themselves.

This fixes c2deepincl.cc which was introduced yesterday to expose this same 
issue.

Tested with bootstrap and pph regression testing on x64.

Gab

2011-08-17  Gabriel Charette  

gcc/cp/ChangeLog.pph
* pph-streamer-in.c (pph_reading_includes): New.
(pph_in_includes): Add logic to control pph_reading_includes.
(pph_read_file_1): Only call pph_add_include if reading an include
from the main file (not from pph_in_includes).
(pph_read_file): Don't handle adding to pph_read_images here.
(pph_reader_finish): Free pph_read_images.
* pph-streamer-out.c (pph_tree_matches): Remove now unused STREAM
parameter. Update all users.
(pph_add_include): Changed signature to (stream, bool).
Update all users.
Handle adding INCLUDE to pph_read_images here.
* gcc/cp/pph-streamer.c (pph_read_images): Moved here from
pph-streamer-in.c
(pph_stream_close): Free stream->encoder.w.includes.
(pph_cache_lookup_in_includes): Lookup in pph_read_images.
Remove now unused STREAM parameter.
Update all users.
(pph_cache_get): Index in pph_read_images.
* pph-streamer.h (pph_stream): Move field includes to
pph_stream.encoder.w.includes. Update all users.
* gcc/cp/pph.c (pph_finish): Fixed extra space typo.

gcc/testsuite/ChangeLog.pph
* g++.dg/pph/c2deepincl.cc: Remove asm xdiff.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 013f526..3b2e082 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -33,13 +33,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "cppbuiltin.h"
 #include "toplev.h"
 
-/* List of PPH images read during parsing.  Images opened during #include
-   processing and opened from pph_in_includes cannot be closed
-   immediately after reading, because the pickle cache contained in
-   them may be referenced from other images.  We delay closing all of
-   them until the end of parsing (when pph_reader_finish is called).  */
-static VEC(pph_stream_ptr,heap) *pph_read_images = NULL;
-
 typedef char *char_p;
 DEF_VEC_P(char_p);
 DEF_VEC_ALLOC_P(char_p,heap);
@@ -53,6 +46,12 @@ DEF_VEC_ALLOC_P(char_p,heap);
   memory will remain allocated until the end of compilation.  */
 static VEC(char_p,heap) *string_tables = NULL;
 
+/* Increment when we are in the process of reading includes as we do not want
+   to add those to the parent pph stream's list of includes to be written out.
+   Decrement when done. We cannot use a simple true/false flag as read includes
+   will call pph_in_includes as well.  */
+static int pph_reading_includes = 0;
+
 /* Wrapper for memory allocation calls that should have their results
registered in the PPH streamer cache.  DATA is the pointer returned
by the memory allocation call in ALLOC_EXPR.  IX is the cache slot 
@@ -1289,13 +1288,17 @@ pph_in_includes (pph_stream *stream)
 {
   unsigned i, num;
 
+  pph_reading_includes++;
+
   num = pph_in_uint (stream);
   for (i = 0; i < num; i++)
 {
   const char *include_name = pph_in_string (stream);
   pph_stream *include = pph_read_file (include_name);
-  pph_add_include (stream, include);
+  pph_add_include (include, false);
 }
+
+  pph_reading_includes--;
 }
 
 
@@ -1467,8 +1470,8 @@ pph_read_file_1 (pph_stream *stream)
   /* If we are generating an image, the PPH contents we just read from
  STREAM will need to be read again the next time we want to read
  the image we are now generating.  */
-  if (pph_out_file)
-pph_add_include (NULL, stream);
+  if (pph_out_file && !pph_reading_includes)
+pph_add_include (stream, true);
 }
 
 
@@ -1481,10 +1484,7 @@ pph_read_file (const char *filename)
 
   stream = pph_stream_open (filename, "rb");
   if (stream)
-{
-  pph_read_file_1 (stream);
-  VEC_safe_push (pph_stream_ptr, heap, pph_read_images, stream);
-}
+pph_read_file_1 (stream);
   else
 error ("Cannot open PPH file for reading: %s: %m", filename);
 
@@ -1964,4 +1964,6 @@ pph_reader_finish (void)
   /* Close any images read during parsing.  */
   FOR_EACH_VEC_ELT (pph_stream_ptr, pph_read_images, i, image)
 pph_stream_close (i

[pph] Fix child references being included multiple times (issue4904050)

2011-08-17 Thread Gabriel Charette
I changed my mind and kept stream->includes the way it was originally meant to 
be, i.e. every stream will have its list of includes not only the main pph's 
stream.

More specifically I will be using this for every stream when regenerating the 
linemap (and reading the includes in parallel) in my upcoming patch!

Furthermore, we could get rid of the global pph_read_image altogether now as 
it's only a flat vector representation of the include tree structure saved 
through the pph_streams'->includes. The only problem I see is in pph_cache_get 
where we need a fix index for a stream (we could definitely map an index to the 
post-order traversal of the include tree, but it won't be as fast as a simple 
index in a flat vector), I didn't do it for now..

Cheers,
Gab

2011-08-17  Gabriel Charette  

gcc/cp/ChangeLog.pph
* pph-streamer-in.c (pph_reading_includes): New.
(pph_in_includes): Add logic to control pph_reading_includes.
(pph_read_file_1): Only call pph_add_include if reading an include
from the main file (not from pph_in_includes).
(pph_read_file): Don't handle adding to pph_read_images here.
(pph_reader_finish): Free pph_read_images.
* pph-streamer-out.c (pph_tree_matches): Remove now unused STREAM
parameter. Update all users.
(pph_add_include): Handle adding INCLUDE to pph_read_images here.
* pph-streamer.c (pph_read_images): Moved here from pph-streamer-in.c
(pph_stream_close): Free stream->includes.
(pph_cache_lookup_in_includes): Lookup in pph_read_images.
Remove now unused STREAM parameter. Update all users.
(pph_cache_get): Index in pph_read_images.
* pph-streamer.h (pph_stream): Changed comment for field "includes".
* pph.c (pph_finish): Fixed extra space typo.

gcc/testsuite/ChangeLog.pph
* g++.dg/pph/c2deepincl.cc: Remove asm xdiff.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 013f526..58f084e 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -33,13 +33,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "cppbuiltin.h"
 #include "toplev.h"
 
-/* List of PPH images read during parsing.  Images opened during #include
-   processing and opened from pph_in_includes cannot be closed
-   immediately after reading, because the pickle cache contained in
-   them may be referenced from other images.  We delay closing all of
-   them until the end of parsing (when pph_reader_finish is called).  */
-static VEC(pph_stream_ptr,heap) *pph_read_images = NULL;
-
 typedef char *char_p;
 DEF_VEC_P(char_p);
 DEF_VEC_ALLOC_P(char_p,heap);
@@ -53,6 +46,12 @@ DEF_VEC_ALLOC_P(char_p,heap);
   memory will remain allocated until the end of compilation.  */
 static VEC(char_p,heap) *string_tables = NULL;
 
+/* Increment when we are in the process of reading includes as we do not want
+   to add those to the parent pph stream's list of includes to be written out.
+   Decrement when done. We cannot use a simple true/false flag as read includes
+   will call pph_in_includes as well.  */
+static int pph_reading_includes = 0;
+
 /* Wrapper for memory allocation calls that should have their results
registered in the PPH streamer cache.  DATA is the pointer returned
by the memory allocation call in ALLOC_EXPR.  IX is the cache slot 
@@ -1289,6 +1288,8 @@ pph_in_includes (pph_stream *stream)
 {
   unsigned i, num;
 
+  pph_reading_includes++;
+
   num = pph_in_uint (stream);
   for (i = 0; i < num; i++)
 {
@@ -1296,6 +1297,8 @@ pph_in_includes (pph_stream *stream)
   pph_stream *include = pph_read_file (include_name);
   pph_add_include (stream, include);
 }
+
+  pph_reading_includes--;
 }
 
 
@@ -1467,7 +1470,7 @@ pph_read_file_1 (pph_stream *stream)
   /* If we are generating an image, the PPH contents we just read from
  STREAM will need to be read again the next time we want to read
  the image we are now generating.  */
-  if (pph_out_file)
+  if (pph_out_file && !pph_reading_includes)
 pph_add_include (NULL, stream);
 }
 
@@ -1481,10 +1484,7 @@ pph_read_file (const char *filename)
 
   stream = pph_stream_open (filename, "rb");
   if (stream)
-{
-  pph_read_file_1 (stream);
-  VEC_safe_push (pph_stream_ptr, heap, pph_read_images, stream);
-}
+pph_read_file_1 (stream);
   else
 error ("Cannot open PPH file for reading: %s: %m", filename);
 
@@ -1964,4 +1964,6 @@ pph_reader_finish (void)
   /* Close any images read during parsing.  */
   FOR_EACH_VEC_ELT (pph_stream_ptr, pph_read_images, i, image)
 pph_stream_close (image);
+
+  VEC_free (pph_stream_ptr, heap, pph_read_images);
 }
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index 2099d4e..44fe018 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-strea

Re: [pph] Fix child references being included multiple times (issue 4904050)

2011-08-17 Thread Gabriel Charette
Thinking more about this on my way back...

I will only need includes directly included by the current pph, not
the full include tree as I added in version 2 of this patch thinking I
would need it for the line_table...

Can you approve version 1 instead?!

> http://codereview.appspot.com/4904050/diff/3001/gcc/cp/pph-streamer.h#newcode210
> gcc/cp/pph-streamer.h:210: extern VEC(pph_stream_ptr, heap)
> *pph_read_images;
>>
>> 209
>> 210 extern VEC(pph_stream_ptr, heap) *pph_read_images;
>
> Move earlier in the file and add documentation.

The documentation is on the variable in the C file directly as I've
noticed this is what is done most of the time...

I put it at that line in the file because this is where the references
from pph-streamer.c are (unless it's different for variables then it
is for functions??)

Cheers,
Gab


Re: Linemap force location and remove LINEMAP_POSITION_FOR_COLUMN (issue4801090)

2011-08-18 Thread Gabriel Charette
Tom: ok for trunk?

fortran@: The fortran change just reflects the fix from libcpp,
fortran bootstrap and tests passed.

Thanks,
Gabriel

On Wed, Aug 17, 2011 at 1:04 PM, Dodji Seketeli  wrote:
> Hello Gabriel,
>
> gch...@google.com (Gabriel Charette) a écrit:
>
>> Here is the updated patch.
>>
>> It nows exposes two libcpp functions to force the source_location for tokens 
>> when desired.
>>
>> The lexer then checks for a value set by these functions in cpp_reader and 
>> acts accordingly when needing a location for a new token (either using the 
>> forced_location or calling the linemap as it used to).
>>
>> It turns out the fortran library made the same mistake of creating a 
>> line_table entry for builtins, I fixed it as well in this patch.
>>
>> Tested on x64 for c++,fortran.
>>
>> (fyi: I moved the removal of LINEMAP_POSITION_FOR_COLUMN to a separate patch 
>> which is checked-in already; thus it doesn't show up in this updated patch 
>> obviously.
>> )
>>
>> Ok for trunk?
>>
>> Gabriel
>>
>> 2011-08-15  Gabriel Charette  
>>
>>       gcc/c-family/ChangeLog
>>       * c-opts.c (c_finish_options): Force BUILTINS_LOCATION for tokens
>>       defined in cpp_init_builtins and c_cpp_builtins.
>>
>>       gcc/fortran/ChangeLog
>>       * cpp.c (gfc_cpp_init): Force BUILTINS_LOCATION for tokens
>>       defined in cpp_define_builtins.
>>
>>       libcpp/ChangeLog
>>       * init.c (cpp_create_reader): Inititalize forced_token_location_p.
>>       * internal.h (struct cpp_reader): Add field forced_token_location_p.
>>       * lex.c (_cpp_lex_direct): Use forced_token_location_p.
>>       (cpp_force_token_locations): New.
>>       (cpp_stop_forcing_token_locations): New.
>
> I cannot approve or reject this patch, but FWIW, it looks OK to me.
>
> Thanks.
>
> --
>                Dodji
>


[pph] Fix child references being included multiple times (issue4904050)

2011-08-18 Thread Gabriel Charette
Committing version 1.

Added comment for pph_read_images and moved as requested.

See final patch attached.

Gab

2011-08-18  Gabriel Charette  

gcc/cp/ChangeLog.pph
* pph-streamer-in.c (pph_reading_includes): New.
(pph_in_includes): Add logic to control pph_reading_includes.
(pph_read_file_1): Only call pph_add_include if reading an include
from the main file (not from pph_in_includes).
(pph_read_file): Don't handle adding to pph_read_images here.
(pph_reader_finish): Free pph_read_images.
* pph-streamer-out.c (pph_tree_matches): Remove now unused STREAM
parameter. Update all users.
(pph_add_include): Changed signature to (stream, bool).
Update all users.
Handle adding INCLUDE to pph_read_images here.
* gcc/cp/pph-streamer.c (pph_read_images): Moved here from
pph-streamer-in.c
(pph_stream_close): Free stream->encoder.w.includes.
(pph_cache_lookup_in_includes): Lookup in pph_read_images.
Remove now unused STREAM parameter.
Update all users.
(pph_cache_get): Index in pph_read_images.
* pph-streamer.h (pph_stream): Move field includes to
pph_stream.encoder.w.includes. Update all users.
* gcc/cp/pph.c (pph_init): Initialize pph_read_images to NULL.
(pph_finish): Fixed extra space typo.

gcc/testsuite/ChangeLog.pph
* g++.dg/pph/c2deepincl.cc: Remove asm xdiff.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 40b65c7..4666ace 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -33,13 +33,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "cppbuiltin.h"
 #include "toplev.h"
 
-/* List of PPH images read during parsing.  Images opened during #include
-   processing and opened from pph_in_includes cannot be closed
-   immediately after reading, because the pickle cache contained in
-   them may be referenced from other images.  We delay closing all of
-   them until the end of parsing (when pph_reader_finish is called).  */
-static VEC(pph_stream_ptr,heap) *pph_read_images = NULL;
-
 typedef char *char_p;
 DEF_VEC_P(char_p);
 DEF_VEC_ALLOC_P(char_p,heap);
@@ -53,6 +46,12 @@ DEF_VEC_ALLOC_P(char_p,heap);
   memory will remain allocated until the end of compilation.  */
 static VEC(char_p,heap) *string_tables = NULL;
 
+/* Increment when we are in the process of reading includes as we do not want
+   to add those to the parent pph stream's list of includes to be written out.
+   Decrement when done. We cannot use a simple true/false flag as read includes
+   will call pph_in_includes as well.  */
+static int pph_reading_includes = 0;
+
 /* Wrapper for memory allocation calls that should have their results
registered in the PPH streamer cache.  DATA is the pointer returned
by the memory allocation call in ALLOC_EXPR.  IX is the cache slot 
@@ -1289,13 +1288,17 @@ pph_in_includes (pph_stream *stream)
 {
   unsigned i, num;
 
+  pph_reading_includes++;
+
   num = pph_in_uint (stream);
   for (i = 0; i < num; i++)
 {
   const char *include_name = pph_in_string (stream);
   pph_stream *include = pph_read_file (include_name);
-  pph_add_include (stream, include);
+  pph_add_include (include, false);
 }
+
+  pph_reading_includes--;
 }
 
 
@@ -1467,8 +1470,8 @@ pph_read_file_1 (pph_stream *stream)
   /* If we are generating an image, the PPH contents we just read from
  STREAM will need to be read again the next time we want to read
  the image we are now generating.  */
-  if (pph_out_file)
-pph_add_include (NULL, stream);
+  if (pph_out_file && !pph_reading_includes)
+pph_add_include (stream, true);
 }
 
 
@@ -1481,10 +1484,7 @@ pph_read_file (const char *filename)
 
   stream = pph_stream_open (filename, "rb");
   if (stream)
-{
-  pph_read_file_1 (stream);
-  VEC_safe_push (pph_stream_ptr, heap, pph_read_images, stream);
-}
+pph_read_file_1 (stream);
   else
 error ("Cannot open PPH file for reading: %s: %m", filename);
 
@@ -1964,4 +1964,6 @@ pph_reader_finish (void)
   /* Close any images read during parsing.  */
   FOR_EACH_VEC_ELT (pph_stream_ptr, pph_read_images, i, image)
 pph_stream_close (image);
+
+  VEC_free (pph_stream_ptr, heap, pph_read_images);
 }
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index d64f6c4..1b84cc3 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -207,11 +207,11 @@ pph_out_start_record (pph_stream *stream, void *data)
   return false;
 }
 
-  /* DATA is not in STREAM's cache.  See if it is in any of STREAM's
+  /* DATA is not in STREAM's cache.  See if it is in any of the
  included images.  If it is, write an external reference to it
  and inform the caller that it should not write a physical
  representation fo

[pph] Add support for line table streaming with includes (issue4908051)

2011-08-18 Thread Gabriel Charette
Before this patch the line_table was not identical to the non-pph line_table.

The child references patch just recently made this worst.

We had a design problem where we need to load the line_table entries for the 
main file before the child's entries. However we need to load the bindings of 
the child before the parent's...

So the only solution is to do both in parallel, using the linemap output to 
write a reference to an include to be loaded recursively during the streaming 
in of the line_table of the parent.

This also allows us to store less information per pph! Only the line_table 
entries specifically defined in a pph are needed, referenced pph headers' 
entries are skipped and injected recursively when streaming in!

One important change is that it was easier to stream in the line_table and 
includes first, before replaying the identifiers, is that a problem in the type 
of syntax we wanted to support?? (i.e. in this model we can't rely on tokens 
defined in the main file to affect things defined in its pph children).

The line_table is now almost perfectly identical in pph and non-pph (I scanned 
it in the debugger after parsing p4eabi.cc which is the hardest mix of 
line_table entries I found). The only reason it still differs is that we load 
some included headers twice, where as the non-pph skips it the second time, 
this is a known current issue so I didn't bother working around it in the 
line_table streaming implementation.

This fixes the asm diff in p4eabi.cc
It also affects the line number of some expected failures (I think those are 
now the "correct" line numbers for the builtins that we are failing on).

Tested on x64 with bootstrap and pph regression testing.

Cheers,
Gab

2011-08-18  Gabriel Charette  

gcc/cp/ChangeLog.pph
* pph-streamer-in.c (pph_in_includes): Remove.
(pph_in_linetable_marker): New.
(pph_in_line_table_and_includes): Renamed from
pph_in_and_merge_line_table.
Now handles line_table and includes input in parallel.
Now returns source_location corresponding to line 1 / col 0
of the header currently loaded as pph.
(pph_read_file_1): Read line_table and includes before replaying
tokens. Use location returned by pph_in_line_table_and_includes
as forced token location for replayed tokens.
* pph-streamer-out.c (pph_out_includes): Remove.
(pph_out_linetable_marker): New.
(pph_filename_eq_ignoring_path): New.
(pph_get_next_include): New.
(pph_out_line_table_and_includes): Renamed from pph_out_line_table.
Now handles output of both the line_table and includes references
in parallel.
(pph_write_file): Write out line_table and includes before
identifiers.
* pph-streamer.h (enum pph_linetable_marker): New.
* pph.c (pph_include_handler): Add hack to mimic
line_table->highest_location behaviour in _cpp_stack_include used
by the non-pph compiler.

gcc/testsuite/ChangeLog.pph
* g++.dg/pph/p4eabi1.cc: Remove asm xdiff.
* g++.dg/pph/x4keyed.cc: Changed line info for expected failure.
* g++.dg/pph/x7rtti.cc: Changed line info for expected failures.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 4666ace..a3a3566 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -1281,27 +1281,6 @@ pph_in_symtab (pph_stream *stream)
 }
 
 
-/* Read all the images included by STREAM.  */
-
-static void
-pph_in_includes (pph_stream *stream)
-{
-  unsigned i, num;
-
-  pph_reading_includes++;
-
-  num = pph_in_uint (stream);
-  for (i = 0; i < num; i++)
-{
-  const char *include_name = pph_in_string (stream);
-  pph_stream *include = pph_read_file (include_name);
-  pph_add_include (include, false);
-}
-
-  pph_reading_includes--;
-}
-
-
 /* Read a linenum_type from STREAM.  */
 
 static inline linenum_type
@@ -1320,6 +1299,20 @@ pph_in_source_location (pph_stream *stream)
 }
 
 
+/* Read a line table marker from STREAM.  */
+
+static inline enum pph_linetable_marker
+pph_in_linetable_marker (pph_stream *stream)
+{
+  enum pph_linetable_marker m =
+(enum pph_linetable_marker) pph_in_uchar (stream);
+  gcc_assert (m == PPH_LINETABLE_ENTRY
+ || m == PPH_LINETABLE_REFERENCE
+ || m == PPH_LINETABLE_END);
+  return m;
+}
+
+
 /* Read a line_map from STREAM into LM.  */
 
 static void
@@ -1343,47 +1336,102 @@ pph_in_line_map (pph_stream *stream, struct line_map 
*lm)
 }
 
 
-/* Read the line_table from STREAM and merge it in LINETAB.  */
+/* Read the line_table from STREAM and merge it in LINETAB.  At the same time
+   load includes in the order they were originally included by loading them at
+   the point they were referenced in the line_table.
 
-static void
-pph_in_and_merge_line_table (pph_stream *stream, struct line_maps *linetab)
+   Returns the s

[pph] Add support for line table streaming with includes (issue4908051)

2011-08-19 Thread Gabriel Charette
Applied requested changes.

Tested on x64 with bootstrap and pph regression testing.

Committing to pph branch, if any other changes are needed to this patch, I'm 
writting a clean up patch for the line_table implementation now and will add 
whatever else is needed to it.

One thing I wasn't sure is how to handle headers with no .h extensions, will we 
ever pph any of those? I currently support them in this patch.

Cheers,
Gab

2011-08-19  Gabriel Charette  

gcc/cp/ChangeLog.pph
* pph-streamer-in.c (pph_in_includes): Remove.
(pph_in_linetable_marker): New.
(pph_in_line_table_and_includes): Renamed from
pph_in_and_merge_line_table.
Now handles line_table and includes input in parallel.
Now returns source_location corresponding to line 1 / col 0
of the header currently loaded as pph.
(pph_read_file_1): Read line_table and includes before replaying
tokens. Use location returned by pph_in_line_table_and_includes
as forced token location for replayed tokens.
* pph-streamer-out.c (pph_out_includes): Remove.
(pph_out_linetable_marker): New.
(pph_filename_eq_ignoring_path): New.
(pph_get_next_include): New.
(pph_out_line_table_and_includes): Renamed from pph_out_line_table.
Now handles output of both the line_table and includes references
in parallel.
(pph_write_file): Write out line_table and includes before
identifiers.
* pph-streamer.h (enum pph_linetable_marker): New.
* pph.c (pph_include_handler): Add hack to mimic
line_table->highest_location behaviour in _cpp_stack_include used
by the non-pph compiler.

gcc/testsuite/ChangeLog.pph
* g++.dg/pph/p4eabi1.cc: Remove asm xdiff.
* g++.dg/pph/x4keyed.cc: Changed line info for expected failure.
* g++.dg/pph/x7rtti.cc: Changed line info for expected failures.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 4666ace..9686edf 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -1281,27 +1281,6 @@ pph_in_symtab (pph_stream *stream)
 }
 
 
-/* Read all the images included by STREAM.  */
-
-static void
-pph_in_includes (pph_stream *stream)
-{
-  unsigned i, num;
-
-  pph_reading_includes++;
-
-  num = pph_in_uint (stream);
-  for (i = 0; i < num; i++)
-{
-  const char *include_name = pph_in_string (stream);
-  pph_stream *include = pph_read_file (include_name);
-  pph_add_include (include, false);
-}
-
-  pph_reading_includes--;
-}
-
-
 /* Read a linenum_type from STREAM.  */
 
 static inline linenum_type
@@ -1320,6 +1299,20 @@ pph_in_source_location (pph_stream *stream)
 }
 
 
+/* Read a line table marker from STREAM.  */
+
+static inline enum pph_linetable_marker
+pph_in_linetable_marker (pph_stream *stream)
+{
+  enum pph_linetable_marker m =
+(enum pph_linetable_marker) pph_in_uchar (stream);
+  gcc_assert (m == PPH_LINETABLE_ENTRY
+ || m == PPH_LINETABLE_REFERENCE
+ || m == PPH_LINETABLE_END);
+  return m;
+}
+
+
 /* Read a line_map from STREAM into LM.  */
 
 static void
@@ -1343,47 +1336,100 @@ pph_in_line_map (pph_stream *stream, struct line_map 
*lm)
 }
 
 
-/* Read the line_table from STREAM and merge it in LINETAB.  */
+/* Read the line_table from STREAM and merge it in LINETAB.  At the same time
+   load includes in the order they were originally included by loading them at
+   the point they were referenced in the line_table.
 
-static void
-pph_in_and_merge_line_table (pph_stream *stream, struct line_maps *linetab)
+   Returns the source_location of line 1 / col 0 for this include.
+
+   FIXME pph: The line_table is now identical to the non-pph line_table, the
+   only problem is that we load line_table entries twice for headers that are
+   re-included and are #ifdef guarded; thus shouldn't be replayed.  This is
+   a known current issue, so I didn't bother working around it here for now.  
*/
+
+static source_location
+pph_in_line_table_and_includes (pph_stream *stream, struct line_maps *linetab)
 {
-  unsigned int ix, pph_used, old_depth;
+  unsigned int old_depth;
+  bool first;
+  int includer_ix = -1;
+  unsigned int used_before = linetab->used;
   int entries_offset = linetab->used - PPH_NUM_IGNORED_LINE_TABLE_ENTRIES;
+  enum pph_linetable_marker next_lt_marker = pph_in_linetable_marker (stream);
 
-  pph_used = pph_in_uint (stream);
+  pph_reading_includes++;
 
-  for (ix = 0; ix < pph_used; ix++, linetab->used++)
+  for (first = true; next_lt_marker != PPH_LINETABLE_END;
+   next_lt_marker = pph_in_linetable_marker (stream))
 {
-  struct line_map *lm;
+  if (next_lt_marker == PPH_LINETABLE_REFERENCE)
+   {
+ int old_loc_offset;
+ const char *include_name = pph_in_string (stream);
+ source_location prev_start_loc = pph_in_source_location (

Re: [pph] Fix x1dynarra1, x1dynarray2a and x1dynarray2b (issue4921051)

2011-08-22 Thread Gabriel Charette
On Mon, Aug 22, 2011 at 8:22 AM, Diego Novillo  wrote:
>
> This patch fixes some template test cases.  We were trying to
> expand functions that did not really need expanding (templates).  This
> got me thinking that we are not approaching the expansion properly.
>
> We are trying to re-create all the cgraph creation done during the
> compilation of the header file.  Rather than re-creating all this, it
> would be more efficient to save the state of the callgraph and varpool
> at the time of pph generation and then simply recreate it at read
> time.  I will experiment with that, see if it actually makes any
> sense.
>

I had this idea earlier when playing with varpool for functions not
being streamed with their "rest_of_decl"compilation" state. The
problem for doing this if I remember correctly is that calling the
functions which generate those creates some unique ordering and IDs,
so that we need to do it in order of the current include order of each
pph in the current TU, and since the order of each pph in a given
compilation is not set ahead of time, I'm not sure this is possible
(at least not simple). We could probably find a way to merge those
states on the way in, but that would most likely tie us to the
implementation of those calls..

Gab


[pph] Cleanup line_table and includes streaming (issue4921052)

2011-08-22 Thread Gabriel Charette
This is a refactoring patch, it doesn't change/fix anything in pph itself.

I extracted out/in logic for includes into their own functions.

I removed the LINETAB parameter from in/out functions for the line_table as 
there is only one line_table and that's the only one we stream, the main/global 
one.

I wanted to move pph_loc_offset to pph_stream.encoder.r, but it's not possible 
while locations are called by the streamer hook as in the callback we do not 
have a pph_stream* parameter, added a FIXME to do it later if we do get rid of 
the hook for locations.

Tested with bootstrap and pph regression testing on x64.

Cheers,
Gab

2011-08-22  Gabriel Charette  

* pph-streamer-in.c (pph_loc_offset): Add FIXME to move this variable
to pph_stream.encoder.r
(pph_in_include): New.
(pph_in_line_table_and_includes): Remove LINETAB parameter. Update
all users to use global LINE_TABLE instead.
Remove code moved to new function pph_in_include. And call it.
(pph_read_file_1): Remove extra parameter in call to
pph_in_line_table_and_includes.
* pph-streamer-out.c (pph_out_include): New.
(pph_get_next_include): Fix comment.
(pph_out_line_table_and_includes): Remove LINETAB parameter. Update
all users to use global LINE_TABLE instead.
Remove code moved to new function pph_out_include. And call it.
* gcc/cp/pph-streamer.h (pph_stream): Fix indenting.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 07e1135..2b7dc2d 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -75,7 +75,11 @@ static int pph_reading_includes = 0;
 } while (0)
 
 /* Set in pph_in_and_merge_line_table. Represents the source_location offset
-   which every streamed in token must add to it's serialized source_location. 
*/
+   which every streamed in token must add to it's serialized source_location.
+
+   FIXME pph: Ideally this would be in pph_stream.encoder.r, but for that we
+   first need to get rid of the dependency to the streamer_hook for locations.
+   */
 static int pph_loc_offset;
 
 
@@ -1336,9 +1340,37 @@ pph_in_line_map (pph_stream *stream, struct line_map *lm)
 }
 
 
-/* Read the line_table from STREAM and merge it in LINETAB.  At the same time
-   load includes in the order they were originally included by loading them at
-   the point they were referenced in the line_table.
+/* Read in from STREAM and merge a referenced include into the current parsing
+   context.  */
+
+static void
+pph_in_include (pph_stream *stream)
+{
+  int old_loc_offset;
+  const char *include_name;
+  pph_stream *include;
+  source_location prev_start_loc = pph_in_source_location (stream);
+
+  /* Simulate highest_location to be as it would be at this point in a non-pph
+ compilation.  */
+  line_table->highest_location = (prev_start_loc - 1) + pph_loc_offset;
+
+  /* FIXME pph: If we move pph_loc_offset to pph_stream.encoder.r, we could
+ have an independent offset for each stream and not have to save and
+ restore the state of a global pph_loc_offset as we are doing here.  */
+  old_loc_offset = pph_loc_offset;
+
+  include_name = pph_in_string (stream);
+  include = pph_read_file (include_name);
+  pph_add_include (include, false);
+
+  pph_loc_offset = old_loc_offset;
+}
+
+
+/* Read the line_table from STREAM and merge it in the current line_table.  At
+   the same time load includes in the order they were originally included by
+   loading them at the point they were referenced in the line_table.
 
Returns the source_location of line 1 / col 0 for this include.
 
@@ -1348,13 +1380,13 @@ pph_in_line_map (pph_stream *stream, struct line_map 
*lm)
a known current issue, so I didn't bother working around it here for now.  
*/
 
 static source_location
-pph_in_line_table_and_includes (pph_stream *stream, struct line_maps *linetab)
+pph_in_line_table_and_includes (pph_stream *stream)
 {
   unsigned int old_depth;
   bool first;
   int includer_ix = -1;
-  unsigned int used_before = linetab->used;
-  int entries_offset = linetab->used - PPH_NUM_IGNORED_LINE_TABLE_ENTRIES;
+  unsigned int used_before = line_table->used;
+  int entries_offset = line_table->used - PPH_NUM_IGNORED_LINE_TABLE_ENTRIES;
   enum pph_linetable_marker next_lt_marker = pph_in_linetable_marker (stream);
 
   pph_reading_includes++;
@@ -1364,29 +1396,16 @@ pph_in_line_table_and_includes (pph_stream *stream, 
struct line_maps *linetab)
 {
   if (next_lt_marker == PPH_LINETABLE_REFERENCE)
{
- int old_loc_offset;
- const char *include_name = pph_in_string (stream);
- source_location prev_start_loc = pph_in_source_location (stream);
- pph_stream *include;
-
  gcc_assert (!first);
-
- linetab->highest_location = (prev_start_loc - 1) + pph_loc_offset;
-
- old_loc_offset = pph_loc_offset;
-

[pph] Remove fixed FIXME in p4eabi.h (issue4939045)

2011-08-23 Thread Gabriel Charette
This memory problem was probably due to the big line_table being created with 
the incorrect code before.

This test now passes and this FIXME was irrelevant, removed it.

Trivial patch, already discussed with Diego, committed to pph.

2011-08-23  Gabriel Charette  

* g++.dg/pph/p4eabi1.h: Remove fixed FIXME.

diff --git a/gcc/testsuite/g++.dg/pph/p4eabi1.h 
b/gcc/testsuite/g++.dg/pph/p4eabi1.h
index 781de86..8c949ea 100644
--- a/gcc/testsuite/g++.dg/pph/p4eabi1.h
+++ b/gcc/testsuite/g++.dg/pph/p4eabi1.h
@@ -1,5 +1,4 @@
 // { dg-options "-w -fpermissive" }
-// FIXME pph - Enabling PPH for this file causes memory problems in cc1plus.
 // c1eabi1.h   c1eabi1.pph
 
 #ifndef C4EABI1_H

--
This patch is available for review at http://codereview.appspot.com/4939045


[pph] Use pph_pickle_cache* instead of pph_stream* as first parameter for cache functions (issue4930051)

2011-08-24 Thread Gabriel Charette
This is a refactoring patch to make all pph caching function take a 
pph_pickle_cache* directly as a first parameter instead of a pph_stream*.

This will allow us to have a global "pph_pickle_cache *pph_preloaded_cache" to 
store the preloaded nodes instead of preload the nodes at the beginning of 
every stream's cache.

I need to be able to differentiate between cache hits and preloaded cache hits. 
The easy way would be to mark the index at which real cache entries start, but 
since we want to have an independent cache for preloads in the long run, might 
as well do it right now.

Gab

2011-08-24  Gabriel Charette  

* pph-streamer-in.c (ALLOC_AND_REGISTER): Take a pph_pickle_cache*
as a first parameter instead of a pph_stream*.
Update all users.
(ALLOC_AND_REGISTER_ALTERNATE): Likewise.
* pph-streamer.c (pph_cache_insert_at): Likewise.
(pph_cache_lookup): Likewise.
(pph_cache_add): Likewise.
(pph_cache_get): Likewise.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 2b7dc2d..720da6a 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -55,23 +55,23 @@ static int pph_reading_includes = 0;
 /* Wrapper for memory allocation calls that should have their results
registered in the PPH streamer cache.  DATA is the pointer returned
by the memory allocation call in ALLOC_EXPR.  IX is the cache slot 
-   in STREAM where the newly allocated DATA should be registered at.  */
-#define ALLOC_AND_REGISTER(STREAM, IX, DATA, ALLOC_EXPR)   \
+   in CACHE where the newly allocated DATA should be registered at.  */
+#define ALLOC_AND_REGISTER(CACHE, IX, DATA, ALLOC_EXPR)\
 do {   \
   (DATA) = (ALLOC_EXPR);   \
-  pph_cache_insert_at (STREAM, DATA, IX);  \
+  pph_cache_insert_at (CACHE, DATA, IX);   \
 } while (0)
 
 /* Same as ALLOC_AND_REGISTER, but instead of registering DATA into the
cache at slot IX, it registers ALT_DATA.  Used to support mapping
-   pointers to global data in the original STREAM that need to point
+   pointers to global data in the original CACHE that need to point
to a different instance when aggregating individual PPH files into
the current translation unit (see pph_in_binding_level for an
example).  */
-#define ALLOC_AND_REGISTER_ALTERNATE(STREAM, IX, DATA, ALLOC_EXPR, ALT_DATA)\
+#define ALLOC_AND_REGISTER_ALTERNATE(CACHE, IX, DATA, ALLOC_EXPR, ALT_DATA)\
 do {   \
   (DATA) = (ALLOC_EXPR);   \
-  pph_cache_insert_at (STREAM, ALT_DATA, IX);  \
+  pph_cache_insert_at (CACHE, ALT_DATA, IX);   \
 } while (0)
 
 /* Set in pph_in_and_merge_line_table. Represents the source_location offset
@@ -413,11 +413,11 @@ pph_in_cxx_binding_1 (pph_stream *stream)
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (pph_is_reference_marker (marker))
-return (cxx_binding *) pph_cache_get (stream, include_ix, ix);
+return (cxx_binding *) pph_cache_get (&stream->cache, include_ix, ix);
 
   value = pph_in_tree (stream);
   type = pph_in_tree (stream);
-  ALLOC_AND_REGISTER (stream, ix, cb, cxx_binding_make (value, type));
+  ALLOC_AND_REGISTER (&stream->cache, ix, cb, cxx_binding_make (value, type));
   cb->scope = pph_in_binding_level (stream, NULL);
   bp = pph_in_bitpack (stream);
   cb->value_is_inherited = bp_unpack_value (&bp, 1);
@@ -461,9 +461,10 @@ pph_in_class_binding (pph_stream *stream)
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (pph_is_reference_marker (marker))
-return (cp_class_binding *) pph_cache_get (stream, image_ix, ix);
+return (cp_class_binding *) pph_cache_get (&stream->cache, image_ix, ix);
 
-  ALLOC_AND_REGISTER (stream, ix, cb, ggc_alloc_cleared_cp_class_binding ());
+  ALLOC_AND_REGISTER (&stream->cache, ix, cb,
+  ggc_alloc_cleared_cp_class_binding ());
   cb->base = pph_in_cxx_binding (stream);
   cb->identifier = pph_in_tree (stream);
 
@@ -484,9 +485,10 @@ pph_in_label_binding (pph_stream *stream)
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (pph_is_reference_marker (marker))
-return (cp_label_binding *) pph_cache_get (stream, image_ix, ix);
+return (cp_label_binding *) pph_cache_get (&stream->cache, image_ix, ix);
 
-  ALLOC_AND_REGISTER (stream, ix, lb, ggc_alloc_cleared_cp_label_binding ());
+  ALLOC_AND_REGISTER (&stream->cache, ix, lb,
+  ggc_alloc_cleared_cp_label_binding ());
   lb->label = pph_in_tree (stream);
   lb->prev_value = pph_in_tree (stream);
 
@@ -524,14 +526,15 @@ pph_in_binding_level (pph_stream *stream, 
cp_binding_level *to_register)
   if (marker == PPH_RECORD_E

[pph] Independent pre-loaded cache for common nodes (issue4956041)

2011-08-24 Thread Gabriel Charette
This patch creates an independent cache, pph_preloaded_cache, which contains 
all common nodes which used to be directly added to each stream's cache.

The streams' cache now only contain nodes which really belong to them.

The preloaded cache is last in the lookup on the way out (potentially allowing 
us to play tricks later if we need to, i.e. by adding a modified preloaded 
structure's reference in the main cache to get the hit we want earlier and 
control the result...?)

Tested with bootstrap and pph regression testing.

Cheers,
Gab

2011-08-24  Gabriel Charette  

* pph-streamer-in.c (pph_is_reference_marker): Handle PPH_RECORD_PREF.
(pph_in_start_record): Likewise.
* pph-streamer-out.c (pph_out_start_record): Add extra lookup in
pph_preloaded_cache if lookup in current and included streams failed.
* pph-streamer.c (pph_preloaded_cache): New.
(pph_cache_preload): Change first parameter to a pph_pickle_cache*
from a pph_stream*. Update all users.
(pph_cache_init): New.
(pph_init_preloaded_cache): New local variable.
(pph_stream_open): Use pph_cache_init. Do not call pph_cache_preload.
(pph_cache_get): Add a new pph_record_marker parameter which we
use to determine to type of get to do. Update all users.
* pph-streamer.h (enum pph_record_marker): Add PPH_RECORD_PREF.
(pph_in_record_marker): Handle PPH_RECORD_PREF.
* pph.c (pph_init): Call pph_init_preloaded_cache.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 720da6a..1561f88 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -145,12 +145,14 @@ pph_init_read (pph_stream *stream)
 }
 
 
-/* Return true if MARKER is either PPH_RECORD_IREF or PPH_RECORD_XREF.  */
+/* Return true if MARKER is PPH_RECORD_IREF, PPH_RECORD_XREF,
+   or PPH_RECORD_PREF.  */
 
 static inline bool
 pph_is_reference_marker (enum pph_record_marker marker)
 {
-  return marker == PPH_RECORD_IREF || marker == PPH_RECORD_XREF;
+  return marker == PPH_RECORD_IREF || marker == PPH_RECORD_XREF
+ || marker == PPH_RECORD_PREF;
 }
 
 
@@ -189,8 +191,10 @@ pph_in_start_record (pph_stream *stream, unsigned 
*include_ix_p,
 
   /* For PPH_RECORD_START and PPH_RECORD_IREF markers, read the
  streamer cache slot where we should store or find the
- rematerialized data structure (see description above).  */
-  if (marker == PPH_RECORD_START || marker == PPH_RECORD_IREF)
+ rematerialized data structure (see description above).
+ Also read the preloaded cache slot in IX for PPH_RECORD_PREF.  */
+  if (marker == PPH_RECORD_START || marker == PPH_RECORD_IREF
+  || marker == PPH_RECORD_PREF)
 *cache_ix_p = pph_in_uint (stream);
   else if (marker == PPH_RECORD_XREF)
 {
@@ -407,13 +411,13 @@ pph_in_cxx_binding_1 (pph_stream *stream)
   cxx_binding *cb;
   tree value, type;
   enum pph_record_marker marker;
-  unsigned ix, include_ix;
+  unsigned ix, image_ix;
 
-  marker = pph_in_start_record (stream, &include_ix, &ix);
+  marker = pph_in_start_record (stream, &image_ix, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (pph_is_reference_marker (marker))
-return (cxx_binding *) pph_cache_get (&stream->cache, include_ix, ix);
+return (cxx_binding *) pph_cache_get (&stream->cache, image_ix, ix, 
marker);
 
   value = pph_in_tree (stream);
   type = pph_in_tree (stream);
@@ -461,7 +465,8 @@ pph_in_class_binding (pph_stream *stream)
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (pph_is_reference_marker (marker))
-return (cp_class_binding *) pph_cache_get (&stream->cache, image_ix, ix);
+return (cp_class_binding *) pph_cache_get (&stream->cache, image_ix, ix,
+  marker);
 
   ALLOC_AND_REGISTER (&stream->cache, ix, cb,
   ggc_alloc_cleared_cp_class_binding ());
@@ -485,7 +490,8 @@ pph_in_label_binding (pph_stream *stream)
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (pph_is_reference_marker (marker))
-return (cp_label_binding *) pph_cache_get (&stream->cache, image_ix, ix);
+return (cp_label_binding *) pph_cache_get (&stream->cache, image_ix, ix,
+  marker);
 
   ALLOC_AND_REGISTER (&stream->cache, ix, lb,
   ggc_alloc_cleared_cp_label_binding ());
@@ -526,7 +532,8 @@ pph_in_binding_level (pph_stream *stream, cp_binding_level 
*to_register)
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (pph_is_reference_marker (marker))
-return (cp_binding_level *) pph_cache_get (&stream->cache, image_ix, ix);
+return (cp_binding_level *) pph_cache_get (&stream->cache, image_ix, ix,
+  marker);
 
   /* If TO_REGISTER is set, register tha

[pph] Use REAL_IDENTIFIER_TYPE_VALUE instead of TREE_TYPE for IDENTIFIER_NODE (issue4965046)

2011-08-25 Thread Gabriel Charette
This was the last thing remaining on my cleanup list.

As suggested by Steven and Jason in issue4550121, we should use 
REAL_IDENTIFIER_TYPE_VALUE for IDENTIFIER_NODEs instead of TREE_TYPE (although 
the former resolves to the later in its macro definition, this is more robust 
to potential later changes to TREE_TYPE in trunk).
This patch does that change.

As mentionned by Steven in the same issue, we were accessing some fields 
directly instead of correctly using their corresponding accessor macros.
This patch makes use of the correct accessor macros for 
pph_read/write_tree_body.

There is no implementation change in this patch, every macro used resolves to 
what we it replaces, if anything this will make the pph code slightly more 
robust to trunk merges.

Tested with boostrap and pph regression testing on x64.

Cheers,
Gab

2011-08-25  Gabriel Charette  

* pph-streamer-in.c (pph_read_tree_body): Use accessor macros for
all fields. Use REAL_IDENTIFIER_TYPE_VALUE instead of TREE_TYPE
for the IDENTIFIER_NODE case.
* pph-streamer-out.c (pph_write_tree_body): Likewise.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index f37feaf..2fcb436 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -1826,14 +1826,11 @@ pph_read_tree_body (pph_stream *stream, tree expr)
   break;
 
 case IDENTIFIER_NODE:
-  {
-struct lang_identifier *id = LANG_IDENTIFIER_CAST (expr);
-id->namespace_bindings = pph_in_cxx_binding (stream);
-id->bindings = pph_in_cxx_binding (stream);
-id->class_template_info = pph_in_tree (stream);
-id->label_value = pph_in_tree (stream);
-   TREE_TYPE (expr) = pph_in_tree (stream);
-  }
+  IDENTIFIER_NAMESPACE_BINDINGS (expr) = pph_in_cxx_binding (stream);
+  IDENTIFIER_BINDING (expr) = pph_in_cxx_binding (stream);
+  IDENTIFIER_TEMPLATE (expr) = pph_in_tree (stream);
+  IDENTIFIER_LABEL_VALUE (expr) = pph_in_tree (stream);
+  REAL_IDENTIFIER_TYPE_VALUE (expr) = pph_in_tree (stream);
   break;
 
 case BASELINK:
@@ -1876,17 +1873,13 @@ pph_read_tree_body (pph_stream *stream, tree expr)
   break;
 
 case LAMBDA_EXPR:
-  {
-struct tree_lambda_expr *e
-= (struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (expr);
-pph_in_tree_common (stream, expr);
-   e->locus = pph_in_location (stream);
-e->capture_list = pph_in_tree (stream);
-e->this_capture = pph_in_tree (stream);
-e->return_type = pph_in_tree (stream);
-e->extra_scope = pph_in_tree (stream);
-e->discriminator = pph_in_uint (stream);
-  }
+  pph_in_tree_common (stream, expr);
+  LAMBDA_EXPR_LOCATION (expr) = pph_in_location (stream);
+  LAMBDA_EXPR_CAPTURE_LIST (expr) = pph_in_tree (stream);
+  LAMBDA_EXPR_THIS_CAPTURE (expr) = pph_in_tree (stream);
+  LAMBDA_EXPR_RETURN_TYPE (expr) = pph_in_tree (stream);
+  LAMBDA_EXPR_EXTRA_SCOPE (expr) = pph_in_tree (stream);
+  LAMBDA_EXPR_DISCRIMINATOR (expr) = pph_in_uint (stream);
   break;
 
 case TREE_VEC:
@@ -1899,15 +1892,12 @@ pph_read_tree_body (pph_stream *stream, tree expr)
   break;
 
 case TEMPLATE_PARM_INDEX:
-  {
-template_parm_index *p = TEMPLATE_PARM_INDEX_CAST (expr);
-pph_in_tree_common (stream, expr);
-p->index = pph_in_uint (stream);
-p->level = pph_in_uint (stream);
-p->orig_level = pph_in_uint (stream);
-p->num_siblings = pph_in_uint (stream);
-p->decl = pph_in_tree (stream);
-  }
+  pph_in_tree_common (stream, expr);
+  TEMPLATE_PARM_IDX (expr) = pph_in_uint (stream);
+  TEMPLATE_PARM_LEVEL (expr) = pph_in_uint (stream);
+  TEMPLATE_PARM_ORIG_LEVEL (expr) = pph_in_uint (stream);
+  TEMPLATE_PARM_NUM_SIBLINGS (expr) = pph_in_uint (stream);
+  TEMPLATE_PARM_DECL (expr) = pph_in_tree (stream);
   break;
 
 case DEFERRED_NOEXCEPT:
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index 3f7ac0c..27495e7 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -1612,14 +1612,11 @@ pph_write_tree_body (pph_stream *stream, tree expr)
   break;
 
 case IDENTIFIER_NODE:
-  {
-struct lang_identifier *id = LANG_IDENTIFIER_CAST (expr);
-pph_out_cxx_binding (stream, id->namespace_bindings);
-pph_out_cxx_binding (stream, id->bindings);
-pph_out_tree_1 (stream, id->class_template_info, 3);
-pph_out_tree_1 (stream, id->label_value, 3);
-   pph_out_tree_1 (stream, TREE_TYPE (expr), 3);
-  }
+  pph_out_cxx_binding (stream, IDENTIFIER_NAMESPACE_BINDINGS (expr));
+  pph_out_cxx_binding (stream, IDENTIFIER_BINDING (expr));
+  pph_out_tree_1 (stream, IDENTIFIER_TEMPLATE (expr), 3);
+  pph_out_tree_1 (stream, IDENTIFIER_LABEL_VALUE (expr), 3);
+  pph_out_tree_1 (st

Re: [pph] Detect #include outside the global context (issue4958045)

2011-08-25 Thread Gabriel Charette
I'm getting the following pph test failure output after this patch
(I'll commit my patch on top of it anyways as I get the same errors
with a clean build and with my patch, which itself had a clean test
output before this recent pull before my commit).

XPASS: g++.dg/pph/x7rtti.cc -fno-dwarf2-cfi-asm  -fpph-map=pph.map -I.
 (test for bogus messages, line )
XPASS: g++.dg/pph/x7rtti.cc -fno-dwarf2-cfi-asm  -fpph-map=pph.map -I.
 (test for bogus messages, line )
XPASS: g++.dg/pph/x7rtti.cc -fno-dwarf2-cfi-asm  -fpph-map=pph.map -I.
 (test for bogus messages, line )
XPASS: g++.dg/pph/x7rtti.cc -fno-dwarf2-cfi-asm  -fpph-map=pph.map -I.
 (test for bogus messages, line )
XPASS: g++.dg/pph/x7rtti.cc -fno-dwarf2-cfi-asm  -fpph-map=pph.map -I.
 (test for bogus messages, line )
XPASS: g++.dg/pph/x7rtti.cc -fno-dwarf2-cfi-asm  -fpph-map=pph.map -I.
 (test for bogus messages, line )
XPASS: g++.dg/pph/x7rtti.cc -fno-dwarf2-cfi-asm  -fpph-map=pph.map -I.
 (test for bogus messages, line )
XPASS: g++.dg/pph/x7rtti.cc -fno-dwarf2-cfi-asm  -fpph-map=pph.map -I.
 (test for bogus messages, line )
XPASS: g++.dg/pph/x7rtti.cc -fno-dwarf2-cfi-asm  -fpph-map=pph.map -I.
 (test for bogus messages, line )
XPASS: g++.dg/pph/x7rtti.cc -fno-dwarf2-cfi-asm  -fpph-map=pph.map -I.
 (test for bogus messages, line )
XPASS: g++.dg/pph/x7rtti.cc -fno-dwarf2-cfi-asm  -fpph-map=pph.map -I.
 (test for bogus messages, line )
XPASS: g++.dg/pph/x7rtti.cc -fno-dwarf2-cfi-asm  -fpph-map=pph.map -I.
 (test for bogus messages, line )
XPASS: g++.dg/pph/x7rtti.cc -fno-dwarf2-cfi-asm  -fpph-map=pph.map -I.
 (test for bogus messages, line )
# of expected passes336
# of unexpected successes   35
# of expected failures  45
# of unresolved testcases   1

Cheers,
Gab

On Thu, Aug 25, 2011 at 3:30 PM, Diego Novillo  wrote:
>
> To prevent PPH images from depend on the context in which they were
> generated, we require that the header file be compiled in isolation
> and when included, it should only be included in the global context.
> That is, things like
>
> namespace Foo {
>    #include "bar.h"
>    ...
> };
>
> should prevent bar.h from becoming a PPH image, since all the symbols
> defined in it would belong to Foo, but when bar.pph was generated,
> they belonged to ::
>
> This patch detects the use of PPH images inside nested scopes like
> that.  It is a bit crude, but it works.  During lexing, it keeps track
> of open and close braces (all kinds, not just { }), so when the
> #include command is found, it rejects the image if the nesting level
> is positive.
>
> Jason, I added a field to scope_chain.  That seemed the cleaner
> approach to keep track of the nesting level.  Is that a good place to
> keep track of it?  This is the kind of bookkeeping that scope_chain
> seems to be used for, but I can put it elsewhere if you want.
>
> This error flagged the usage of sys/types.pph.  This file is included
> inside 'extern "C" { }', so strictly speaking it should be rejected.
> We can relax these restrictions later.
>
>
> Tested on x86_64.  Applied to branch.
>
>
>        * cp-tree.h (struct saved_scope): Add field x_brace_nesting.
>        * parser.c (cp_lexer_token_is_open_brace): New.
>        (cp_lexer_token_is_close_brace): New.
>        (cp_lexer_get_preprocessor_token): Call them.
>        Increase scope_chain->x_brace_nesting for open braces, decrease
>        for closing braces.
>        * pph.c (pph_is_valid_here): New.  Return false if
>        scope_chain->x_brace_nesting is greater than 0.
>        (pph_include_handler): Call it.
>
>
> testsuite/ChangeLog.pph
>
>        * g++.dg/pph/pph.exp: Do not create a PPH image for sys/types.h.
>        * g++.dg/pph/y8inc-nmspc.cc: Mark fixed.
>
> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
> index 8fb2ccc..e0b67c6 100644
> --- a/gcc/cp/cp-tree.h
> +++ b/gcc/cp/cp-tree.h
> @@ -973,6 +973,10 @@ struct GTY(()) saved_scope {
>   cp_binding_level *bindings;
>
>   struct saved_scope *prev;
> +
> +  /* Used during lexing to validate where PPH images are included, it
> +     keeps track of nested bracing.  */
> +  unsigned x_brace_nesting;
>  };
>
>  /* The current open namespace.  */
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index 009922e..919671c 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -748,6 +748,31 @@ cp_lexer_saving_tokens (const cp_lexer* lexer)
>   return VEC_length (cp_token_position, lexer->saved_tokens) != 0;
>  }
>
> +
> +/* Return true if TOKEN is one of CPP_OPEN_SQUARE, CPP_OPEN_BRACE or
> +   CPP_OPEN_PAREN.  */
> +
> +static inline bool
> +cp_lexer_token_is_open_brace (cp_token *token)
> +{
> +  return token->type == CPP_OPEN_SQUARE
> +        || token->type == CPP_OPEN_BRACE
> +        || token->type == CPP_OPEN_PAREN;
> +}
> +
> +
> +/* Return true if TOKEN is one of CPP_CLOSE_SQUARE, CPP_CLOSE_BRACE or
> +   CPP_CLOSE_PAREN.  */
> +
> +static inline bool
> +cp_lexer_token_is_close_brace (cp_token *token)
> +{
> +  return token->type == CPP_

Re: [pph] Fix method lookups (part 1) (issue4997042)

2011-09-10 Thread Gabriel Charette
On Fri, Sep 9, 2011 at 4:37 PM, Diego Novillo  wrote:
>
> The main problem fixed here is that name lookups for class methods
> uses a binary search that assumes that the methods in
> CLASSTYPE_METHOD_VEC are sorted by pointer value.
>
> Since the reader typically allocates trees in a different pattern than
> the writer, it is common for the symbols in the vector to have
> different pointer values, so the order used by the writer is different
> than the reader.
>
> This was causing us to fail name lookups when generating the pph image
> for x6dynarray5.h and x6dynarray6.h.
>
> To fix this, I am making finish_struct_methods an extern function and
> calling it after reading a type that has a CLASSTYPE_METHOD_VEC.
>
> This exposed another failure that was simple enough to roll in
> together with this patch.  We should not emit preloaded symbols when
> writing the names in the global namespace.  This was causing a
> DECL_CHAIN cycle.  I added a new filter PPHF_NO_PREFS to skip the
> preloaded symbols when needed.
>

The loop in the DECL_CHAIN in x6dynarray5 was already there before.
This is why I had introduced the preloaded cache to do something along
those lines.

However I don't think simply filtering it out is sufficient in this
case. The reason there is a loop in this case if I recall correctly is
that "new" (amongst others) is overloaded in #include . i.e. it
used to be filtered by PPHF_NO_BUILTINS, but the overload clears the
BUILTIN_LOCATION and thus the builtins filter doesn't filter new out
anymore (but the pointer itself didn't change, so yes filtering PREFs
WILL filter it out, but it will also ignore the overload and load the
old PREF on the way in, not the new "new" overloaded by the include).

By not filtering it out however we create a loop: as, since the
pointer itself hasn't changed, we output the PREF (because we get a
preloaded cache hit), so either way we loose the overload and if not
filtering it out create a loop on the way in, but what we really need
is to output the overload and correctly re-push_overloaded_decl (or
something that has the same effect) on the way in.

Anyways, just can't help it, but keep reading all the patches coming in :)!

Cheers,
Gab


Re: [pph] Do not read pph files more than once (issue4983055)

2011-09-12 Thread Gabriel Charette
Oops forgot to reply all the first time...

On Fri, Sep 9, 2011 at 4:54 PM, Diego Novillo  wrote:
> This was not causing any failures, but it is pretty wasteful to read
> the same PPH more than once.
>
> We cannot just skip them, however.  We need to read the line table to
> properly modify the line table for the current translation unit.

I don't think that's right. If the header is not re-read (i.e. ifdef
guarded out), it should not show in the line_table either. I think you
simply want to do this check at the top of pph_read_file itself.

>
>  /* Read PPH file FILENAME.  Return the in-memory pph_stream instance.  */
>
> -pph_stream *
> +void
>  pph_read_file (const char *filename)
>  {
>   pph_stream *stream;
> @@ -1667,7 +1696,7 @@ pph_read_file (const char *filename)
>   else
> error ("Cannot open PPH file for reading: %s: %m", filename);
>
> -  return stream;
> +  pph_add_read_image (stream);
>  }

This needs to be after the check for an already read image I think
(having it here wouldn't create test failures, but would create
duplicate entries for skipped headers (as right now they are still
added to pph_read_images when skipped I think)).

Cheers!,
Gab

On Fri, Sep 9, 2011 at 4:54 PM, Diego Novillo  wrote:
> This was not causing any failures, but it is pretty wasteful to read
> the same PPH more than once.
>
> We cannot just skip them, however.  We need to read the line table to
> properly modify the line table for the current translation unit.
>
> Tested on x86_64.  Committed to branch.
>
>
> Diego.
>
>
>        * pph-streamer-in.c (pph_image_already_read): New.
>        (pph_read_file_1): Call pph_image_already_read.  If it returns
>        true, return after reading the line table.
>        (pph_add_read_image): New.
>        (pph_read_file): Change return value to void.  Update all callers.
>        Call pph_add_read_image.
>        * pph-streamer-out.c (pph_add_include): Remove second argument.
>        Update all callers.
>        Do not add INCLUDE to pph_read_images.
>        * pph-streamer.h (pph_add_include): Update prototype.
>
> diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
> index b111850..ea44460 100644
> --- a/gcc/cp/pph-streamer-in.c
> +++ b/gcc/cp/pph-streamer-in.c
> @@ -1462,7 +1462,6 @@ pph_in_include (pph_stream *stream)
>  {
>   int old_loc_offset;
>   const char *include_name;
> -  pph_stream *include;
>   source_location prev_start_loc = pph_in_source_location (stream);
>
>   /* Simulate highest_location to be as it would be at this point in a non-pph
> @@ -1475,8 +1474,7 @@ pph_in_include (pph_stream *stream)
>   old_loc_offset = pph_loc_offset;
>
>   include_name = pph_in_string (stream);
> -  include = pph_read_file (include_name);
> -  pph_add_include (include, false);
> +  pph_read_file (include_name);
>
>   pph_loc_offset = old_loc_offset;
>  }
> @@ -1583,6 +1581,23 @@ pph_in_line_table_and_includes (pph_stream *stream)
>  }
>
>
> +/* If FILENAME has already been read, return the stream associated with it.  
> */
> +
> +static pph_stream *
> +pph_image_already_read (const char *filename)
> +{
> +  pph_stream *include;
> +  unsigned i;
> +
> +  /* FIXME pph, implement a hash map to avoid this linear search.  */
> +  FOR_EACH_VEC_ELT (pph_stream_ptr, pph_read_images, i, include)
> +    if (strcmp (include->name, filename) == 0)
> +      return include;
> +
> +  return NULL;
> +}
> +
> +
>  /* Helper for pph_read_file.  Read contents of PPH file in STREAM.  */
>
>  static void
> @@ -1605,6 +1620,11 @@ pph_read_file_1 (pph_stream *stream)
>      read.  */
>   cpp_token_replay_loc = pph_in_line_table_and_includes (stream);
>
> +  /* If we have read STREAM before, we do not need to re-read the rest
> +     of its body.  We only needed to read its line table.  */
> +  if (pph_image_already_read (stream->name))
> +    return;
> +
>   /* Read all the identifiers and pre-processor symbols in the global
>      namespace.  */
>   pph_in_identifiers (stream, &idents_used);
> @@ -1650,13 +1670,22 @@ pph_read_file_1 (pph_stream *stream)
>      STREAM will need to be read again the next time we want to read
>      the image we are now generating.  */
>   if (pph_out_file && !pph_reading_includes)
> -    pph_add_include (stream, true);
> +    pph_add_include (stream);
> +}
> +
> +
> +/* Add STREAM to the list of read images.  */
> +
> +static void
> +pph_add_read_image (pph_stream *stream)
> +{
> +  VEC_safe_push (pph_stream_ptr, heap, pph_read_images, stream);
>  }
>
>
>  /* Read PPH file FILENAME.  Return the in-memory pph_stream instance.  */
>
> -pph_stream *
> +void
>  pph_read_file (const char *filename)
>  {
>   pph_stream *stream;
> @@ -1667,7 +1696,7 @@ pph_read_file (const char *filename)
>   else
>     error ("Cannot open PPH file for reading: %s: %m", filename);
>
> -  return stream;
> +  pph_add_read_image (stream);
>  }
>
>
> diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
> index 264294c..1a32814 100644
> --- a/gcc/cp/pph-streamer

Re: [pph] Remove XPASS noise from pph testsuite (issue4967063)

2011-09-12 Thread Gabriel Charette
Oops forgot to reply all...

On Mon, Sep 12, 2011 at 7:40 AM, Diego Novillo  wrote:
> This patch removes all the XPASS noise from pph.exp runs by pruning
> the output from the base compiles (thanks Ian for the pointer).  It
> add some comments as well.
>
> Lawrence, I noticed that we do not seem to need -I. -fno-dwarf2-cfi-asm
> anymore.  So, I removed them.  I'm not sure I remember exactly why you
> had added them, but since removing them produces no changes to the
> results, I just took them out.

This was a hack because Lawrence was getting different asm checksums
for the pph asm xdiff because his configuration would output some
additional dwarf2-cfi assembly. Thus, no single expected diff checksum
would work for both of us.

Cheers,
Gab


Re: [pph] Prepare for mutation detection [2/3] (issue5142049)

2011-09-28 Thread Gabriel Charette
More comments to come on [3/3], for now just a single comment below on
this specific patch:

> diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
> index 0bd4d64..b267833 100644
> --- a/gcc/cp/pph-streamer-in.c
> +++ b/gcc/cp/pph-streamer-in.c
> @@ -439,7 +439,10 @@ pph_in_cxx_binding_1 (pph_stream *stream)
>   if (marker == PPH_RECORD_END)
>     return NULL;
>   else if (pph_is_reference_marker (marker))
> -    return (cxx_binding *) pph_cache_get (&stream->cache, image_ix, ix, 
> marker);
> +    {
> +      pph_cache *cache = pph_cache_select (stream, marker, image_ix);
> +      return (cxx_binding *) pph_cache_get (cache, ix);
> +    }

Seems like you replaced the pph_cache_get one liners with these
two-liners. Wouldn't a simple inline function be nicer for this?

Gab


Re: [pph] Prepare for mutation detection [3/3] (issue5139052)

2011-09-28 Thread Gabriel Charette
Very nice!

I really like where this is heading :)!

I think it would be great to instrument this to know how many times we
need to use a PPH_RECORD_MREF, to avoid trashing the cache (i.e.
potentially there are specific cases where only a small field's value
changes and pickling the entire tree again is sub-optimal; if instead
we could detect those cases and simply output the required change
which could then be applied on the reader side it would potentially be
better... it is possible that we haven't been affected by these
specific cases up until now, but that they would all massively result
in PPH_RECORD_MREFs now (the instrumentation would also potentially
help us find some of those tricky mutation, if there are any caused by
other things than overloads, which we aren't aware of yet...just a
thought).

(or maybe even assert that those mutation are indeed overloads if we
think that's the only time it occurs??)

Cheers,
Gab

On Tue, Sep 27, 2011 at 1:03 PM, Diego Novillo  wrote:
>
> This finishes removing constants and builtins out of the cache.
> This time in a slightly more elegant way.
>
> The patch introduces a new version of pph_out_start_record exclusively
> for trees (pph_out_start_tree_record).  If the tree is not cacheable
> then it emits a PPH_RECORD_START_NO_CACHE record to indicate that the
> reader should not bother adding the tree to its cache.
>
> It also changes the semantics of pph_out_start_record.  It now returns
> true when the caller should do nothing else.
>
> We are now signing every DECL and TYPE tree we see, but doing nothing
> with this signature.  In the final patch this will change so we only
> sign DECLs/TYPEs after reading, if we are also generating a PPH image
> (pure readers do not need to care about mutations).
>
> Tested on x86_64.  Committed to branch.
>
>
>        * pph-streamer-in.c (pph_read_namespace_tree): Do not insert
>        constants in the cache.
>        * pph-streamer-out.c (pph_cache_should_handle): New.
>        (pph_out_start_ref_record): Factor out of ...
>        (pph_out_start_record): ... here.
>        Change return value meaning; true means 'all done'; false
>        means 'caller should write data out'.  Update all callers.
>        (pph_out_start_tree_record):  New.
>        (pph_write_builtin): Remove.  Update all users.
>        (pph_write_namespace_tree): Call pph_out_start_tree_record.
>        * pph-streamer.c (pph_cache_insert_at): Assert that we are
>        not trying to insert the same data more than once.
>        * pph-streamer.h (enum pph_record_marker): Add new value
>        PPH_RECORD_START_NO_CACHE.
>        (pph_in_record_marker): Handle it.
>
> diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
> index b267833..8e7c772 100644
> --- a/gcc/cp/pph-streamer-in.c
> +++ b/gcc/cp/pph-streamer-in.c
> @@ -2137,7 +2137,6 @@ pph_read_namespace_tree (pph_stream *stream, tree 
> enclosing_namespace)
>       /* For integer constants we only need the type and its hi/low
>         words.  */
>       expr = streamer_read_integer_cst (ib, data_in);
> -      pph_cache_insert_at (&stream->cache, expr, ix);
>     }
>   else
>     {
> diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
> index 7157275..2f9fcae 100644
> --- a/gcc/cp/pph-streamer-out.c
> +++ b/gcc/cp/pph-streamer-out.c
> @@ -182,14 +182,56 @@ pph_flush_buffers (pph_stream *stream)
>  }
>
>
> -/* Start a new record in STREAM for data in DATA.  If DATA is NULL
> -   write an end-of-record marker and return false.  If DATA is not NULL
> -   and did not exist in the pickle cache, add it, write a
> -   start-of-record marker and return true.  If DATA existed in the
> -   cache, write a shared-record marker and return false.  */
> +/* Return true if tree node T should be added to the pickle cache.  */
>
>  static inline bool
> -pph_out_start_record (pph_stream *stream, void *data)
> +pph_cache_should_handle (tree t)
> +{
> +  if (t)
> +    {
> +      if (TREE_CODE (t) == INTEGER_CST)
> +        {
> +          /* With the exception of some special constants that are
> +            pointer-compared everywhere (e.g., integer_zero_node), we
> +            do not want constants in the cache.  Their physical
> +            representation is smaller than a cache reference record
> +            and they can also trick the cache in similar ways to
> +            builtins (read below).  */
> +          return false;
> +        }
> +      else if (streamer_handle_as_builtin_p (t))
> +        {
> +          /* We do not want builtins in the cache for two reasons:
> +
> +            - They never need pickling.  Much like pre-loaded tree
> +              nodes, builtins are pre-built by the compiler and
> +              accessible with their class and code.
> +
> +            - They can trick the cache.  When possible, user-provided
> +              functions are generally replaced by their builtin
> +              counterparts (e.g., strcmp, malloc, etc).  When this
> +       

Re: [pph] Prepare for mutation detection [2/3] (issue5142049)

2011-09-28 Thread Gabriel Charette
On Wed, Sep 28, 2011 at 5:31 PM, Diego Novillo  wrote:
> On Wed, Sep 28, 2011 at 17:23, Gabriel Charette  wrote:
>> More comments to come on [3/3], for now just a single comment below on
>> this specific patch:
>>
>>> diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
>>> index 0bd4d64..b267833 100644
>>> --- a/gcc/cp/pph-streamer-in.c
>>> +++ b/gcc/cp/pph-streamer-in.c
>>> @@ -439,7 +439,10 @@ pph_in_cxx_binding_1 (pph_stream *stream)
>>>   if (marker == PPH_RECORD_END)
>>>     return NULL;
>>>   else if (pph_is_reference_marker (marker))
>>> -    return (cxx_binding *) pph_cache_get (&stream->cache, image_ix, ix, 
>>> marker);
>>> +    {
>>> +      pph_cache *cache = pph_cache_select (stream, marker, image_ix);
>>> +      return (cxx_binding *) pph_cache_get (cache, ix);
>>> +    }
>>
>> Seems like you replaced the pph_cache_get one liners with these
>> two-liners. Wouldn't a simple inline function be nicer for this?
>
> I call them separately.  Or do you mean a single call that combines
> them for the common case?
>

Yes that's what I mean, a single call that combines both, since that's
the common usage and I feel there should be as little cache code at
the top of every pph_* function (in particular, every time a new  pph
streaming function is added all that code needs to be "duplicated", so
the less code the better imo).


Re: [pph] Make libcpp symbol validation a warning (issue5235061)

2011-10-13 Thread Gabriel Charette
Just looked at the line_table related sections, but see comments below:

On Tue, Oct 11, 2011 at 4:26 PM, Diego Novillo  wrote:
>
> Currently, the consistency check done on pre-processor symbols is
> triggering on symbols that are not really problematic (e.g., symbols
> used for double-include guards).
>
> The problem is that in the testsuite, we are refusing to process PPH
> images that fail that test, which means we don't get to test other
> issues.  To avoid this, I changed the error() call to warning().  Seemed
> innocent enough, but there were more problems behind that one:
>
> 1- We do not really try to avoid reading PPH images more than once.
>   This problem is different than the usual double-inclusion guard.
>   For instance, suppose a file foo.pph includes 1.pph, 2.pph and
>   3.pph.  When generating foo.pph, we read all 3 files just once and
>   double-include guards do not need to trigger.  However, if we are
>   later building a TU with:
>        #include 2.pph
>        #include foo.pph
>   we first read 2.pph and when reading foo.pph, we try to read 2.pph
>   again, because it is mentioned in foo.pph's line map table.
>
>   I added a guard in pph_stream_open() so it doesn't try to open the
>   same file more than once, but that meant adjusting some of the
>   assertions while reading the line table.  We should not expect to
>   find foo.pph's line map table exactly like the one we wrote.

That makes sense.

> @@ -328,8 +327,6 @@ pph_in_line_table_and_includes (pph_stream *stream)
>   int entries_offset = line_table->used - PPH_NUM_IGNORED_LINE_TABLE_ENTRIES;
>   enum pph_linetable_marker next_lt_marker = pph_in_linetable_marker (stream);
>
> -  pph_reading_includes++;
> -
>   for (first = true; next_lt_marker != PPH_LINETABLE_END;
>        next_lt_marker = pph_in_linetable_marker (stream))
>     {
> @@ -373,19 +370,33 @@ pph_in_line_table_and_includes (pph_stream *stream)
>          else
>            lm->included_from += entries_offset;
>
> -         gcc_assert (lm->included_from < (int) line_table->used);
> -

This should still hold, it is impossible that included_from points to
an entry that doesn't exist (i.e. beyond line_table->used), but since
we recalculate it on the previous line, adding entries_offset, this
was just a safe check to make sure everything read makes sense.

>          lm->start_location += pph_loc_offset;
>
>          line_table->used++;
>        }
>     }
>
> -  pph_reading_includes--;
> +  /* We used to expect exactly the same number of entries, but files
> +     included from this PPH file may sometimes not be needed.  For
> +     example,
> +
> +       #include "2.pph"
> +       #include "foo.pph"
> +         +-->  #include "1.pph"
> +               #include "2.pph"
> +               #include "3.pph"
> +
> +     When foo.pph was originally created, the line table was built
> +     with inclusions of 1.pph, 2.pph and 3.pph.  But when compiling
> +     the main translation unit, we include 2.pph before foo.pph, so
> +     the inclusion of 2.pph from foo.pph does nothing.  Leaving the
> +     line table in a different shape than the original compilation.
>
> +     Instead of insisting on getting EXPECTED_IN entries, we expect at
> +     most EXPECTED_IN entries.  */
>   {
>     unsigned int expected_in = pph_in_uint (stream);
> -    gcc_assert (line_table->used - used_before == expected_in);
> +    gcc_assert (line_table->used - used_before <= expected_in);

I'm not sure exactly how you skip headers already parsed now (we
didn't used to when I wrote this code and that was the only problem
remaining in the line_table (i.e. duplicate entries for guarded
headers in the non-pph compile)), but couldn't you count the number of
skipped entries and assert (line_table->used - used_before) +
numSkipped == expected_in) ?

I'd have to re-download the code, I've bee following through patches,
but I'm not so sure now exactly how the "guarded headers skipping" is
done, my memorized knowledge of the codebase has diverged I feel..!

A more important note: I think it could be worth having a new flag
that outputs the line_table when done parsing (as a mean to robustly
test it). My way to test it usually was to breakpoint on
varpool_assemble_decl (a random choice, but it was only called after
parsing was done...), both in pph and non-pph compiles and compare the
line_table in gdb However, to have a stable test in the long run,
it could be nice to have a flag that asks for an output of the
line_table and then we could checksum and compare the line_table
outputted by the pph and non-pph compiles.

A good test I had found to break in and analyze the line_table was
p4eabi.h as it pretty much had all the problems that I fixed regarding
the line_table (it also has re-includes if I remember correctly, but
that wasn't a problem before as we would not guard out re-includes as
I just mentioned above).

Having such a robust test would be important I feel as, as we saw with
previous bugs, discrepa

Re: [pph] Remove all the -fpph flags and pph_catch_... calls that instrumented the incr compiler (issue4559070)

2011-06-02 Thread Gabriel Charette
(sorry about the triple-posting, just learnt this mailing list
required plain text emails... hopefully, this works now..)

Additional note: The patch was tested with a full bootstrap build and
regression testing (no new bugs introduced).

There might be header files that are now unused due to the code removed.

-Gab


[pph] Removing unused timevars following pph instrumentation removal patch (issue4568053)

2011-06-03 Thread Gabriel Charette
Removed the 3 PPH timevars used in pph instrumentation. Those are not used
anymore following the instrumentation removal patch.

Bootstrap build and regression testing were successful.

2011-06-03  Gabriel Charette  

* timevar.def (TV_PPH_CACHE_IN): Remove.
(TV_PPH_CACHE_OUT): Remove.
(TV_PPH_MANAGE): Remove.

Index: timevar.def
===
--- timevar.def (revision 174568)
+++ timevar.def (working copy)
@@ -69,11 +69,6 @@
 DEFTIMEVAR (TV_PTH_SKIP_TOKENS   , "PTH skip cached tokens")
 DEFTIMEVAR (TV_PTH_INIT  , "PTH initialization")
 
-/* Time spent handling PPH state.  */
-DEFTIMEVAR (TV_PPH_CACHE_IN  , "PPH cache in")
-DEFTIMEVAR (TV_PPH_CACHE_OUT , "PPH cache out")
-DEFTIMEVAR (TV_PPH_MANAGE, "PPH bookkeeping")
-
 DEFTIMEVAR (TV_CGRAPH, "callgraph construction")
 DEFTIMEVAR (TV_CGRAPHOPT , "callgraph optimization")
 DEFTIMEVAR (TV_VARPOOL   , "varpool construction")

--
This patch is available for review at http://codereview.appspot.com/4568053


[pph] Removing pth implementation from pph implementation (issue4571047)

2011-06-06 Thread Gabriel Charette
Removed all of the pth code with the exception of pth_save_token_cache 
and pth_load_token_cache and their respective closure.

The renaming of the remaining functions to pph will be done in a separate patch.

The patch was tested with a full bootstrap build and regression testing.

Note: There might be header files that are now unused due to the code removed.

2011-06-06  Gabriel Charette  

* gcc/c-family/c.opt (fpth): Remove. Update all users.
(fpth-debug): Likewise.
(fpth-stats). Likewise.
(fpth-md5). Likewise.
* gcc/cp/pph.c (pth_stats): Remove field. Update all users.
(pth_get_state): Remove. Update all users.
(pth_debug_identifiers): Likewise.
(pth_debug_token_hunks): Likewise.
(pth_debug_state): Likewise.
(pth_image_lookup): Likewise.
(pth_init): Likewise.
(pth_print_stats): Likewise.
(pth_finish): Likewise.
* gcc/cp/pph.h (struct pth_include): Likewise.
(struct pth_image): Likewise.
(struct pth_state): Likewise.
(PTH_STATS_INCR): Likewise.
* gcc/timevar.def (TV_PTH_DEPENDENCY): Likewise.
(TV_PTH_MANAGE): Likewise.
(TV_PTH_MD5): Likewise.
(TV_PTH_LOAD): Likewise.
(TV_PTH_SAVE): Likewise.
(TV_PTH_SKIP_TOKENS): Likewise.
(TV_PTH_INIT): Likewise.


Index: gcc/c-family/c.opt
===
--- gcc/c-family/c.opt  (revision 174725)
+++ gcc/c-family/c.opt  (working copy)
@@ -961,22 +961,6 @@
 C++ ObjC++ Var(flag_pretty_templates) Init(1)
 -fno-pretty-templates Do not pretty-print template specializations as the 
template signature followed by the arguments
 
-fpth
-C++ Var(flag_pth)
--fpth  Enable pre-tokenized header (PTH) support
-
-fpth-debug=
-C++ Joined RejectNegative UInteger Var(flag_pth_debug)
--fpth-debug=N  Enable debugging output at level N from PTH support
-
-fpth-stats
-C++ Var(flag_pth_stats)
--fpth-statsEnable statistics gathering for PTH
-
-fpth-md5
-C++ Var(flag_pth_md5)
--fpth-md5   Use MD5 digests instead of timestamps to determine if a header 
file has changed
-
 freplace-objc-classes
 ObjC ObjC++ Var(flag_replace_objc_classes)
 Used in Fix-and-Continue mode to indicate that object files may be swapped in 
at runtime
Index: gcc/c-family/c-opts.c
===
--- gcc/c-family/c-opts.c   (revision 174725)
+++ gcc/c-family/c-opts.c   (working copy)
@@ -1226,12 +1226,6 @@
 {
   FILE *deps_stream = NULL;
 
-  /* FIXME.  Hack!  When using a PTH image, we did not allow the 
- pre-processor to keep track of dependencies, so we cannot
- write them out.  */
-  if (flag_pth)
-return;
-
   /* Don't write the deps file if there are errors.  */
   /* FIXME.  We are emitting the deps file even if there were errors.
  This is a temporary workaround to avoid confusing Google's build
Index: gcc/cp/pph.c
===
--- gcc/cp/pph.c(revision 174725)
+++ gcc/cp/pph.c(working copy)
@@ -38,159 +38,10 @@
 #include "pph.h"
 #include "pph-streamer.h"
 
-/* Statistics collected for PTH.  */
-struct pth_stats_d pth_stats;
-
 /* Log file where PPH analysis is written to.  Controlled by
-fpph_logfile.  If this flag is not given, stdout is used.  */
 FILE *pph_logfile = NULL;
 
-
-/* Return true if path P1 and path P2 point to the same file.  */
-
-static inline bool
-pathnames_equal_p (const char *p1, const char *p2)
-{
-  return strcmp (lrealpath (p1), lrealpath (p2)) == 0;
-}
-
-/* Hash and comparison functions for the directory of cached images.  */
-
-static hashval_t
-pth_image_dir_hash (const void *p)
-{
-  const char *s = lrealpath (((const pth_image *)p)->fname);
-  return htab_hash_string (s);
-}
-
-
-static int
-pth_image_dir_eq (const void *p1, const void *p2)
-{
-  const char *s1 = ((const pth_image *)p1)->fname;
-  const char *s2 = ((const pth_image *)p2)->fname;
-  return pathnames_equal_p (s1, s2);
-}
-
-
-static GTY(()) pth_state *pth_global_state = NULL;
-
-/* Return the global PTH state where the cache and its directory
-   are stored.  */
-
-pth_state *
-pth_get_state (void)
-{
-  if (pth_global_state == NULL)
-{
-  pth_global_state = ggc_alloc_cleared_pth_state ();
-  pth_global_state->cache_dir = htab_create_ggc (10, pth_image_dir_hash,
-pth_image_dir_eq, NULL);
-}
-
-  return pth_global_state;
-}
-
-
-/* Return an identification string for a PTH image.  */
-
-static const char *
-pth_id_str (void)
-{
-  /* FIXME pph - Build a better identification string.  */
-  return "PTH0x42";
-}
-
-
-/* Return the number of bytes taken by the header of a PTH image.  */
-
-static size_t
-pth_header_len (void)
-{
-  /* The header of a PTH image contains:
-   - An identification str

[pph] Stream TREE_TYPE for identifier node (issue4550121)

2011-06-07 Thread Gabriel Charette
We need to stream TREE_TYPE for identifier node.

This fixes some ICEs, but introduces some new assembly mismatch errors.

Here is the testing diff:
47,49d46
< XPASS: g++.dg/pph/x1autometh.cc  -fpph-map=pph.map -I.  (test for bogus 
messages, line )
< XPASS: g++.dg/pph/x1autometh.cc  -fpph-map=pph.map -I. (test for excess 
errors)
< FAIL: g++.dg/pph/x1autometh.cc  (assembly mismatch)
51c48
< XPASS: g++.dg/pph/x1functions.cc  -fpph-map=pph.map -I. (test for excess 
errors)
---
> XPASS: g++.dg/pph/x1functions.cc  -I.  (test for bogus messages, line )
53,54d49
< XPASS: g++.dg/pph/x1special.cc  -fpph-map=pph.map -I.  (test for bogus 
messages, line )
< XPASS: g++.dg/pph/x1special.cc  -fpph-map=pph.map -I. (test for excess errors)
62d56
< XPASS: g++.dg/pph/x1typerefs.cc  -fpph-map=pph.map -I.  (test for bogus 
messages, line )
70,74c64,68
< # of expected passes  174
< # of unexpected failures  2
< # of unexpected successes 21
< # of expected failures37
< /usr/local/google/gchare/gcc/dbg/gcc/testsuite/g++/../../g++  version 
4.7.0-pph 20110606 (experimental) (GCC) 
---
> # of expected passes  177
> # of unexpected failures  1
> # of unexpected successes 16
> # of expected failures46
> /usr/local/google/gchare/gcc-clean/bld/gcc/testsuite/g++/../../g++  version 
> 4.7.0-pph 20110606 (experimental) (GCC)

2011-06-07  Gabriel Charette  

* gcc/cp/pph-streamer-in.c (pph_read_tree): 
Read TREE_TYPE from id_node.
* gcc/cp/pph-streamer-out.c (pph_write_tree):
Write TREE_TYPE from id_node.
* gcc/testsuite/g++.dg/pph/x1functions.cc (dg-xfail-if "ICE"): Remove.
(dg-xfail-if "ERROR"): Add.

Index: gcc/cp/pph-streamer-in.c
===
--- gcc/cp/pph-streamer-in.c(revision 174760)
+++ gcc/cp/pph-streamer-in.c(working copy)
@@ -1027,6 +1027,7 @@
 id->bindings = pph_in_cxx_binding (stream);
 id->class_template_info = pph_in_tree (stream);
 id->label_value = pph_in_tree (stream);
+   TREE_TYPE (expr) = pph_in_tree (stream);
   }
   break;
 
Index: gcc/cp/pph-streamer-out.c
===
--- gcc/cp/pph-streamer-out.c   (revision 174760)
+++ gcc/cp/pph-streamer-out.c   (working copy)
@@ -983,6 +983,7 @@
 pph_out_cxx_binding (stream, id->bindings, ref_p);
 pph_out_tree_or_ref_1 (stream, id->class_template_info, ref_p, 3);
 pph_out_tree_or_ref_1 (stream, id->label_value, ref_p, 3);
+   pph_out_tree_or_ref_1 (stream, TREE_TYPE (expr), ref_p, 3);
   }
   break;
 
Index: gcc/testsuite/g++.dg/pph/x1functions.cc
===
--- gcc/testsuite/g++.dg/pph/x1functions.cc (revision 174760)
+++ gcc/testsuite/g++.dg/pph/x1functions.cc (working copy)
@@ -1,6 +1,5 @@
-// { dg-xfail-if "ICE" { "*-*-*" } { "-fpph-map=pph.map" } }
+// { dg-xfail-if "ERROR" { "*-*-*" } { "-fpph-map=pph.map" } }
 // { dg-bogus "'mbr_decl_inline' was not declared in this scope" "" { xfail 
*-*-* } 0 }
-// { dg-bogus "c1functions.h:8:34: internal compiler error: Segmentation 
fault" "" { xfail *-*-* } 0 }
 // { dg-prune-output "In file included from " }
 // { dg-prune-output "In member function " }
 // { dg-prune-output "At global scope:" }

--
This patch is available for review at http://codereview.appspot.com/4550121


[pph] Rename pph_output__tree_header to respect naming convention (issue4528135)

2011-06-09 Thread Gabriel Charette
This was probably introduced in sync with my renaming patch. Just noticed and 
fixed it.

There isn't the equivalent pph_input function, is that normal?

Index: pph-streamer.c
===
--- pph-streamer.c  (revision 174853)
+++ pph-streamer.c  (working copy)
@@ -96,7 +96,7 @@
   streamer_hooks.indexable_with_decls_p = pph_indexable_with_decls_p;
   streamer_hooks.unpack_value_fields = pph_unpack_value_fields;
   streamer_hooks.alloc_tree = pph_alloc_tree;
-  streamer_hooks.output_tree_header = pph_output_tree_header;
+  streamer_hooks.output_tree_header = pph_out_tree_header;
   streamer_hooks.has_unique_integer_csts_p = true;
 }
 
Index: pph-streamer-out.c
===
--- pph-streamer-out.c  (revision 174853)
+++ pph-streamer-out.c  (working copy)
@@ -838,7 +838,7 @@
OB.  If EXPR does not need to be handled specially, do nothing.  */
 
 void
-pph_output_tree_header (struct output_block *ob, tree expr)
+pph_out_tree_header (struct output_block *ob, tree expr)
 {
   pph_stream *stream = (pph_stream *) ob->sdata;
 
Index: pph-streamer.h
===
--- pph-streamer.h  (revision 174853)
+++ pph-streamer.h  (working copy)
@@ -142,7 +142,7 @@
 void pph_init_write (pph_stream *);
 void pph_write_tree (struct output_block *, tree, bool ref_p);
 void pph_pack_value_fields (struct bitpack_d *, tree);
-void pph_output_tree_header (struct output_block *, tree);
+void pph_out_tree_header (struct output_block *, tree);
 void pph_out_chain_filtered (pph_stream *, tree, bool, enum chain_filter);
 
 /* In name-lookup.c.  */
Index: ChangeLog.pph
===
--- ChangeLog.pph   (revision 174853)
+++ ChangeLog.pph   (working copy)
@@ -1,3 +1,8 @@
+2011-06-09  Gabriel Charette  
+
+   * pph-streamer-out.c (pph_out_tree_header): Rename from
+ pph_output_tree_header. Update all users.
+
 2011-06-08   Diego Novillo  
 
* parser.c (cp_lexer_dump_tokens): If START_TOKEN is NULL,

--
This patch is available for review at http://codereview.appspot.com/4528135


[pph] pph_in_binding_level fixing shadowed_labels read (issue4589054)

2011-06-14 Thread Gabriel Charette
We weren't reading in shadowed labels properly.

The local variable *sl also turned out to be useless, the compiler just didn't
mention it until now as it was "used" by the bad VEC_iterate call.

This doesn't fix any currently exposed pph bugs, but does help with me with
the patch I'm currently writting.

This was tested with a bootstrap build and pph regression testing.


2011-06-14  Gabriel Charette  

* pph-streamer-in.c (pph_in_binding_level): Fix read
of shadowed_labels.
(pph_in_binding_level): Removed *sl.

Index: pph-streamer-in.c
===
--- pph-streamer-in.c   (revision 174998)
+++ pph-streamer-in.c   (working copy)
@@ -427,7 +427,6 @@
 pph_in_binding_level (pph_stream *stream)
 {
   unsigned i, num, ix;
-  cp_label_binding *sl;
   struct cp_binding_level *bl;
   struct bitpack_d bp;
   enum pph_record_marker marker;
@@ -461,7 +460,7 @@
 
   num = pph_in_uint (stream);
   bl->shadowed_labels = NULL;
-  for (i = 0; VEC_iterate (cp_label_binding, bl->shadowed_labels, i, sl); i++)
+  for (i = 0; i < num; i++)
 {
   cp_label_binding *sl = pph_in_label_binding (stream);
   VEC_safe_push (cp_label_binding, gc, bl->shadowed_labels, sl);

--
This patch is available for review at http://codereview.appspot.com/4589054


[pph] Fix cxx_binding streaming logic (issue4646041)

2011-06-16 Thread Gabriel Charette
We were losing bindings when reassigning prev bindings with the current
streaming logic.

This doesn't fix any currently exposed bugs, but again helps me as part of
fixing the bigger bug I'm on.

Tested with bootstrap build and pph regression testing.

At the end of pph_out_cxx_binding I could also simply do 
pph_out_uchar (stream, PPH_RECORD_END);
instead of
pph_out_cxx_binding_1 (stream, NULL, ref_p);
which has the exact same effect.

I just thought it might clearer to the reader and also more robust code
if we eventually decide to change the way caching works internally.

2011-06-16  Gabriel Charette  

* gcc/cp/pph-streamer-in.c (pph_in_cxx_binding): Fix streaming logic.
* gcc/cp/pph-streamer-out.c (pph_out_cxx_binding): Fix streaming logic.

Index: gcc/cp/pph-streamer-in.c
===
--- gcc/cp/pph-streamer-in.c(revision 175106)
+++ gcc/cp/pph-streamer-in.c(working copy)
@@ -353,24 +353,18 @@
 static cxx_binding *
 pph_in_cxx_binding (pph_stream *stream)
 {
-  unsigned i, num_bindings;
-  cxx_binding *curr, *cb;
+  cxx_binding *curr, *prev, *cb;
 
+  /* Read the current binding first.  */
+  cb = pph_in_cxx_binding_1 (stream);
+
   /* Read the list of previous bindings.  */
-  num_bindings = pph_in_uint (stream);
-  for (curr = NULL, i = 0; i < num_bindings; i++)
+  for (curr = cb; curr; curr = prev)
 {
-  cxx_binding *prev = pph_in_cxx_binding_1 (stream);
-  if (curr)
-   curr->previous = prev;
-  curr = prev;
+  prev = pph_in_cxx_binding_1 (stream);
+  curr->previous = prev;
 }
 
-  /* Read the current binding at the end.  */
-  cb = pph_in_cxx_binding_1 (stream);
-  if (cb)
-cb->previous = curr;
-
   return cb;
 }
 
Index: gcc/cp/pph-streamer-out.c
===
--- gcc/cp/pph-streamer-out.c   (revision 175106)
+++ gcc/cp/pph-streamer-out.c   (working copy)
@@ -339,21 +339,18 @@
 static void
 pph_out_cxx_binding (pph_stream *stream, cxx_binding *cb, bool ref_p)
 {
-  unsigned num_bindings;
   cxx_binding *prev;
 
-  num_bindings = 0;
-  for (prev = cb ? cb->previous : NULL; prev; prev = prev->previous)
-num_bindings++;
+  /* Write the current binding first.  */
+  pph_out_cxx_binding_1 (stream, cb, ref_p);
 
   /* Write the list of previous bindings.  */
-  pph_out_uint (stream, num_bindings);
-  if (num_bindings > 0)
-for (prev = cb->previous; prev; prev = prev->previous)
-  pph_out_cxx_binding_1 (stream, prev, ref_p);
+  for (prev = cb ? cb->previous : NULL; prev; prev = prev->previous)
+pph_out_cxx_binding_1 (stream, prev, ref_p);
 
-  /* Write the current binding at the end.  */
-  pph_out_cxx_binding_1 (stream, cb, ref_p);
+  /* Mark the end of the list (if there was a list).  */
+  if (cb)
+pph_out_cxx_binding_1 (stream, NULL, ref_p);
 }
 
 

--
This patch is available for review at http://codereview.appspot.com/4646041


[pph] Initialize cache_ix in all paths in pph_start_record (issue4642045)

2011-06-17 Thread Gabriel Charette
Read the comment in the diff for all the details.

I found this while working on my current patch, adding some assertion at the
end of the function would create a new build error and moving it around in the
function would stop showing the error.

I discussed this with Collin and Jeff and it appears that the compiler
changes it's inlining decisions based on very picky details. In this particular
case, inlining the function resulted in an error.

Tested with bootstrap build and pph regression testing.

2011-06-17  Gabriel Charette  

* gcc/cp/pph-streamer-in.c (pph_start_record):
Initialize cache_ix in all paths.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index b3c2ac9..186100f 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -204,7 +204,15 @@ pph_start_record (pph_stream *stream, unsigned *cache_ix)
   if (marker == PPH_RECORD_START || marker == PPH_RECORD_SHARED)
 *cache_ix = pph_in_uint (stream);
   else
-gcc_assert (marker == PPH_RECORD_END);
+{
+  gcc_assert (marker == PPH_RECORD_END);
+  /* Initialize CACHE_IX to an invalid index. Even though this
+is never used in practice, the compiler will throw an error
+if the optimizer inlines this function and discards the asserts
+in a given build as it will complain that " 'ix' may be used
+unititialized".  */
+  *cache_ix = -1;
+}
 
   return marker;
 }

--
This patch is available for review at http://codereview.appspot.com/4642045


[pph] Rename two pph_start_record functions adding in/out. (issue4629049)

2011-06-17 Thread Gabriel Charette
There were two pph_start_record functions, one for the in part, one for the out
part. I renamed them to have different names to avoid confusion for the reader
(and it also makes it easier for tags).

2011-06-17  Gabriel Charette  

* gcc/cp/pph-streamer-in.c (pph_in_start_record): 
Rename from pph_start_record. Update all users.
* gcc/cp/pph-streamer-out.c (pph_out_start_record): 
Rename from pph_start_record. Update all users.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index b3c2ac9..cd611c7 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -192,7 +192,7 @@ pph_init_read (pph_stream *stream)
materialized structure.  */
 
 static inline enum pph_record_marker
-pph_start_record (pph_stream *stream, unsigned *cache_ix)
+pph_in_start_record (pph_stream *stream, unsigned *cache_ix)
 {
   enum pph_record_marker marker;
 
@@ -211,7 +211,7 @@ pph_start_record (pph_stream *stream, unsigned *cache_ix)
 
 
 /* Return a shared pointer from the streamer cache in STREAM.  This is
-   called when pph_start_record returns PPH_RECORD_SHARED.  It means
+   called when pph_in_start_record returns PPH_RECORD_SHARED.  It means
that the data structure we are about to read has been instantiated
before and is present in the streamer cache.  */
 
@@ -330,7 +330,7 @@ pph_in_cxx_binding_1 (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -378,7 +378,7 @@ pph_in_class_binding (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -401,7 +401,7 @@ pph_in_label_binding (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -425,7 +425,7 @@ pph_in_binding_level (pph_stream *stream)
   struct bitpack_d bp;
   enum pph_record_marker marker;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -495,7 +495,7 @@ pph_in_c_language_function (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -521,7 +521,7 @@ pph_in_language_function (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -614,7 +614,7 @@ pph_in_struct_function (pph_stream *stream)
 
   gcc_assert (stream->data_in != NULL);
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
 
@@ -713,7 +713,7 @@ pph_in_lang_specific (pph_stream *stream, tree decl)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return;
 
@@ -828,7 +828,7 @@ pph_in_sorted_fields_type (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -908,7 +908,7 @@ pph_in_lang_type_class (pph_stream *stream,
   ltc->typeinfo_var = pph_in_tree (stream);
   ltc->vbases = pph_in_tree_vec (stream);
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_START)
 {
   ltc->nested_udts = pph_in_binding_table (stream);
@@ -950,7 +950,7 @@ pph_in_lang_type (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index 49847a9..83e90c3 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -200,7 +200,7 @@ pph_flush_buffers (pph_stream *stream)
cache, write a shared-record marker and return false.  */
 
 static inline bool
-pph

[pph] Rename two pph_start_record functions adding in/out. (issue4629049)

2011-06-17 Thread Gabriel Charette
Updating the first version of this patch (I accidently sent an old patch with
the renaming backwards).

There were two pph_start_record functions, one for the in part, one for the out
part. I renamed them to have different names to avoid confusion for the reader
(and it also makes it easier for tags).

2011-06-17  Gabriel Charette  

* gcc/cp/pph-streamer-in.c (pph_in_start_record): 
Rename from pph_start_record. Update all users.
* gcc/cp/pph-streamer-out.c (pph_out_start_record): 
Rename from pph_start_record. Update all users.

Index: gcc/cp/pph-streamer-in.c
diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index b3c2ac9..cd611c7 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -192,7 +192,7 @@ pph_init_read (pph_stream *stream)
materialized structure.  */
 
 static inline enum pph_record_marker
-pph_start_record (pph_stream *stream, unsigned *cache_ix)
+pph_in_start_record (pph_stream *stream, unsigned *cache_ix)
 {
   enum pph_record_marker marker;
 
@@ -211,7 +211,7 @@ pph_start_record (pph_stream *stream, unsigned *cache_ix)
 
 
 /* Return a shared pointer from the streamer cache in STREAM.  This is
-   called when pph_start_record returns PPH_RECORD_SHARED.  It means
+   called when pph_in_start_record returns PPH_RECORD_SHARED.  It means
that the data structure we are about to read has been instantiated
before and is present in the streamer cache.  */
 
@@ -330,7 +330,7 @@ pph_in_cxx_binding_1 (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -378,7 +378,7 @@ pph_in_class_binding (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -401,7 +401,7 @@ pph_in_label_binding (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -425,7 +425,7 @@ pph_in_binding_level (pph_stream *stream)
   struct bitpack_d bp;
   enum pph_record_marker marker;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -495,7 +495,7 @@ pph_in_c_language_function (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -521,7 +521,7 @@ pph_in_language_function (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -614,7 +614,7 @@ pph_in_struct_function (pph_stream *stream)
 
   gcc_assert (stream->data_in != NULL);
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
 
@@ -713,7 +713,7 @@ pph_in_lang_specific (pph_stream *stream, tree decl)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return;
 
@@ -828,7 +828,7 @@ pph_in_sorted_fields_type (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
@@ -908,7 +908,7 @@ pph_in_lang_type_class (pph_stream *stream,
   ltc->typeinfo_var = pph_in_tree (stream);
   ltc->vbases = pph_in_tree_vec (stream);
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_START)
 {
   ltc->nested_udts = pph_in_binding_table (stream);
@@ -950,7 +950,7 @@ pph_in_lang_type (pph_stream *stream)
   enum pph_record_marker marker;
   unsigned ix;
 
-  marker = pph_start_record (stream, &ix);
+  marker = pph_in_start_record (stream, &ix);
   if (marker == PPH_RECORD_END)
 return NULL;
   else if (marker == PPH_RECORD_SHARED)
Index: gcc/cp/pph-streamer-out.c
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index 49847a9..83e90c3 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc

[pph] Initialize cache_ix in all paths in pph_start_record (issue4642045)

2011-06-17 Thread Gabriel Charette
Clarified comment from v1 of this patch.

2011-06-17  Gabriel Charette  

* gcc/cp/pph-streamer-in.c (pph_start_record):
Initialize cache_ix in all paths.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index b3c2ac9..186100f 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -204,7 +204,15 @@ pph_start_record (pph_stream *stream, unsigned *cache_ix)
   if (marker == PPH_RECORD_START || marker == PPH_RECORD_SHARED)
 *cache_ix = pph_in_uint (stream);
   else
-gcc_assert (marker == PPH_RECORD_END);
+{
+  gcc_assert (marker == PPH_RECORD_END);
+  /* Initialize CACHE_IX to an invalid index. Even though this
+is never used in practice, the compiler will throw an error
+if the optimizer inlines this function in a given build as
+it will complain that " 'ix' may be used uninitialized".  */
+  *cache_ix = -1;
+}
 
   return marker;
 }

--
This patch is available for review at http://codereview.appspot.com/4642045


[pph] Fix binding_level's names_size streaming (issue4634071)

2011-06-20 Thread Gabriel Charette
We were streaming out the original names_size which includes the
built-in names which are not streamed out.

This only streams out the actual number of streamed names as names_size.

It appears names_size is not even used anywhere in the code
(or at least I couldn't find any use of it with `grep "names_size" -R gcc/`.
Should we just remove it?

This doesn't fix any currently failing pph tests.

Tested with bootstrap build and pph regression testing.

2011-06-20  Gabriel Charette  

* gcc/cp/pph-streamer-out.c (pph_count_filter_match): Added.
(pph_out_chain_filtered): Use pph_count_filter_match.
(pph_out_binding_level): Use pph_count_filter_match.
(pph_out_lang_specific): Fixed space typo.
(pph_write_tree): Fixed space typo.

diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index 49847a9..1f9ae1d 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -383,6 +383,34 @@ pph_out_label_binding (pph_stream *stream, 
cp_label_binding *lb, bool ref_p)
 }
 
 
+/* Returns the number of nodes matching FILTER in chain
+   starting with FIRST.  */
+
+static unsigned
+pph_count_filter_match (tree first, enum chain_filter filter)
+{
+  unsigned count;
+  tree t;
+
+  switch (filter)
+{
+case NO_BUILTINS:
+  for (t = first, count = 0; t; t = TREE_CHAIN (t))
+   {
+ if (filter == NO_BUILTINS && DECL_P (t) && DECL_IS_BUILTIN (t))
+   continue;
+ count++;
+   }
+  break;
+
+default:
+  internal_error ("unknown chain_filter used in pph_count_filter_match");
+}
+
+  return count;
+}
+
+
 /* Output a chain of nodes to STREAM starting with FIRST.  Skip any
nodes that do not match FILTER.  REF_P is true if nodes in the chain
should be emitted as references.  */
@@ -402,13 +430,7 @@ pph_out_chain_filtered (pph_stream *stream, tree first, 
bool ref_p,
   return;
 }
 
-  /* Count all the nodes that match the filter.  */
-  for (t = first, count = 0; t; t = TREE_CHAIN (t))
-{
-  if (filter == NO_BUILTINS && DECL_P (t) && DECL_IS_BUILTIN (t))
-   continue;
-  count++;
-}
+  count = pph_count_filter_match (first, filter);
   pph_out_uint (stream, count);
 
   /* Output all the nodes that match the filter.  */
@@ -439,7 +461,7 @@ static void
 pph_out_binding_level (pph_stream *stream, struct cp_binding_level *bl,
bool ref_p)
 {
-  unsigned i;
+  unsigned i, streamed_names_size;
   cp_class_binding *cs;
   cp_label_binding *sl;
   struct bitpack_d bp;
@@ -448,7 +470,8 @@ pph_out_binding_level (pph_stream *stream, struct 
cp_binding_level *bl,
 return;
 
   pph_out_chain_filtered (stream, bl->names, ref_p, NO_BUILTINS);
-  pph_out_uint (stream, bl->names_size);
+  streamed_names_size = pph_count_filter_match (bl->names, NO_BUILTINS);
+  pph_out_uint (stream, streamed_names_size);
   pph_out_chain_filtered (stream, bl->namespaces, ref_p, NO_BUILTINS);
 
   pph_out_tree_vec (stream, bl->static_decls, ref_p);
@@ -714,7 +737,7 @@ pph_out_lang_specific (pph_stream *stream, tree decl, bool 
ref_p)
   ld = DECL_LANG_SPECIFIC (decl);
   if (!pph_start_record (stream, ld))
 return;
-
+
   /* Write all the fields in lang_decl_base.  */
   ldb = &ld->u.base;
   pph_out_ld_base (stream, ldb);
@@ -1080,7 +1103,7 @@ pph_write_tree (struct output_block *ob, tree expr, bool 
ref_p)
   TI_TYPEDEFS_NEEDING_ACCESS_CHECKING (expr), ref_p);
   break;
 
-case TEMPLATE_PARM_INDEX: 
+case TEMPLATE_PARM_INDEX:
   {
 template_parm_index *p = TEMPLATE_PARM_INDEX_CAST (expr);
 pph_out_tree_common (stream, expr, ref_p);

--
This patch is available for review at http://codereview.appspot.com/4634071


[pph] Reorganize pph read/write file into their respective streamers (issue4657042)

2011-06-21 Thread Gabriel Charette
Avoid exposing more and more streamer functions in the headers by moving all
the read logic to pph-streamer-in.c and the write logic to pph-streamer-out.c

This is a pure copy/paste of the functions, 
no new functionality was added in this patch

Tested with bootstrap build and pph regression testing.

2011-06-21  Gabriel Charette  

* gcc/cp/pph-streamer-in.c (pph_in_tree_vec): Make static.
(pph_add_names_to_namespace): Moved from pph.c.
(wrap_macro_def): Moved from pph.c.
(report_validation_error): Moved from pph.c.
(pth_load_identifiers): Moved from pph.c.
(pph_read_file_contents): Moved from pph.c.
(pph_read_file): Moved from pph.c
* gcc/cp/pph-streamer-out.c (pph_out_tree_vec): Make static.
(pph_out_chain_filtered): Make static.
(pth_save_identifiers): Moved from pph.c.
(pph_write_file_contents): Moved from pph.c.
(pph_write_file): Moved from pph.c.
* gcc/cp/pph-streamer.h (pph_out_tree_vec): Now static, removed.
(pph_out_chain_filtered): Now static, removed.
(pph_write_file): Now public, added.
(pph_in_tree_vec): Now static, removed.
(pph_read_file): Now public, added.
* gcc/cp/pph.h (pph_dump_namespace): Exposed.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index af6102b..e71f744 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -281,7 +281,7 @@ pph_in_ld_min (pph_stream *stream, struct lang_decl_min 
*ldm)
 
 /* Read and return a gc VEC of trees from STREAM.  */
 
-VEC(tree,gc) *
+static VEC(tree,gc) *
 pph_in_tree_vec (pph_stream *stream)
 {
   unsigned i, num;
@@ -976,6 +976,208 @@ pph_in_lang_type (pph_stream *stream)
 }
 
 
+/* Add all the new names declared in NEW_NS to NS.  */
+
+static void
+pph_add_names_to_namespace (tree ns, tree new_ns)
+{
+  tree t, chain;
+  struct cp_binding_level *level = NAMESPACE_LEVEL (new_ns);
+
+  for (t = level->names; t; t = chain)
+{
+  /* Pushing a decl into a scope clobbers its DECL_CHAIN.
+Preserve it.  */
+  chain = DECL_CHAIN (t);
+  pushdecl_into_namespace (t, ns);
+}
+
+  for (t = level->namespaces; t; t = chain)
+{
+  /* Pushing a decl into a scope clobbers its DECL_CHAIN.
+Preserve it.  */
+  /* FIXME pph: we should first check to see if it isn't already there.  */
+  chain = DECL_CHAIN (t);
+  pushdecl_into_namespace (t, ns);
+  pph_add_names_to_namespace (t, t);
+}
+}
+
+
+/* Wrap a macro DEFINITION for printing in an error.  */
+
+static char *
+wrap_macro_def (const char *definition)
+{
+  char *string;
+  if (definition)
+{
+  size_t length;
+  length = strlen (definition);
+  string = (char *) xmalloc (length+3);
+  string[0] = '"';
+  strcpy (string + 1, definition);
+  string[length + 1] = '"';
+  string[length + 2] = '\0';
+}
+  else
+string = xstrdup ("undefined");
+  return string;
+}
+
+
+/* Report a macro validation error in FILENAME for macro IDENT,
+   which should have the value EXPECTED but actually had the value FOUND. */
+
+static void
+report_validation_error (const char *filename,
+const char *ident, const char *found,
+const char *before, const char *after)
+{
+  char* quote_found = wrap_macro_def (found);
+  char* quote_before = wrap_macro_def (before);
+  char* quote_after = wrap_macro_def (after);
+  error ("PPH file %s fails macro validation, "
+ "%s is %s and should be %s or %s\n",
+ filename, ident, quote_found, quote_before, quote_after);
+  free (quote_found);
+  free (quote_before);
+  free (quote_after);
+}
+
+
+/* Load the IDENTIFERS for a hunk from a STREAM.  */
+
+static void
+pth_load_identifiers (cpp_idents_used *identifiers, pph_stream *stream)
+{
+  unsigned int j;
+  unsigned int max_ident_len, max_value_len, num_entries;
+  unsigned int ident_len, before_len, after_len;
+
+  max_ident_len = pph_in_uint (stream);
+  identifiers->max_ident_len = max_ident_len;
+  max_value_len = pph_in_uint (stream);
+  identifiers->max_value_len = max_value_len;
+  num_entries = pph_in_uint (stream);
+  identifiers->num_entries = num_entries;
+  identifiers->entries = XCNEWVEC (cpp_ident_use, num_entries);
+  identifiers->strings = XCNEW (struct obstack);
+
+  /* Strings need no alignment.  */
+  _obstack_begin (identifiers->strings, 0, 0,
+  (void *(*) (long)) xmalloc,
+  (void (*) (void *)) free);
+  obstack_alignment_mask (identifiers->strings) = 0;
+  /* FIXME pph: We probably need to free all these things somewhere.  */
+
+  /* Read the identifiers in HUNK. */
+  for (j = 0; j < num_entries; ++j)
+{
+  const char *s;
+  identifiers->entries[j].used_by_directive = pph_in_uint (stream);
+  identifiers->entries[j].expa

[pph] Stream scope_chain->bindings instead of global namespace (issue4661045)

2011-06-22 Thread Gabriel Charette
We were streaming out the whole global namespace tree and only using its
bindings on the way in. These bindings (defined by NAMESPACE_LEVEL 
(global_namespace))
are the same as scope_chain->bindings.

Stream those bindings only instead.

This also allows us to append the global_namespace itself to the lto cache
early so that anything pointing to global namespace in the underlying
structure of the bindings (and anything else potentially?!) will point to the
actual global namespace when streamed back in (as opposed to the stale version
we were streaming in).

Can someone confirm that we really didn't need to stream anything but the
bindings from the global_namespace?

This patch also changes the behaviour of the dumper (used for debug only) in
that it dumps the global namespace on read AFTER the bindings were merged with
the current global namespace; as opposed to the prior behaviour which was
to dump the namespace READ in.
This is actually a good thing, because I just realized some of the bindings
are read, but not merged correctly (working on that next), and this exposes
it.

2011-06-22  Gabriel Charette  

* gcc/cp/pph-streamer-in.c (pph_add_names_to_namespace): Replaced by
pph_add_bindings_to_namespace.
(pph_add_bindings_to_namespace): New.
(pph_in_scope_chain): New.
(pph_read_file_contents): Remove unused variable file_ns.
(pph_read_file_contents): Call pph_in_scope_chain.
* gcc/cp/pph-streamer-out.c (pph_out_scope_chain): New.
(pph_write_file_contents): Call pph_out_scope_chain.
* gcc/cp/pph-streamer.c (pph_preload_common_nodes):
Call lto_streamer_cache_append.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index e71f744..2e3545a 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -976,15 +976,14 @@ pph_in_lang_type (pph_stream *stream)
 }
 
 
-/* Add all the new names declared in NEW_NS to NS.  */
+/* Add all bindings declared in BL to NS.  */
 
 static void
-pph_add_names_to_namespace (tree ns, tree new_ns)
+pph_add_bindings_to_namespace (struct cp_binding_level *bl, tree ns)
 {
   tree t, chain;
-  struct cp_binding_level *level = NAMESPACE_LEVEL (new_ns);
 
-  for (t = level->names; t; t = chain)
+  for (t = bl->names; t; t = chain)
 {
   /* Pushing a decl into a scope clobbers its DECL_CHAIN.
 Preserve it.  */
@@ -992,18 +991,35 @@ pph_add_names_to_namespace (tree ns, tree new_ns)
   pushdecl_into_namespace (t, ns);
 }
 
-  for (t = level->namespaces; t; t = chain)
+  for (t = bl->namespaces; t; t = chain)
 {
   /* Pushing a decl into a scope clobbers its DECL_CHAIN.
 Preserve it.  */
   /* FIXME pph: we should first check to see if it isn't already there.  */
   chain = DECL_CHAIN (t);
   pushdecl_into_namespace (t, ns);
-  pph_add_names_to_namespace (t, t);
+  /* FIXME pph: this carried over from pph_add_names_to_namespace,
+it only makes sense to use this when merging names in an existing
+namespace.
+  pph_add_bindings_to_namespace (NAMESPACE_LEVEL (t), t);  */
 }
 }
 
 
+/* Merge scope_chain bindings from the stream into SS. */
+
+static void
+pph_in_scope_chain (pph_stream *stream)
+{
+  struct cp_binding_level *pph_bindings;
+
+  pph_bindings = pph_in_binding_level (stream);
+
+  /* Merge the bindings obtained from STREAM in the global namespace.  */
+  pph_add_bindings_to_namespace (pph_bindings, global_namespace);
+}
+
+
 /* Wrap a macro DEFINITION for printing in an error.  */
 
 static char *
@@ -1128,7 +1144,6 @@ pph_read_file_contents (pph_stream *stream)
   cpp_ident_use *bad_use;
   const char *cur_def;
   cpp_idents_used idents_used;
-  tree file_ns;
 
   pth_load_identifiers (&idents_used, stream);
 
@@ -1141,12 +1156,12 @@ pph_read_file_contents (pph_stream *stream)
   /* Re-instantiate all the pre-processor symbols defined by STREAM.  */
   cpp_lt_replay (parse_in, &idents_used);
 
-  /* Read global_namespace from STREAM and add all the names defined
- there to the current global_namespace.  */
-  file_ns = pph_in_tree (stream);
+  /* Read the bindings from STREAM and merge them with the current bindings.  
*/
+  pph_in_scope_chain (stream);
+
   if (flag_pph_dump_tree)
-pph_dump_namespace (pph_logfile, file_ns);
-  pph_add_names_to_namespace (global_namespace, file_ns);
+pph_dump_namespace (pph_logfile, global_namespace);
+
   keyed_classes = pph_in_tree (stream);
   unemitted_tinfo_decls = pph_in_tree_vec (stream);
   /* FIXME pph: This call replaces the tinfo, we should merge instead.
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index 3187338..691cfdd 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -935,6 +935,33 @@ pph_out_lang_type (pph_stream *stream, tree type, bool 
ref_p)
 }
 
 
+/* Write saved_scope information stored in SS, does NOT output all fields,
+   meant to be used for

[pph] Stream scope_chain->bindings instead of global namespace (issue4661045)

2011-06-22 Thread Gabriel Charette
gcc/cp/pph-streamer-in.c:1003: namespace.
 1001   /* FIXME pph: this carried over from pph_add_names_to_namespace,
 1002 »it only makes sense to use this when merging names in an 
existing
 1003 »namespace.

pph_add_names_to_namespace does not exist anymore.  I don't understand this
comment.

What I meant is that pph_add_bindings_to_namespace is just a modified version of
the old pph_add_names_to_namespace in which this recursive call was made (and 
was
already useless before, i.e. commenting it out wouldn't introduce any changes 
in the
test results...).

I changed the comment, adding it to the FIXME just above it which mentions we 
should
check if this namespace already exists (i.e. it only makes sense to add bindings
in the "streamed in" namespace to the actual namespace IF they are NOT the same 
object
(otherwise the bindings are already part of the "streamed in" namespace so this 
call is useless).

##
gcc/cp/pph-streamer-out.c:947: gcc_assert ( ss->old_namespace ==
global_namespace
  945   /* old_namespace should be global_namespace and all entries listed below
  946  should be NULL or 0; otherwise the header parsed was incomplete.  */
  947   gcc_assert ( ss->old_namespace == global_namespace

No space after '('.

FIXED.

##
gcc/cp/pph-streamer-out.c:949: || ss->function_decl || ss->template_parms ||
ss->x_saved_tree
  948   && !(ss->class_name || ss->class_type || ss->access_specifier
  949|| ss->function_decl || ss->template_parms || ss->x_saved_tree

Align '&&' vertically with the open brace.

FIXED.

##
gcc/cp/pph-streamer.c:34: #include "name-lookup.h"
  33 #include "cppbuiltin.h"
+ 34 #include "name-lookup.h"

You also need to add cp/name-lookup.h to the list of dependencies for cp/pph.o
in cp/Make-lang.in.

I simply removed the include, I originally added it because it holds 
global_namespace, but it
compiles without it (which I guess is fine if we don't try to stick to "include 
what you use").

2011-06-22  Gabriel Charette  

* gcc/cp/pph-streamer-in.c (pph_add_names_to_namespace): Replaced by
pph_add_bindings_to_namespace.
(pph_add_bindings_to_namespace): New.
(pph_in_scope_chain): New.
(pph_read_file_contents): Remove unused variable file_ns.
(pph_read_file_contents): Call pph_in_scope_chain.
* gcc/cp/pph-streamer-out.c (pph_out_scope_chain): New.
(pph_write_file_contents): Call pph_out_scope_chain.
* gcc/cp/pph-streamer.c (pph_preload_common_nodes):
Call lto_streamer_cache_append.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index e71f744..c16b88d 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -976,15 +976,14 @@ pph_in_lang_type (pph_stream *stream)
 }
 
 
-/* Add all the new names declared in NEW_NS to NS.  */
+/* Add all bindings declared in BL to NS.  */
 
 static void
-pph_add_names_to_namespace (tree ns, tree new_ns)
+pph_add_bindings_to_namespace (struct cp_binding_level *bl, tree ns)
 {
   tree t, chain;
-  struct cp_binding_level *level = NAMESPACE_LEVEL (new_ns);
 
-  for (t = level->names; t; t = chain)
+  for (t = bl->names; t; t = chain)
 {
   /* Pushing a decl into a scope clobbers its DECL_CHAIN.
 Preserve it.  */
@@ -992,18 +991,33 @@ pph_add_names_to_namespace (tree ns, tree new_ns)
   pushdecl_into_namespace (t, ns);
 }
 
-  for (t = level->namespaces; t; t = chain)
+  for (t = bl->namespaces; t; t = chain)
 {
   /* Pushing a decl into a scope clobbers its DECL_CHAIN.
 Preserve it.  */
-  /* FIXME pph: we should first check to see if it isn't already there.  */
+  /* FIXME pph: we should first check to see if it isn't already there.  
+   If it is, we should use this function recursively to merge
+   the bindings in T in the corresponding namespace.  */
   chain = DECL_CHAIN (t);
   pushdecl_into_namespace (t, ns);
-  pph_add_names_to_namespace (t, t);
 }
 }
 
 
+/* Merge scope_chain bindings from the stream into SS. */
+
+static void
+pph_in_scope_chain (pph_stream *stream)
+{
+  struct cp_binding_level *pph_bindings;
+
+  pph_bindings = pph_in_binding_level (stream);
+
+  /* Merge the bindings obtained from STREAM in the global namespace.  */
+  pph_add_bindings_to_namespace (pph_bindings, global_namespace);
+}
+
+
 /* Wrap a macro DEFINITION for printing in an error.  */
 
 static char *
@@ -1128,7 +1142,6 @@ pph_read_file_contents (pph_stream *stream)
   cpp_ident_use *bad_use;
   const char *cur_def;
   cpp_idents_used idents_used;
-  tree file_ns;
 
   pth_load_identifiers (&idents_used, stream);
 
@@ -1141,12 +1154,12 @@ pph

[pph] Fixed extra space typos in pph-streamer-out.c (issue4663041)

2011-06-22 Thread Gabriel Charette
I've had these two small changes around for a while after making a search and 
replace
for extra spaces in my own added code last week.

Tested with bootstrap and pph regression testing, you never know ;)

2011-06-22  Gabriel Charette  

* gcc/cp/pph-streamer-out.c (pph_out_lang_specific): 
Removed extra space.
(pph_write_tree): Removed extra space.

diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index 32851a4..f219cef 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -714,7 +714,7 @@ pph_out_lang_specific (pph_stream *stream, tree decl, bool 
ref_p)
   ld = DECL_LANG_SPECIFIC (decl);
   if (!pph_out_start_record (stream, ld))
 return;
-
+
   /* Write all the fields in lang_decl_base.  */
   ldb = &ld->u.base;
   pph_out_ld_base (stream, ldb);
@@ -1166,7 +1166,7 @@ pph_write_tree (struct output_block *ob, tree expr, bool 
ref_p)
   TI_TYPEDEFS_NEEDING_ACCESS_CHECKING (expr), ref_p);
   break;
 
-case TEMPLATE_PARM_INDEX: 
+case TEMPLATE_PARM_INDEX:
   {
 template_parm_index *p = TEMPLATE_PARM_INDEX_CAST (expr);
 pph_out_tree_common (stream, expr, ref_p);

--
This patch is available for review at http://codereview.appspot.com/4663041


[pph] Fix binding_level's names_size streaming (issue4634071)

2011-06-22 Thread Gabriel Charette
Here is the patch removing names_size.

We found out it was write-only and that we could remove it.

I tested it with a full bootstrap build as well as a full regression test (make 
check-g++).

(actually one of the pph test fails, but that's because of a line number issue 
in where
we expect the ICE... I'll have to re-upload the patch as the script already 
submitted the files...)

2011-06-22  Gabriel Charette  

* gcc/cp/name-lookup.h (cp_binding_level): Removed unused
member names_size. Update all users.

diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 54977ce..297c57e 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -544,7 +544,6 @@ add_decl_to_level (tree decl, cxx_scope *b)
 necessary.  */
   TREE_CHAIN (decl) = b->names;
   b->names = decl;
-  b->names_size++;
 
   /* If appropriate, add decl to separate list of statics.  We
 include extern variables because they might turn out to be
diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h
index 009b5d9..5f266eb 100644
--- a/gcc/cp/name-lookup.h
+++ b/gcc/cp/name-lookup.h
@@ -191,9 +191,6 @@ struct GTY(()) cp_binding_level {
are wrapped in TREE_LISTs; the TREE_VALUE is the OVERLOAD.  */
 tree names;
 
-/* Count of elements in names chain.  */
-size_t names_size;
-
 /* A chain of NAMESPACE_DECL nodes.  */
 tree namespaces;
 
diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 0e8c6bf..a535cab 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -442,7 +442,6 @@ pph_in_binding_level (pph_stream *stream)
   ALLOC_AND_REGISTER (stream, ix, bl, ggc_alloc_cleared_cp_binding_level ());
 
   bl->names = pph_in_chain (stream);
-  bl->names_size = pph_in_uint (stream);
   bl->namespaces = pph_in_chain (stream);
 
   bl->static_decls = pph_in_tree_vec (stream);
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index f219cef..7a6c516 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -448,7 +448,6 @@ pph_out_binding_level (pph_stream *stream, struct 
cp_binding_level *bl,
 return;
 
   pph_out_chain_filtered (stream, bl->names, ref_p, NO_BUILTINS);
-  pph_out_uint (stream, bl->names_size);
   pph_out_chain_filtered (stream, bl->namespaces, ref_p, NO_BUILTINS);
 
   pph_out_tree_vec (stream, bl->static_decls, ref_p);

--
This patch is available for review at http://codereview.appspot.com/4634071


[pph] Fix binding_level's names_size streaming (issue4634071)

2011-06-22 Thread Gabriel Charette
See previous message. This patch only adds the fix to the dg-bogus comment for 
the failing pph test.

2011-06-22  Gabriel Charette  

* gcc/cp/name-lookup.h (cp_binding_level): Removed unused
member names_size. Update all users.

diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 54977ce..297c57e 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -544,7 +544,6 @@ add_decl_to_level (tree decl, cxx_scope *b)
 necessary.  */
   TREE_CHAIN (decl) = b->names;
   b->names = decl;
-  b->names_size++;
 
   /* If appropriate, add decl to separate list of statics.  We
 include extern variables because they might turn out to be
diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h
index 009b5d9..5f266eb 100644
--- a/gcc/cp/name-lookup.h
+++ b/gcc/cp/name-lookup.h
@@ -191,9 +191,6 @@ struct GTY(()) cp_binding_level {
are wrapped in TREE_LISTs; the TREE_VALUE is the OVERLOAD.  */
 tree names;
 
-/* Count of elements in names chain.  */
-size_t names_size;
-
 /* A chain of NAMESPACE_DECL nodes.  */
 tree namespaces;
 
diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 0e8c6bf..a535cab 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -442,7 +442,6 @@ pph_in_binding_level (pph_stream *stream)
   ALLOC_AND_REGISTER (stream, ix, bl, ggc_alloc_cleared_cp_binding_level ());
 
   bl->names = pph_in_chain (stream);
-  bl->names_size = pph_in_uint (stream);
   bl->namespaces = pph_in_chain (stream);
 
   bl->static_decls = pph_in_tree_vec (stream);
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index f219cef..7a6c516 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -448,7 +448,6 @@ pph_out_binding_level (pph_stream *stream, struct 
cp_binding_level *bl,
 return;
 
   pph_out_chain_filtered (stream, bl->names, ref_p, NO_BUILTINS);
-  pph_out_uint (stream, bl->names_size);
   pph_out_chain_filtered (stream, bl->namespaces, ref_p, NO_BUILTINS);
 
   pph_out_tree_vec (stream, bl->static_decls, ref_p);
diff --git a/gcc/testsuite/g++.dg/pph/x1template.cc 
b/gcc/testsuite/g++.dg/pph/x1template.cc
index 5b1e980..cecefd7 100644
--- a/gcc/testsuite/g++.dg/pph/x1template.cc
+++ b/gcc/testsuite/g++.dg/pph/x1template.cc
@@ -1,5 +1,5 @@
 // { dg-xfail-if "ICE" { "*-*-*" } { "-fpph-map=pph.map" } }
-// { dg-bogus "x1template.h:18:13: internal compiler error: in resume_scope, 
at cp/name-lookup.c:1569" "" { xfail *-*-* } 0 }
+// { dg-bogus "x1template.h:18:13: internal compiler error: in resume_scope, 
at cp/name-lookup.c:1568" "" { xfail *-*-* } 0 }
 // { dg-prune-output "In file included from " }
 
 #include "x1template.h"

--
This patch is available for review at http://codereview.appspot.com/4634071


Re: [pph] Fix binding_level's names_size streaming (issue4634071)

2011-06-22 Thread Gabriel Charette
And it looks like this wasn't sent to anyone directly...
Adding back dnovillo and crowl (Diego I don't think Jason was ever
added to the original message...?)

Gab

On Wed, Jun 22, 2011 at 5:02 PM, Gabriel Charette  wrote:
>
> See previous message. This patch only adds the fix to the dg-bogus comment 
> for the failing pph test.
>
> 2011-06-22  Gabriel Charette  
>
>        * gcc/cp/name-lookup.h (cp_binding_level): Removed unused
>        member names_size. Update all users.
>
> diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
> index 54977ce..297c57e 100644
> --- a/gcc/cp/name-lookup.c
> +++ b/gcc/cp/name-lookup.c
> @@ -544,7 +544,6 @@ add_decl_to_level (tree decl, cxx_scope *b)
>         necessary.  */
>       TREE_CHAIN (decl) = b->names;
>       b->names = decl;
> -      b->names_size++;
>
>       /* If appropriate, add decl to separate list of statics.  We
>         include extern variables because they might turn out to be
> diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h
> index 009b5d9..5f266eb 100644
> --- a/gcc/cp/name-lookup.h
> +++ b/gcc/cp/name-lookup.h
> @@ -191,9 +191,6 @@ struct GTY(()) cp_binding_level {
>        are wrapped in TREE_LISTs; the TREE_VALUE is the OVERLOAD.  */
>     tree names;
>
> -    /* Count of elements in names chain.  */
> -    size_t names_size;
> -
>     /* A chain of NAMESPACE_DECL nodes.  */
>     tree namespaces;
>
> diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
> index 0e8c6bf..a535cab 100644
> --- a/gcc/cp/pph-streamer-in.c
> +++ b/gcc/cp/pph-streamer-in.c
> @@ -442,7 +442,6 @@ pph_in_binding_level (pph_stream *stream)
>   ALLOC_AND_REGISTER (stream, ix, bl, ggc_alloc_cleared_cp_binding_level ());
>
>   bl->names = pph_in_chain (stream);
> -  bl->names_size = pph_in_uint (stream);
>   bl->namespaces = pph_in_chain (stream);
>
>   bl->static_decls = pph_in_tree_vec (stream);
> diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
> index f219cef..7a6c516 100644
> --- a/gcc/cp/pph-streamer-out.c
> +++ b/gcc/cp/pph-streamer-out.c
> @@ -448,7 +448,6 @@ pph_out_binding_level (pph_stream *stream, struct 
> cp_binding_level *bl,
>     return;
>
>   pph_out_chain_filtered (stream, bl->names, ref_p, NO_BUILTINS);
> -  pph_out_uint (stream, bl->names_size);
>   pph_out_chain_filtered (stream, bl->namespaces, ref_p, NO_BUILTINS);
>
>   pph_out_tree_vec (stream, bl->static_decls, ref_p);
> diff --git a/gcc/testsuite/g++.dg/pph/x1template.cc 
> b/gcc/testsuite/g++.dg/pph/x1template.cc
> index 5b1e980..cecefd7 100644
> --- a/gcc/testsuite/g++.dg/pph/x1template.cc
> +++ b/gcc/testsuite/g++.dg/pph/x1template.cc
> @@ -1,5 +1,5 @@
>  // { dg-xfail-if "ICE" { "*-*-*" } { "-fpph-map=pph.map" } }
> -// { dg-bogus "x1template.h:18:13: internal compiler error: in resume_scope, 
> at cp/name-lookup.c:1569" "" { xfail *-*-* } 0 }
> +// { dg-bogus "x1template.h:18:13: internal compiler error: in resume_scope, 
> at cp/name-lookup.c:1568" "" { xfail *-*-* } 0 }
>  // { dg-prune-output "In file included from " }
>
>  #include "x1template.h"
>
> --
> This patch is available for review at http://codereview.appspot.com/4634071


Re: [pph] Stream scope_chain->bindings instead of global namespace (issue4661045)

2011-06-23 Thread Gabriel Charette
Yes I did fill the form, included you as an approver, haven't heard
back from it yet.

Gab

On Thu, Jun 23, 2011 at 10:23 AM, Diego Novillo  wrote:
>
> On Thu, Jun 23, 2011 at 13:21, Diego Novillo  wrote:
> > I've made a couple of minor edits to comments and formatting and
> > committed to the branch (final patch below).
>
> Incidentally, did you fill-in the svn write access form?  You've
> produced enough good patches already.  Time for you to be able to
> commit your own.
>
>
> Diego.


Removed unused cp_binding_level field names_size. (issue4662052)

2011-06-23 Thread Gabriel Charette
The names_size member of cp_binding_level was write only. Removed it.
Seems like it was introduced for java in 2002, but it's not used anywhere 
anymore in the code.

Tested with bootstrap and full regression testing.

2011-06-23  Gabriel Charette  

* name-lookup.h (cp_binding_level): Removed unused
member names_size. Update all users.

diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 953edd5..8bf5f5f 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -541,7 +541,6 @@ add_decl_to_level (tree decl, cxx_scope *b)
 necessary.  */
   TREE_CHAIN (decl) = b->names;
   b->names = decl;
-  b->names_size++;
 
   /* If appropriate, add decl to separate list of statics.  We
 include extern variables because they might turn out to be
diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h
index 009b5d9..5f266eb 100644
--- a/gcc/cp/name-lookup.h
+++ b/gcc/cp/name-lookup.h
@@ -191,9 +191,6 @@ struct GTY(()) cp_binding_level {
are wrapped in TREE_LISTs; the TREE_VALUE is the OVERLOAD.  */
 tree names;
 
-/* Count of elements in names chain.  */
-size_t names_size;
-
 /* A chain of NAMESPACE_DECL nodes.  */
 tree namespaces;
 

--
This patch is available for review at http://codereview.appspot.com/4662052


Re: Removed unused cp_binding_level field names_size. (issue4662052)

2011-06-23 Thread Gabriel Charette
Also:

Tested on x86-64. Ok to commit to trunk?

On Thu, Jun 23, 2011 at 2:32 PM, Gabriel Charette  wrote:
> The names_size member of cp_binding_level was write only. Removed it.
> Seems like it was introduced for java in 2002, but it's not used anywhere 
> anymore in the code.
>
> Tested with bootstrap and full regression testing.
>
> 2011-06-23  Gabriel Charette  
>
>        * name-lookup.h (cp_binding_level): Removed unused
>        member names_size. Update all users.
>
> diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
> index 953edd5..8bf5f5f 100644
> --- a/gcc/cp/name-lookup.c
> +++ b/gcc/cp/name-lookup.c
> @@ -541,7 +541,6 @@ add_decl_to_level (tree decl, cxx_scope *b)
>         necessary.  */
>       TREE_CHAIN (decl) = b->names;
>       b->names = decl;
> -      b->names_size++;
>
>       /* If appropriate, add decl to separate list of statics.  We
>         include extern variables because they might turn out to be
> diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h
> index 009b5d9..5f266eb 100644
> --- a/gcc/cp/name-lookup.h
> +++ b/gcc/cp/name-lookup.h
> @@ -191,9 +191,6 @@ struct GTY(()) cp_binding_level {
>        are wrapped in TREE_LISTs; the TREE_VALUE is the OVERLOAD.  */
>     tree names;
>
> -    /* Count of elements in names chain.  */
> -    size_t names_size;
> -
>     /* A chain of NAMESPACE_DECL nodes.  */
>     tree namespaces;
>
>
> --
> This patch is available for review at http://codereview.appspot.com/4662052
>


Re: [pph] Fix binding_level's names_size streaming (issue4634071)

2011-06-24 Thread Gabriel Charette
This was commited to trunk. Diego can you commit this patch to pph as well?

Thanks,
Gab

On Thu, Jun 23, 2011 at 4:07 AM, Diego Novillo  wrote:
> On Wed, Jun 22, 2011 at 20:17, Gabriel Dos Reis
>  wrote:
>> On Wed, Jun 22, 2011 at 7:05 PM, Gabriel Charette  wrote:
>>> And it looks like this wasn't sent to anyone directly...
>>> Adding back dnovillo and crowl (Diego I don't think Jason was ever
>>> added to the original message...?)
>>
>> should not this go to mainline too?
>
> Yes, I CC'd Jason in the original thread that started this discussion.
>  Gab, could you send a patch for trunk?  Please CC Jason when you do.
>
>
> Diego.
>


[pph] Stream chain of struct fields (issue4631072)

2011-06-24 Thread Gabriel Charette
We were only streaming the first field of every struct. Struct fields have a 
chain link to the next field, thus we need to stream the DECL_CHAIN of every 
field as well recursively.

I limited this to VAR_DECL and FUNCTION_DECL for now (which fixes all of our 
current bugs in regards to the struct fields issues), are there any other DECLs 
that can potentially be fields of a struct?

I was tempted to stream the DECL_CHAIN for the whole "group" VAR_DECL belongs 
to in pph_read_tree, but as it turns out we don't want to do this for 
NAMESPACE_DECL as it gets a new chain link when re-added to the bindings early 
on and changing it here causes an ICE in one of the test cases.
Hence, I reverted to the conservative way of only streaming it for what we know 
we need it for.

Syntax-wise: Is it ok to play this 'case' fall through trick with VAR_DECL or 
should I make a separate case entry with it's own break?

2011-06-24  Gabriel Charette  

* gcc/cp/pph-streamer-in.c (pph_read_tree):
Stream in DECL_CHAIN of VAR_DECL.
Stream in DECL_CHAIN of FUNCTION_DECL.
* gcc/cp/pph-streamer-out.c (pph_write_tree):
Stream out DECL_CHAIN of VAR_DECL.
Stream out DECL_CHAIN of FUNCTION_DECL.
* gcc/testsuite/g++.dg/pph/x1functions.cc: Fixed bogus, now asm diff.
* gcc/testsuite/g++.dg/pph/x1variables.cc: Fixed bogus, now asm diff.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 0e6763f..8d12839 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -1216,12 +1216,13 @@ pph_read_tree (struct lto_input_block *ib 
ATTRIBUTE_UNUSED,
   DECL_INITIAL (expr) = pph_in_tree (stream);
   break;
 
+case VAR_DECL:
+  DECL_CHAIN (expr) = pph_in_tree (stream);
 case CONST_DECL:
 case FIELD_DECL:
 case NAMESPACE_DECL:
 case PARM_DECL:
 case USING_DECL:
-case VAR_DECL:
   /* FIXME pph: Should we merge DECL_INITIAL into lang_specific? */
   DECL_INITIAL (expr) = pph_in_tree (stream);
   pph_in_lang_specific (stream, expr);
@@ -1232,6 +1233,7 @@ pph_read_tree (struct lto_input_block *ib 
ATTRIBUTE_UNUSED,
   pph_in_lang_specific (stream, expr);
   DECL_SAVED_TREE (expr) = pph_in_tree (stream);
   DECL_STRUCT_FUNCTION (expr) = pph_in_struct_function (stream);
+  DECL_CHAIN (expr) = pph_in_tree (stream);
   break;
 
 case TYPE_DECL:
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index 613cdcd..e85a629 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -1062,12 +1062,13 @@ pph_write_tree (struct output_block *ob, tree expr, 
bool ref_p)
   pph_out_tree_or_ref_1 (stream, DECL_INITIAL (expr), ref_p, 3);
   break;
 
+case VAR_DECL:
+  pph_out_tree_or_ref_1 (stream, DECL_CHAIN (expr), ref_p, 3);
 case CONST_DECL:
 case FIELD_DECL:
 case NAMESPACE_DECL:
 case PARM_DECL:
 case USING_DECL:
-case VAR_DECL:
   /* FIXME pph: Should we merge DECL_INITIAL into lang_specific? */
   pph_out_tree_or_ref_1 (stream, DECL_INITIAL (expr), ref_p, 3);
   pph_out_lang_specific (stream, expr, ref_p);
@@ -1078,6 +1079,7 @@ pph_write_tree (struct output_block *ob, tree expr, bool 
ref_p)
   pph_out_lang_specific (stream, expr, ref_p);
   pph_out_tree_or_ref_1 (stream, DECL_SAVED_TREE (expr), ref_p, 3);
   pph_out_struct_function (stream, DECL_STRUCT_FUNCTION (expr), ref_p);
+  pph_out_tree_or_ref_1 (stream, DECL_CHAIN (expr), ref_p, 3);
   break;
 
 case TYPE_DECL:
diff --git a/gcc/testsuite/g++.dg/pph/x1functions.cc 
b/gcc/testsuite/g++.dg/pph/x1functions.cc
index 20cde5c..78df01b 100644
--- a/gcc/testsuite/g++.dg/pph/x1functions.cc
+++ b/gcc/testsuite/g++.dg/pph/x1functions.cc
@@ -1,5 +1,4 @@
-// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
-// { dg-bogus "'mbr_decl_inline' was not declared in this scope" "" { xfail 
*-*-* } 0 }
+// pph asm xdiff
 
 #include "x1functions.h"
 
diff --git a/gcc/testsuite/g++.dg/pph/x1variables.cc 
b/gcc/testsuite/g++.dg/pph/x1variables.cc
index bac3136..0f0814f 100644
--- a/gcc/testsuite/g++.dg/pph/x1variables.cc
+++ b/gcc/testsuite/g++.dg/pph/x1variables.cc
@@ -1,6 +1,4 @@
-// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
-// { dg-bogus "c1variables.h:5:8: error: 'int D::mbr_uninit_plain' is not a 
static member of 'struct D'" "" { xfail *-*-* } 0 }
-// { dg-bogus "c1variables.h:6:14: error: 'const int D::mbr_init_const' is not 
a static member of 'struct D'" "" { xfail *-*-* } 0 }
+// pph asm xdiff
 
 #include "x1variables.h"
 

--
This patch is available for review at http://codereview.appspot.com/4631072


Re: [pph] Add header files to pph.map (issue4639073)

2011-06-27 Thread Gabriel Charette
Couldn't we have headers look for their corresponding .pph file by
default when -fpph-map is on? (especially since pph.map is only
temporary for the implementation phase)

I would see it like this:
if -fpph-map is not NULL:
  look for mapping in file
  if not found:
look for default mapping (i.e. replace .h by .pph and look for file)
if not found:
  use actual #include behaviour

Could that also be why the small test I tried to introduce last week
to test the ordering of the bindings coming from the pph would pass
(i.e. it wouldn't use it's pph as I didn't add it to pph.map?).

On Mon, Jun 27, 2011 at 9:21 AM, Diego Novillo  wrote:
>
> When I added these tests, I forgot to add them to pph.map, so the header
> files were being generated into an image, but not used in the second
> compilation.
>
> Most of the failures are in the form of different asm output.  There
> is one new ICE, though.
>
> Committed to branch.
>
>
> Diego.
>
>        * g++.dg/pph/pph.map: Add entries for c120060625-1.cc,
>        c1attr-warn-unused-result.cc, c1builtin-integral-1.cc,
>        c1builtin-object-size-2.cc, c1eabi1.cc, c1eabi1.h,
>        c1limits-externalid.cc, c1meteor-contest.cc, c1pr36533.cc,
>        c1pr44948-1a.cc, c1return-5.cc, and x1template.cc.
>        * g++.dg/pph/c120060625-1.cc: Adjust XFAIL patterns.
>        * g++.dg/pph/c1attr-warn-unused-result.cc: Adjust XFAIL
>        patterns.
>        * g++.dg/pph/c1builtin-integral-1.cc: Adjust XFAIL patterns.
>        * g++.dg/pph/c1builtin-object-size-2.cc: Adjust XFAIL
>        patterns.
>        * g++.dg/pph/c1eabi1.cc: Adjust XFAIL patterns.
>        * g++.dg/pph/c1eabi1.h: Adjust XFAIL patterns.
>        * g++.dg/pph/c1limits-externalid.cc: Adjust XFAIL patterns.
>        * g++.dg/pph/c1meteor-contest.cc: Adjust XFAIL patterns.
>        * g++.dg/pph/c1pr36533.cc: Adjust XFAIL patterns.
>        * g++.dg/pph/c1pr44948-1a.cc: Adjust XFAIL patterns.
>        * g++.dg/pph/c1return-5.cc: Adjust XFAIL patterns.
>        * g++.dg/pph/x1template.cc: Adjust XFAIL patterns.
>
> diff --git a/gcc/testsuite/g++.dg/pph/c120060625-1.cc 
> b/gcc/testsuite/g++.dg/pph/c120060625-1.cc
> index 05c7929..d09be39 100644
> --- a/gcc/testsuite/g++.dg/pph/c120060625-1.cc
> +++ b/gcc/testsuite/g++.dg/pph/c120060625-1.cc
> @@ -1 +1,2 @@
> +// pph asm xdiff
>  #include "c120060625-1.h"
> diff --git a/gcc/testsuite/g++.dg/pph/c1attr-warn-unused-result.cc 
> b/gcc/testsuite/g++.dg/pph/c1attr-warn-unused-result.cc
> index 921d294..da75561 100644
> --- a/gcc/testsuite/g++.dg/pph/c1attr-warn-unused-result.cc
> +++ b/gcc/testsuite/g++.dg/pph/c1attr-warn-unused-result.cc
> @@ -1,2 +1,3 @@
>  /* { dg-options "-w" } */
> +// pph asm xdiff
>  #include "c1attr-warn-unused-result.h"
> diff --git a/gcc/testsuite/g++.dg/pph/c1builtin-integral-1.cc 
> b/gcc/testsuite/g++.dg/pph/c1builtin-integral-1.cc
> index bf53219..962086c 100644
> --- a/gcc/testsuite/g++.dg/pph/c1builtin-integral-1.cc
> +++ b/gcc/testsuite/g++.dg/pph/c1builtin-integral-1.cc
> @@ -1 +1,2 @@
> +// pph asm xdiff
>  #include "c1builtin-integral-1.h"
> diff --git a/gcc/testsuite/g++.dg/pph/c1builtin-object-size-2.cc 
> b/gcc/testsuite/g++.dg/pph/c1builtin-object-size-2.cc
> index 615e7da..17fe707 100644
> --- a/gcc/testsuite/g++.dg/pph/c1builtin-object-size-2.cc
> +++ b/gcc/testsuite/g++.dg/pph/c1builtin-object-size-2.cc
> @@ -1,2 +1,3 @@
>  /* { dg-options "-O2 -w -fpermissive" } */
> +// pph asm xdiff
>  #include "c1builtin-object-size-2.h"
> diff --git a/gcc/testsuite/g++.dg/pph/c1eabi1.cc 
> b/gcc/testsuite/g++.dg/pph/c1eabi1.cc
> index b2e9b11..07a3a8b 100644
> --- a/gcc/testsuite/g++.dg/pph/c1eabi1.cc
> +++ b/gcc/testsuite/g++.dg/pph/c1eabi1.cc
> @@ -1,3 +1,4 @@
> +// { dg-timeout 2 { target *-*-* } }
>  // { dg-options "-w -fpermissive" }
>  // pph asm xdiff
>
> diff --git a/gcc/testsuite/g++.dg/pph/c1eabi1.h 
> b/gcc/testsuite/g++.dg/pph/c1eabi1.h
> index 5f5b593..383b752 100644
> --- a/gcc/testsuite/g++.dg/pph/c1eabi1.h
> +++ b/gcc/testsuite/g++.dg/pph/c1eabi1.h
> @@ -1,4 +1,6 @@
>  // { dg-options "-w -fpermissive" }
> +// FIXME pph - Enabling PPH for this file causes memory problems in cc1plus.
> +// c1eabi1.h   c1eabi1.pph
>
>  #ifndef __PPH_GUARD_H
>  #define __PPH_GUARD_H
> diff --git a/gcc/testsuite/g++.dg/pph/c1limits-externalid.cc 
> b/gcc/testsuite/g++.dg/pph/c1limits-externalid.cc
> index 8b5039c..8d2da40 100644
> --- a/gcc/testsuite/g++.dg/pph/c1limits-externalid.cc
> +++ b/gcc/testsuite/g++.dg/pph/c1limits-externalid.cc
> @@ -1 +1,2 @@
> +// pph asm xdiff
>  #include "c1limits-externalid.h"
> diff --git a/gcc/testsuite/g++.dg/pph/c1meteor-contest.cc 
> b/gcc/testsuite/g++.dg/pph/c1meteor-contest.cc
> index bb097ac..58d2c89 100644
> --- a/gcc/testsuite/g++.dg/pph/c1meteor-contest.cc
> +++ b/gcc/testsuite/g++.dg/pph/c1meteor-contest.cc
> @@ -1,2 +1,4 @@
> +/* { dg-timeout 5 { target *-*-* } }  */
> +// { dg-xfail-if "INFINITE" { "*-*-*" } { "-fpph-map=pph.map" } }
>  /* { dg-options "-w" }  */
>  #include "c

Re: [pph] New test (issue4629075)

2011-06-27 Thread Gabriel Charette
Just wondering why you're naming x finishing by an underscore "x_",
this is a valid name, but just thinking it's tricky syntax, does this
test anything more? or is it just a preference for private members?

LGTM

On Mon, Jun 27, 2011 at 9:39 AM, Diego Novillo  wrote:
> We are very close to having the first simple C++ program working from
> a PPH image.  Adding a runnable test case.
>
> This produces assembly miscomparisons and does not link.  I'll be
> working on it this week.
>
>
> Diego.
>
>        * g++.dg/pph/x1ten-hellos.cc: New.
>        * g++.dg/pph/x1ten-hellos.h: New.
>        * g++.dg/pph/pph.map: Add x1ten-hellos.h
>
> diff --git a/gcc/testsuite/g++.dg/pph/x1ten-hellos.cc 
> b/gcc/testsuite/g++.dg/pph/x1ten-hellos.cc
> new file mode 100644
> index 000..b99d08a
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pph/x1ten-hellos.cc
> @@ -0,0 +1,12 @@
> +// { dg-do run }
> +// { dg-xfail-if "LINK ERROR" { "*-*-*" } { "-fpph-map=pph.map" } }
> +// pph asm xdiff
> +#include "x1ten-hellos.h"
> +
> +int main(void)
> +{
> +  A a;
> +  for (int i = 0; i < 10; i++)
> +    a.hello();
> +  return 0;
> +}
> diff --git a/gcc/testsuite/g++.dg/pph/x1ten-hellos.h 
> b/gcc/testsuite/g++.dg/pph/x1ten-hellos.h
> new file mode 100644
> index 000..2a53b66
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pph/x1ten-hellos.h
> @@ -0,0 +1,21 @@
> +#ifndef A_H_
> +#define A_H_
> +#include 
> +
> +class A
> +{
> +public:
> +  A() {
> +    x_ = 0;
> +    printf ("constructing\n");
> +  }
> +
> +  void hello(void) {
> +    x_++;
> +    printf ("Hello World (%d)\n", x_);
> +  }
> +
> +private:
> +  int x_;
> +};
> +#endif
> diff --git a/gcc/testsuite/g++.dg/pph/pph.map 
> b/gcc/testsuite/g++.dg/pph/pph.map
> index f0c7abd..2735af8 100644
> --- a/gcc/testsuite/g++.dg/pph/pph.map
> +++ b/gcc/testsuite/g++.dg/pph/pph.map
> @@ -38,6 +47,7 @@ x1struct0.h   x1struct0.pph
>  x1struct1.h    x1struct1.pph
>  x1struct2.h    x1struct2.pph
>  x1template.h   x1template.pph
> +x1ten-hellos.h x1ten-hellos.pph
>  x1tmplclass.h  x1tmplclass.pph
>  x1tmplfunc.h   x1tmplfunc.pph
>  x1typerefs.h   x1typerefs.pph
>
> --
> This patch is available for review at http://codereview.appspot.com/4629075
>


Re: [pph] Add header files to pph.map (issue4639073)

2011-06-27 Thread Gabriel Charette
On Mon, Jun 27, 2011 at 10:06 AM, Diego Novillo  wrote:
> On Mon, Jun 27, 2011 at 13:01, Gabriel Charette  wrote:
>> Couldn't we have headers look for their corresponding .pph file by
>> default when -fpph-map is on? (especially since pph.map is only
>> temporary for the implementation phase)
>
> The problem is with headers that include other headers.  We want to
> limit the generation of images to specific headers.  Given that we are
> in this initial implementation phase, the simplest approach is to
> remember to update pph.map.

Well in what I'm proposing we only use the pph file if it was actually
generated before (we don't generate it if it's not there). Are there
any situations where we have a corresponding pph file, but don't
actually want to use it when the fpph-map flag is on? Seems unlikely
as we put all the pph files in the pph map for now anyways...

>
>> Could that also be why the small test I tried to introduce last week
>> to test the ordering of the bindings coming from the pph would pass
>> (i.e. it wouldn't use it's pph as I didn't add it to pph.map?).
>
> Yes, that's likely.
>
>
> Diego.
>


Re: [pph] Add header files to pph.map (issue4639073)

2011-06-27 Thread Gabriel Charette
On Mon, Jun 27, 2011 at 10:18 AM, Diego Novillo  wrote:
> On Mon, Jun 27, 2011 at 13:13, Gabriel Charette  wrote:
>> On Mon, Jun 27, 2011 at 10:06 AM, Diego Novillo  wrote:
>>> On Mon, Jun 27, 2011 at 13:01, Gabriel Charette  wrote:
>>>> Couldn't we have headers look for their corresponding .pph file by
>>>> default when -fpph-map is on? (especially since pph.map is only
>>>> temporary for the implementation phase)
>>>
>>> The problem is with headers that include other headers.  We want to
>>> limit the generation of images to specific headers.  Given that we are
>>> in this initial implementation phase, the simplest approach is to
>>> remember to update pph.map.
>>
>> Well in what I'm proposing we only use the pph file if it was actually
>> generated before (we don't generate it if it's not there). Are there
>> any situations where we have a corresponding pph file, but don't
>> actually want to use it when the fpph-map flag is on? Seems unlikely
>> as we put all the pph files in the pph map for now anyways...
>
> Headers include other headers.  We are not generating PPH for all headers.
>
> The mapping file also allows us to control what happens when
> generating a PPH file that emits #include directives itself.  Some of
> those we want to have referenced as PPH, but not all.
>
> It's really easier for us to remember to update the mapping file
> rather than adding some automatic detection that would have to be
> removed later.

Ok I agree, temporary flags and map files are better then temporary
code for the implementation phase.

LGTM,
Gab

>
> Diego.
>


[pph] Moved token cache streaming to in/out respectively (issue4635073)

2011-06-27 Thread Gabriel Charette
Moved all token cache streaming to it's respective in/out streamer.
They were non-static exposed methods, but were only used in 
pph-streamer-in/out.c

This is a pure copy/paste patch.

I will change the functions names to reflect the pph naming scheme in a 
subsequent patch.

Tested with bootstrap and pph regression testing.

2011-06-27  Gabriel Charette  

* pph-streamer-in.c (pth_get_type_from_index): Moved from pph.c.
(pth_load_number): Moved from pph.c.
(pth_load_token_value): Moved from pph.c.
(pth_load_token): Moved from pph.c.
(pth_load_token_cache): Moved from pph.c. Made static.
* pph-streamer-out.c (pth_get_index_from_type): Moved from pph.c.
(pth_write_number): Moved from pph.c.
(pth_save_token_value): Moved from pph.c.
(pth_save_token): Moved from pph.c.
(pth_save_token_cache): Moved from pph.c. Made static.
* pph-streamer.h (struct cp_token_cache): 
Not declared in pph.c, but in parser.h, removed.
(pth_save_token_cache): Now static, removed.
(pth_load_token_cache): Now static, removed.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 605b214..6743c3c 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -242,6 +242,164 @@ pph_register_shared_data (pph_stream *stream, void *data, 
unsigned ix)
 }
 
 
+/* Given a type index TYPE_IDX and TYPE_KIND specifying the kind of type,
+   return a type from integer_types or global_trees.  */
+
+static tree
+pth_get_type_from_index (unsigned type_idx, unsigned type_kind)
+{
+  if (type_kind == CPP_N_INTEGER)
+return integer_types[type_idx];
+  else if (type_kind == CPP_N_FLOATING || type_kind == CPP_N_FRACT)
+return global_trees[type_idx];
+  else if (type_kind == CPP_N_IMAGINARY)
+{
+  /* We don't need a type for the complex number.  The type is
+associated with the real and imaginary parts.  */
+  return NULL_TREE;
+}
+  else
+gcc_unreachable ();
+}
+
+
+/* Load a numeric value from file F.  Return the corresponding tree.  */
+
+static tree
+pth_load_number (pph_stream *f)
+{
+  unsigned type_idx, type_kind;
+  tree type, val;
+
+  type_idx = pph_in_uint (f);
+  type_kind = pph_in_uint (f);
+
+  type = pth_get_type_from_index (type_idx, type_kind);
+
+  if (type_kind == CPP_N_INTEGER)
+{
+  HOST_WIDE_INT v[2];
+  pph_in_bytes (f, v, 2 * sizeof (HOST_WIDE_INT));
+  val = build_int_cst_wide (type, v[0], v[1]);
+}
+  else if (type_kind == CPP_N_FLOATING)
+{
+  REAL_VALUE_TYPE r;
+  pph_in_bytes (f, &r, sizeof (REAL_VALUE_TYPE));
+  val = build_real (type, r);
+}
+  else if (type_kind == CPP_N_FRACT)
+{
+  FIXED_VALUE_TYPE fv;
+  pph_in_bytes (f, &fv, sizeof (FIXED_VALUE_TYPE));
+  val = build_fixed (type, fv);
+}
+  else if (type_kind == CPP_N_IMAGINARY)
+{
+  tree r = pth_load_number (f);
+  tree i = pth_load_number (f);
+  val = build_complex (NULL_TREE, r, i);
+}
+  else
+gcc_unreachable ();
+
+  return val;
+}
+
+
+/* Load the tree value associated with TOKEN to file F.  */
+
+static void
+pth_load_token_value (cp_token *token, pph_stream *f)
+{
+  const char *str;
+
+  switch (token->type)
+{
+  case CPP_TEMPLATE_ID:
+  case CPP_NESTED_NAME_SPECIFIER:
+   break;
+
+  case CPP_NAME:
+   str = pph_in_string (f);
+   token->u.value = get_identifier (str);
+   break;
+
+  case CPP_KEYWORD:
+   token->u.value = ridpointers[token->keyword];
+   break;
+
+  case CPP_CHAR:
+  case CPP_WCHAR:
+  case CPP_CHAR16:
+  case CPP_CHAR32:
+  case CPP_NUMBER:
+   token->u.value = pth_load_number (f);
+   break;
+
+  case CPP_STRING:
+  case CPP_WSTRING:
+  case CPP_STRING16:
+  case CPP_STRING32:
+   str = pph_in_string (f);
+   token->u.value = build_string (strlen (str), str);
+   break;
+
+  case CPP_PRAGMA:
+   /* Nothing to do.  Field pragma_kind has already been loaded.  */
+   break;
+
+  default:
+   pph_in_bytes (f, &token->u.value, sizeof (token->u.value));
+   gcc_assert (token->u.value == NULL);
+}
+}
+
+
+/* Read and return a token from STREAM.  */
+
+static cp_token *
+pth_load_token (pph_stream *stream)
+{
+  cp_token *token = ggc_alloc_cleared_cp_token ();
+
+  /* Do not read the whole structure, the token value has
+ dynamic size as it contains swizzled pointers.
+ FIXME pph, restructure to allow bulk reads of the whole
+ section.  */
+  pph_in_bytes (stream, token, sizeof (cp_token) - sizeof (void *));
+
+  /* FIXME pph.  Use an arbitrary (but valid) location to avoid
+ confusing the rest of the compiler for now.  */
+  token->location = input_location;
+
+  /* FIXME pph: verify that pth_load_token_value works with no tokens.  */
+  pth_load_token_value (token, stream);
+
+  return token;

[pph] Rename token cache and identifiers streaming functions to reflect pph naming scheme (issue4636065)

2011-06-27 Thread Gabriel Charette
Renamed all functions to reflect pph naming schemes (pph_in/out_*).

Also reordered parameters so that the first parameter is always pph_stream*

Tested with bootstrap and pph regression testing.

2011-06-27  Gabriel Charette  

* pph-streamer-in.c (pph_get_type_from_index):
Rename from pth_get_type_from_index. Update all users.
(pph_in_number): Rename from pth_load_number.
Update all users.
(pph_in_token_value): Rename from pth_load_token_value. Change
signature to 'pph_stream*, cp_token*' from 'cp_token*, pph_stream*'.
Update all users.
(pph_in_token): Rename from pth_load_token.
Update all users.
(pph_in_token_cache): Rename from pth_load_token_cache.
Update all users.
(pph_in_identifiers): Rename from pth_load_identifiers. Change
signature to 'pph_stream*, cpp_idents_used*' from
'cpp_idents_used*, pph_stream*'.
from (cpp_idents_used*, pph_stream*).
Update all users.
* pph-streamer-out.c (pph_get_index_from_type):
Rename from pth_get_index_from_type.
Update all users.
(pph_out_number): Rename from pth_write_number.
Update all users.
(pph_out_token_value): Rename from pth_save_token_value.
Update all users.
(pph_out_token): Rename from pth_save_token. Change signature to
'pph_stream*, cp_token*' from 'cp_token*, pph_stream*'.
Update all users.
(pph_out_token_cache): Rename from pth_save_token_cache. Change
signature to 'pph_stream*, cp_token_cache*'
from 'cp_token_cache*, pph_stream*'.
Update all users.
(pph_out_identifiers): Rename from pth_save_identifiers. Change
signature to 'pph_stream*, cpp_idents_used*' from
'cpp_idents_used*, pph_stream*'.
Update all users.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 6743c3c..93b5685 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -246,7 +246,7 @@ pph_register_shared_data (pph_stream *stream, void *data, 
unsigned ix)
return a type from integer_types or global_trees.  */
 
 static tree
-pth_get_type_from_index (unsigned type_idx, unsigned type_kind)
+pph_get_type_from_index (unsigned type_idx, unsigned type_kind)
 {
   if (type_kind == CPP_N_INTEGER)
 return integer_types[type_idx];
@@ -266,7 +266,7 @@ pth_get_type_from_index (unsigned type_idx, unsigned 
type_kind)
 /* Load a numeric value from file F.  Return the corresponding tree.  */
 
 static tree
-pth_load_number (pph_stream *f)
+pph_in_number (pph_stream *f)
 {
   unsigned type_idx, type_kind;
   tree type, val;
@@ -274,7 +274,7 @@ pth_load_number (pph_stream *f)
   type_idx = pph_in_uint (f);
   type_kind = pph_in_uint (f);
 
-  type = pth_get_type_from_index (type_idx, type_kind);
+  type = pph_get_type_from_index (type_idx, type_kind);
 
   if (type_kind == CPP_N_INTEGER)
 {
@@ -296,8 +296,8 @@ pth_load_number (pph_stream *f)
 }
   else if (type_kind == CPP_N_IMAGINARY)
 {
-  tree r = pth_load_number (f);
-  tree i = pth_load_number (f);
+  tree r = pph_in_number (f);
+  tree i = pph_in_number (f);
   val = build_complex (NULL_TREE, r, i);
 }
   else
@@ -310,7 +310,7 @@ pth_load_number (pph_stream *f)
 /* Load the tree value associated with TOKEN to file F.  */
 
 static void
-pth_load_token_value (cp_token *token, pph_stream *f)
+pph_in_token_value (pph_stream *f, cp_token *token)
 {
   const char *str;
 
@@ -334,7 +334,7 @@ pth_load_token_value (cp_token *token, pph_stream *f)
   case CPP_CHAR16:
   case CPP_CHAR32:
   case CPP_NUMBER:
-   token->u.value = pth_load_number (f);
+   token->u.value = pph_in_number (f);
break;
 
   case CPP_STRING:
@@ -359,7 +359,7 @@ pth_load_token_value (cp_token *token, pph_stream *f)
 /* Read and return a token from STREAM.  */
 
 static cp_token *
-pth_load_token (pph_stream *stream)
+pph_in_token (pph_stream *stream)
 {
   cp_token *token = ggc_alloc_cleared_cp_token ();
 
@@ -373,8 +373,8 @@ pth_load_token (pph_stream *stream)
  confusing the rest of the compiler for now.  */
   token->location = input_location;
 
-  /* FIXME pph: verify that pth_load_token_value works with no tokens.  */
-  pth_load_token_value (token, stream);
+  /* FIXME pph: verify that pph_in_token_value works with no tokens.  */
+  pph_in_token_value (stream, token);
 
   return token;
 }
@@ -383,7 +383,7 @@ pth_load_token (pph_stream *stream)
 /* Read and return a cp_token_cache instance from STREAM.  */
 
 static cp_token_cache *
-pth_load_token_cache (pph_stream *stream)
+pph_in_token_cache (pph_stream *stream)
 {
   unsigned i, num;
   cp_token *first, *last;
@@ -391,7 +391,7 @@ pth_load_token_cache (pph_stream *stream)
   num = pph_in_uint (stream);
   for (last = first = NULL, i = 

Add Gabriel Charette to Write After Approval list (issue4626079)

2011-06-27 Thread Gabriel Charette
Added myself to write after approval maintainers list.

2011-06-27  Gabriel Charette  

* MAINTAINERS (Write After Approval): Add myself.

diff --git a/MAINTAINERS b/MAINTAINERS
index 9dead4f..f6a768e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -324,6 +324,7 @@ Christian Bruel 
christian.br...@st.com
 Kevin Buettner kev...@redhat.com
 Andrew Cagney  cag...@redhat.com
 Stephane Carrezstcar...@nerim.fr
+Gabriel Charette   gch...@google.com
 Chandra Chavva ccha...@redhat.com
 Fabien Chêne   fab...@gcc.gnu.org
 William Cohen  wco...@redhat.com

--
This patch is available for review at http://codereview.appspot.com/4626079


Re: [pph] Rename token cache and identifiers streaming functions to reflect pph naming scheme (issue4636065)

2011-06-27 Thread Gabriel Charette
On Mon, Jun 27, 2011 at 1:40 PM,  wrote:
>
> On 2011/06/27 20:33:26, Gabriel Charette wrote:
>>
>> 2011-06-27  Gabriel Charette  <mailto:gch...@google.com>
>
> Remove the 'mailto:' prefix.

Weird, that's not in the actual patch, probably gmail putting it in...

Commited as rev r175568.

Gab


>
>
>>        * pph-streamer-in.c (pph_get_type_from_index):
>>        Rename from pth_get_type_from_index. Update all users.
>>        (pph_in_number): Rename from pth_load_number.
>>        Update all users.
>>        (pph_in_token_value): Rename from pth_load_token_value. Change
>>        signature to 'pph_stream*, cp_token*' from 'cp_token*, pph_stream*'.
>>        Update all users.
>>        (pph_in_token): Rename from pth_load_token.
>>        Update all users.
>>        (pph_in_token_cache): Rename from pth_load_token_cache.
>>        Update all users.
>>        (pph_in_identifiers): Rename from pth_load_identifiers. Change
>>        signature to 'pph_stream*, cpp_idents_used*' from
>>        'cpp_idents_used*, pph_stream*'.
>>        from (cpp_idents_used*, pph_stream*).
>>        Update all users.
>>        * pph-streamer-out.c (pph_get_index_from_type):
>>        Rename from pth_get_index_from_type.
>>        Update all users.
>>        (pph_out_number): Rename from pth_write_number.
>>        Update all users.
>>        (pph_out_token_value): Rename from pth_save_token_value.
>>        Update all users.
>>        (pph_out_token): Rename from pth_save_token. Change signature to
>>        'pph_stream*, cp_token*' from 'cp_token*, pph_stream*'.
>>        Update all users.
>>        (pph_out_token_cache): Rename from pth_save_token_cache. Change
>>        signature to 'pph_stream*, cp_token_cache*'
>>        from 'cp_token_cache*, pph_stream*'.
>>        Update all users.
>>        (pph_out_identifiers): Rename from pth_save_identifiers. Change
>>        signature to 'pph_stream*, cpp_idents_used*' from
>>        'cpp_idents_used*, pph_stream*'.
>>        Update all users.
>
> OK with that change.
>
>
> Diego.
>
> http://codereview.appspot.com/4636065/


[pph] Fix var order when streaming in. (issue4635074)

2011-06-27 Thread Gabriel Charette
The names and namespaces chains are built by adding each new element to the 
front of the list. When streaming it in we traverse the list of names and 
re-add them to the current chains; thus reversing the order in which they were 
defined in the header file.

Since this is a singly linked-list we cannot start from the tail; thus we 
reverse the chain in place and then traverse it, now adding the bindings in the 
same order they were found in the header file.

I introduced a new failing test to test this. The test showed the reverse 
behaviour prior to the patch.
The test still fails however, there is another inversion problem between the 
global variables and the .LFBO, .LCFI0, ...
This patch only fixes the inversion of the global variables declarations in the 
assembly, not the second issue this is exposing.
This second issue is potentially already exposed by another test?? Do we need 
this new test?

This fixes all of the assembly mismatches in c1limits-externalid.cc however!

Tested with bootstrap build and pph regression testing.

2011-06-27  Gabriel Charette  

* pph-streamer-in.c (pph_add_bindings_to_namespace): Reverse names and
namespaces chains.

* g++.dg/pph/c1limits-externalid.cc: Remove pph asm xdiff.
* g++.dg/pph/c1varorder.cc: New.
* g++.dg/pph/c1varorder.h: New.
* g++.dg/pph/pph.map: Add c1varorder.h

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 93b5685..cfa2ce5 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -1141,6 +1141,11 @@ pph_add_bindings_to_namespace (struct cp_binding_level 
*bl, tree ns)
 {
   tree t, chain;
 
+  /* The chains are built backwards (ref: add_decl_to_level@name-lookup.c),
+ reverse them before putting them back in.  */
+  bl->names = nreverse (bl->names);
+  bl->namespaces = nreverse (bl->namespaces);
+
   for (t = bl->names; t; t = chain)
 {
   /* Pushing a decl into a scope clobbers its DECL_CHAIN.
diff --git a/gcc/testsuite/g++.dg/pph/c1limits-externalid.cc 
b/gcc/testsuite/g++.dg/pph/c1limits-externalid.cc
index 8d2da40..8b5039c 100644
--- a/gcc/testsuite/g++.dg/pph/c1limits-externalid.cc
+++ b/gcc/testsuite/g++.dg/pph/c1limits-externalid.cc
@@ -1,2 +1 @@
-// pph asm xdiff
 #include "c1limits-externalid.h"
diff --git a/gcc/testsuite/g++.dg/pph/c1varorder.cc 
b/gcc/testsuite/g++.dg/pph/c1varorder.cc
new file mode 100644
index 000..2db8209
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pph/c1varorder.cc
@@ -0,0 +1,7 @@
+#include "c1varorder.h"
+// pph asm xdiff
+
+int foo(void)
+{
+  return var1 - var2;
+}
diff --git a/gcc/testsuite/g++.dg/pph/c1varorder.h 
b/gcc/testsuite/g++.dg/pph/c1varorder.h
new file mode 100644
index 000..a87c80c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pph/c1varorder.h
@@ -0,0 +1,7 @@
+#ifndef __C1VARORDER_H
+#define __C1VARORDER_H
+
+int var1;
+int var2;
+
+#endif
diff --git a/gcc/testsuite/g++.dg/pph/pph.map b/gcc/testsuite/g++.dg/pph/pph.map
index 2735af8..2ed5bf2 100644
--- a/gcc/testsuite/g++.dg/pph/pph.map
+++ b/gcc/testsuite/g++.dg/pph/pph.map
@@ -25,6 +25,7 @@ c1simple2.h   c1simple2.pph
 c1struct.h c1struct.pph
 c1typerefs.h   c1typerefs.pph
 c1variables.h  c1variables.pph
+c1varorder.h   c1varorder.pph
 c2builtin1.h   c2builtin1.pph
 c2builtin2.h   c2builtin2.pph
 c2builtin3.h   c2builtin3.pph

--
This patch is available for review at http://codereview.appspot.com/4635074


[pph] Add cp_global_trees to cache in preload (issue4635077)

2011-06-28 Thread Gabriel Charette
Add the cp_global_trees to the cache during the preload.

Those are preconstructed trees which we only need the pointers to (i.e. they 
should be identical in both the .cc and .h)

One exception to this is the keyed_classes tree which is generated during 
parsing.

We will need to merge the keyed_classes tree eventually when working with 
multiple pph's.

2011-06-28  Gabriel Charette  

* pph-streamer.c (pph_preload_common_nodes):
Add cp_global_trees[] to cache.

* g++.dg/pph/x1typerefs.cc: Remove xfail.

diff --git a/gcc/cp/pph-streamer.c b/gcc/cp/pph-streamer.c
index e919baf..c62864a 100644
--- a/gcc/cp/pph-streamer.c
+++ b/gcc/cp/pph-streamer.c
@@ -79,6 +79,17 @@ pph_preload_common_nodes (struct lto_streamer_cache_d *cache)
 if (c_global_trees[i])
   lto_streamer_cache_append (cache, c_global_trees[i]);
 
+  /* cp_global_trees[] can have NULL entries in it.  Skip them.  */
+  for (i = 0; i < CPTI_MAX; i++)
+{
+  /* Also skip trees which are generated while parsing.  */
+  if (i == CPTI_KEYED_CLASSES)
+   continue;
+
+  if (cp_global_trees[i])
+   lto_streamer_cache_append (cache, cp_global_trees[i]);
+}
+
   lto_streamer_cache_append (cache, global_namespace);
 }
 
diff --git a/gcc/testsuite/g++.dg/pph/x1typerefs.cc 
b/gcc/testsuite/g++.dg/pph/x1typerefs.cc
index ba7580f..6aa0e96 100644
--- a/gcc/testsuite/g++.dg/pph/x1typerefs.cc
+++ b/gcc/testsuite/g++.dg/pph/x1typerefs.cc
@@ -1,6 +1,3 @@
-// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
-// { dg-bogus "c1typerefs.h:11:18: error: cannot convert 'const 
std::type_info.' to 'const std::type_info.' in initialization" "" { xfail *-*-* 
} 0 }
-
 #include "x1typerefs.h"
 
 int derived::method() {

--
This patch is available for review at http://codereview.appspot.com/4635077


[pph] Append DECL_CONTEXT of global namespace to cache in preload (issue4629081)

2011-06-28 Thread Gabriel Charette
We need members of the global namespace to point to the global translation unit 
decl.
Thus we will append DECL_CONTEXT of global namespace to cache in preload.

This doesn't fix any tests, but helps towards making the tree nodes identicals 
in pph-mode.

Tested with bootstrap build and pph regression testing.

2011-06-28  Gabriel Charette  

* pph-streamer.c (pph_preload_common_nodes):
Append DECL_CONTEXT of global_namespace to cache.

diff --git a/gcc/cp/pph-streamer.c b/gcc/cp/pph-streamer.c
index c62864a..b7ad486 100644
--- a/gcc/cp/pph-streamer.c
+++ b/gcc/cp/pph-streamer.c
@@ -91,6 +91,8 @@ pph_preload_common_nodes (struct lto_streamer_cache_d *cache)
 }
 
   lto_streamer_cache_append (cache, global_namespace);
+
+  lto_streamer_cache_append (cache, DECL_CONTEXT (global_namespace));
 }
 
 

--
This patch is available for review at http://codereview.appspot.com/4629081


[pph] Fixing string streaming functions and their comments (issue4654076)

2011-06-29 Thread Gabriel Charette
Some comments were wrong.

In particular, the strings read from the stream are placed in a data table, and 
thus the strings returned DO NOT need to be freed by the caller, they belong to 
the stream who handles them itself.

Also lto_output_string_with_length does handle NULL strings, removed the 
redundant logic.

Tested with bootstrap build and pph regression testing.

2011-06-29  Gabriel Charette  

* pph-streamer.h (struct pph_stream): Fix comment of data_in field.
(pph_out_string_with_length): lto_output_string_with_length now handles
NULL strings, call it directly.
(pph_in_string): Fix comment.

diff --git a/gcc/cp/pph-streamer.h b/gcc/cp/pph-streamer.h
index b899501..8d0c024 100644
--- a/gcc/cp/pph-streamer.h
+++ b/gcc/cp/pph-streamer.h
@@ -100,7 +100,7 @@ typedef struct pph_stream {
   struct lto_input_block *ib;
 
   /* String tables and other descriptors used by the LTO reading
- routines.  NULL when the file is opened for reading.  */
+ routines.  NULL when the file is opened for writing.  */
   struct data_in *data_in;
 
   /* Array of sections in the PPH file.  */
@@ -250,21 +250,10 @@ static inline void
 pph_out_string_with_length (pph_stream *stream, const char *str,
   unsigned int len)
 {
-  if (str)
-{
-  if (flag_pph_tracer >= 4)
-   pph_trace_string_with_length (stream, str, len);
-  lto_output_string_with_length (stream->ob, stream->ob->main_stream,
-str, len + 1, false);
-}
-  else
-{
-  /* lto_output_string_with_length does not handle NULL strings,
-but lto_output_string does.  */
-  if (flag_pph_tracer >= 4)
-   pph_trace_string (stream, str);
-  pph_out_string (stream, NULL);
-}
+  if (flag_pph_tracer >= 4)
+pph_trace_string_with_length (stream, str, len);
+  lto_output_string_with_length (stream->ob, stream->ob->main_stream,
+ str, len + 1, false);
 }
 
 /* Output VEC V of ASTs to STREAM.
@@ -338,9 +327,7 @@ pph_in_bytes (pph_stream *stream, void *p, size_t n)
 pph_trace_bytes (stream, p, n);
 }
 
-/* Read and return a string of up to MAX characters from STREAM.
-   The caller is responsible for freeing the memory allocated
-   for the string.  */
+/* Read and return a string of up to MAX characters from STREAM.  */
 
 static inline const char *
 pph_in_string (pph_stream *stream)

--
This patch is available for review at http://codereview.appspot.com/4654076


[pph] Stream first/weak_object_global_name (issue4641086)

2011-06-30 Thread Gabriel Charette
first/weak_global_object_name are part of the global state.

This seems to be used to produce the assembler names. They are set only once as 
early as possible in the parsing; thus we should define it to be whatever it 
was in the first pph (or even in the C file if it was set before any pph was 
even loaded.

I'm not sure exactly what this does, but trying to find a fix for the asm diffs 
this is the first thing that I hit in the compiler logic that was different in 
the good compiler vs the pph compiler. With this fix this bit of logic is now 
correct.
However, this doesn't fix any pph test (nor does it even change any pph asm (I 
diff'ed the old bad assemblies (*.s+pph) with the new ones)).

Tested with bootstrap build and pph regression testing.

2011-06-30  Gabriel Charette  

* Make-lang.in (pph-streamer-out.o): Add dependence on output.h
(pph-streamer-in.o): Add dependence on output.h
* pph-streamer-in.c (pph_read_file_contents): Stream in
first_global_object_name and weak_global_object_name.
* gcc/cp/pph-streamer-out.c (pph_write_file_contents): Stream out
first_global_object_name and weak_global_object_name.

diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index 0bb1a15..ec7596a 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -350,8 +350,8 @@ cp/pph-streamer.o: cp/pph-streamer.c $(CONFIG_H) 
$(SYSTEM_H) coretypes.h \
 cp/pph-streamer-out.o: cp/pph-streamer-out.c $(CONFIG_H) $(SYSTEM_H) \
coretypes.h $(TREE_H) tree-pretty-print.h $(LTO_STREAMER_H) \
$(CXX_PPH_STREAMER_H) $(CXX_PPH_H) $(TREE_PASS_H) version.h \
-   cppbuiltin.h tree-iterator.h
+   cppbuiltin.h tree-iterator.h output.h
 cp/pph-streamer-in.o: cp/pph-streamer-in.c $(CONFIG_H) $(SYSTEM_H) \
coretypes.h $(TREE_H) tree-pretty-print.h $(LTO_STREAMER_H) \
$(CXX_PPH_STREAMER_H) $(CXX_PPH_H) $(TREE_PASS_H) version.h \
-   cppbuiltin.h tree-iterator.h
+   cppbuiltin.h tree-iterator.h output.h
diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 3ac5243..c341d50 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h"
 #include "version.h"
 #include "cppbuiltin.h"
+#include "output.h"
 
 /* Wrapper for memory allocation calls that should have their results
registered in the PPH streamer cache.  DATA is the pointer returned
@@ -1309,7 +1310,7 @@ pph_read_file_contents (pph_stream *stream)
 {
   bool verified;
   cpp_ident_use *bad_use;
-  const char *cur_def;
+  const char *cur_def, *pph_fgon, *pph_wgon;
   cpp_idents_used idents_used;
   tree fndecl;
   unsigned i;
@@ -1325,6 +1326,16 @@ pph_read_file_contents (pph_stream *stream)
   /* Re-instantiate all the pre-processor symbols defined by STREAM.  */
   cpp_lt_replay (parse_in, &idents_used);
 
+  /* If first_global_object_name is not set yet, set it to the pph one.  */
+  pph_fgon = pph_in_string (stream);
+  if (!first_global_object_name)
+first_global_object_name = pph_fgon;
+
+  /* If weak_global_object_name is not set yet, set it to the pph one.  */
+  pph_wgon = pph_in_string (stream);
+  if (!weak_global_object_name)
+weak_global_object_name = pph_wgon;
+
   /* Read the bindings from STREAM and merge them with the current bindings.  
*/
   pph_in_scope_chain (stream);
 
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index acc0352..0d29f0b 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h"
 #include "version.h"
 #include "cppbuiltin.h"
+#include "output.h"
 
 /* FIXME pph.  This holds the FILE handle for the current PPH file
that we are writing.  It is necessary because the LTO callbacks do
@@ -1197,9 +1198,14 @@ static void
 pph_write_file_contents (pph_stream *stream, cpp_idents_used *idents_used)
 { 
   pph_out_identifiers (stream, idents_used);
+
+  pph_out_string (stream, first_global_object_name);
+  pph_out_string (stream, weak_global_object_name);
+
   pph_out_scope_chain (stream, scope_chain, false);
   if (flag_pph_dump_tree)
 pph_dump_namespace (pph_logfile, global_namespace);
+
   pph_out_tree (stream, keyed_classes, false);
   pph_out_tree_vec (stream, unemitted_tinfo_decls, false);
 }

--
This patch is available for review at http://codereview.appspot.com/4641086


Re: [pph] Stream first/weak_object_global_name (issue4641086)

2011-06-30 Thread Gabriel Charette
notice_global_symbol is actually called in the parser (before we stream out).

I just confirmed this by setting a break point on the function in the
pph generation of c1varoder.pph and hitting the function twice for the
two variables defined in c1varorder.h

It looks like rtl and assembler_name are set BEFORE we stream out...
so that we would need to stream them (looks like assembler_name is
already streamed, but not rtl...).

Not streaming rtl causes it to be recreated later (which i think might
be the cause of the bad ordering).

Now another problem is that when two pph are generated, they are not
aware of each other (and of their respective
first/weak_global_object_name...) so even if we stream those
variables, their could still be conflicts (and/or asm diffs..)

However, I'm not sure about how make_decl_rtl works, but if it can
regenerate the same rtl we had before (and even potentially solve the
conflicts mentioned in the previous paragraph), we may not need to
actually stream the rtl, we would just need to fix the ordering as the
pph rtl's are being regenerated.

(they are regenerated because DECL_RTL(NODE) either returns
(NODE)->decl_with_rtl.rtl or calls make_decl_rtl(NODE) if it's
NULL...)

If we do this, I think we wanna have the first/weak_object_global_name
set to what it should be by streaming it in from the first pph, to
ensure all the rtl and assembler_name choices are made correctly (I'm
not sure I understand all of this, but it seems to rely on those
fields).

Gab

On Thu, Jun 30, 2011 at 4:33 PM, Diego Novillo  wrote:
> On Thu, Jun 30, 2011 at 16:24, Gabriel Charette  wrote:
>> first/weak_global_object_name are part of the global state.
>>
>> This seems to be used to produce the assembler names. They are set only once 
>> as early as possible in the parsing; thus we should define it to be whatever 
>> it was in the first pph (or even in the C file if it was set before any pph 
>> was even loaded.
>>
>> I'm not sure exactly what this does, but trying to find a fix for the asm 
>> diffs this is the first thing that I hit in the compiler logic that was 
>> different in the good compiler vs the pph compiler. With this fix this bit 
>> of logic is now correct.
>> However, this doesn't fix any pph test (nor does it even change any pph asm 
>> (I diff'ed the old bad assemblies (*.s+pph) with the new ones)).
>
> This does not look right to me.  These two symbols are set when
> calling notice_global_symbol, which is done during code generation
> (you will see it called from cgraph_finalize_function,
> cgraph_mark_reachable_node, etc).
>
> You are probably close to the cause of this relative ordering problem,
> but streaming these two globals is not the solution.  They both should
> be set in the same order by both compilers, but not by forcing them
> this way.
>
> One thing that may be happening here is that the order in which we
> call cgraph_finalize_function is different in the two compilers.
> That's what needs to change.  One thing you could do is set a
> breakpoint in notice_global_symbol.  The two compilers should be
> calling it in the same order.
>
>
> Diego.
>


Re: [pph] Test cleanup (issue4572050)

2011-07-01 Thread Gabriel Charette
Hey,

so I really like the new clean testing system, so that we always
quickly see what we fixed/broked with a local change.

One problem now though: `// pph asm xdiff`, only flags for asm diffs,
but those could be different diffs after a change (for the better or
worse) and this won't be caught. It's probably hard to get something
precise on this, but maybe we could simply add the # of lines of diff
expected, e.g. `// pph asm xdiff 32`. Then we XFAIL if the number of
expected lines in the diff match, but actually fail if the number of
lines in the diff is now different.

I'm not very familiar with dg.. Is that doable? Would be very helpful
at this stage.

Gab

On Wed, Jun 8, 2011 at 1:44 PM, Lawrence Crowl  wrote:
> Update the test suite to reflect recent fixes and merges from trunk.
>
> The following changes happened in this patch.
>
> Conversion of a compilation failure to an assembly diff failure:
>
>    remove the dg comments and add the comment // pph asm xdiff
>
> Conversion of a ICE to a BOGUS
>
>    change the dg-xfail-if line from ICE to BOGUS
>    change the dg-bogus line from the ICE message to the BOGUS message
>    remove the dg-prune-output lines corresponding to the ICE
>        (dg knows to remove them for errors, but not for ICEs)
>
> Update line numbers from a merge (or other edits to regular sources)
>    change the line number from old to new as reflected in the test log
>
> The output of make check filtered through the following sed command
> should yield no FAIL and no XPASS.
>
> sed -e '
>        /-fpph-map=pph.map/     ! {
>                /^XPASS: .*test for bogus messages/     d
>                /^XPASS: .*test for excess errors/      d
>        }
>
>        /^#/    p
>        /^ERROR: /      p
>        /^XFAIL: /      p
>        /^XPASS: /      p
>        /^FAIL: /       p
>
>        d
> '
>
> The same command works to filter the log file to its essential record
> of pass/fail.  In particular, it enables listing XFAILs that need work.
>
>
> Index: gcc/testsuite/ChangeLog.pph
>
> 2011-06-08  Lawrence Crowl 
>
>        * lib/dg-pph.exp (dg-pph-pos): Stop redundantly reporting a missing
>        pph assembly as an xfail when its compile xfails.
>        * g++.dg/pph/x1typerefs.cc: Replace ICE xfail with a bogus error xfail.
>        * g++.dg/pph/x1tmplclass.cc: Likewise.
>        * g++.dg/pph/x1autometh.cc: Replace ICE xfail with an assembly diff
>        xfail.
>        * g++.dg/pph/x1special.cc: Remove ICE xfail.
>        * g++.dg/pph/x1functions.cc: Correct xfail to BOGUS rather than ERROR.
>        Remove leftover pruning from previous ICE.
>        * g++.dg/pph/x1template.cc: Update line number of ICE.
>        * g++.dg/pph/x1variables.cc: Update line number of BOGUS.
>
>
> Index: gcc/testsuite/lib/dg-pph.exp
> ===
> --- gcc/testsuite/lib/dg-pph.exp        (revision 174789)
> +++ gcc/testsuite/lib/dg-pph.exp        (working copy)
> @@ -94,9 +94,7 @@ proc dg-pph-pos { subdir test options ma
>     # Quit if it did not compile successfully.
>     if { ![file_on_host exists "$bname.s"] } {
>        # Expect assembly to be missing when the compile is an expected fail.
> -       if { [llength [grep $test "dg-xfail-if.*-fpph-map"]] } {
> -           xfail "$nshort $options (pph assembly missing)"
> -       } else {
> +       if { ![llength [grep $test "dg-xfail-if.*-fpph-map"]] } {
>            fail "$nshort $options (pph assembly missing)"
>        }
>        return
> Index: gcc/testsuite/g++.dg/pph/x1typerefs.cc
> ===
> --- gcc/testsuite/g++.dg/pph/x1typerefs.cc      (revision 174789)
> +++ gcc/testsuite/g++.dg/pph/x1typerefs.cc      (working copy)
> @@ -1,6 +1,5 @@
> -// { dg-xfail-if "ICE" { "*-*-*" } { "-fpph-map=pph.map" } }
> -// { dg-bogus "c1typerefs.h:11:18: internal compiler error: Segmentation 
> fault" "" { xfail *-*-* } 0 }
> -// { dg-prune-output "In file included from " }
> +// { dg-xfail-if "BOGUS" { "*-*-*" } { "-fpph-map=pph.map" } }
> +// { dg-bogus "c1typerefs.h:11:18: error: cannot convert 'const 
> std::type_info.' to 'const std::type_info.' in initialization" "" { xfail 
> *-*-* } 0 }
>
>  #include "x1typerefs.h"
>
> Index: gcc/testsuite/g++.dg/pph/x1autometh.cc
> ===
> --- gcc/testsuite/g++.dg/pph/x1autometh.cc      (revision 174789)
> +++ gcc/testsuite/g++.dg/pph/x1autometh.cc      (working copy)
> @@ -1,6 +1,4 @@
> -// { dg-xfail-if "ICE" { "*-*-*" } { "-fpph-map=pph.map" } }
> -// { dg-bogus "x1autometh.h:8:1: internal compiler error: Segmentation 
> fault" "" { xfail *-*-* } 0 }
> -// { dg-prune-output "In file included from " }
> +// pph asm xdiff
>
>  #include "x1autometh.h"
>
> Index: gcc/testsuite/g++.dg/pph/x1special.cc
> ===
> --- gcc/testsuite/g++.dg/pph/x1special.cc       (revision 174789)
> +++ 

[pph] Fix executable test detection (issue4635087)

2011-07-01 Thread Gabriel Charette
[string compare "dg-do-what" "run"] which was used before would always return 
true.

Thus the tests would no longer even get to the asm diff section...

Me and Lawrence tried to find a way to get the content of the "dg-do-what" 
variable, but couldn't.

We decided to revert to this quick hack fix for now (better then not running 
the asm diffs...)

(I also added an unrelated re-ordering to the order of the pph asm xdiff 
comment in c1varoder.cc)

2011-07-01  Gabriel Charette  

* g++.dg/pph/c1varorder.cc: Moved pph asm xdiff comment to top.
* lib/dg-pph.exp (proc): Fixed executable test detection.

diff --git a/gcc/testsuite/g++.dg/pph/c1varorder.cc 
b/gcc/testsuite/g++.dg/pph/c1varorder.cc
index 2db8209..a7a65ec 100644
--- a/gcc/testsuite/g++.dg/pph/c1varorder.cc
+++ b/gcc/testsuite/g++.dg/pph/c1varorder.cc
@@ -1,6 +1,7 @@
-#include "c1varorder.h"
 // pph asm xdiff
 
+#include "c1varorder.h"
+
 int foo(void)
 {
   return var1 - var2;
diff --git a/gcc/testsuite/lib/dg-pph.exp b/gcc/testsuite/lib/dg-pph.exp
index b701ce2..e34bd63 100644
--- a/gcc/testsuite/lib/dg-pph.exp
+++ b/gcc/testsuite/lib/dg-pph.exp
@@ -74,8 +74,11 @@ proc dg-pph-pos { subdir test options mapflag suffix } {
 set dg-do-what-default compile
 dg-test -keep-output $test "$options -I." ""
 
+# Determine whether this is an executable test
+set is_exec [llength [grep $test "dg-do run"]]
+
 # Executables do not generate assembly.
-if { ![string compare "dg-do-what" "run"] } {
+if { !$is_exec } {
# Not executable, so quit if it did not compile successfully.
if { ![file_on_host exists "$bname.s"] } {
fail "$nshort $options (regular assembly missing)"
@@ -93,7 +96,7 @@ proc dg-pph-pos { subdir test options mapflag suffix } {
 dg-test -keep-output $test "$options $mapflag -I." ""
 
 # Executables do not generate assembly,
-if { [string compare "dg-do-what" "run"] } {
+if { $is_exec } {
# and so we are done testing.
return
 }

--
This patch is available for review at http://codereview.appspot.com/4635087


[pph] Fix global variable assembly ordering (issue4627087)

2011-07-01 Thread Gabriel Charette
As variables are discovered (while parsing the header) they are added to the 
varpool and their RTL is built.

We do not stream, nor the varpool, nor the RTL (and I don't think we want to + 
that wouldn't work with multiple pph).

We want to rebuild the varpool when streaming the global variables of the pph 
in so as to redefine them in the varpool in the same order they would have been 
found in a regular #include style parse.

I'm not sure whether "global variables, not externals" is specific enough or 
too broad (I can't reuse the caller of varpool_finalize_decl 
(rest_of_decl_compilation) to take care of this logic because it needs some 
parser state which we no longer have). I will create more tests next week with 
different orderings for functions, structs, etc. coming in from the pph.

For now, this fixes 8 tests :).

Tested with bootstrap and pph regression testing.

PS: Just realized I didn't put a comment in the code for that fix, should I add 
one?

2011-07-01  Gabriel Charette  

* gcc/cp/pph-streamer-in.c (pph_add_bindings_to_namespace):
Rebuild the varpool for global variables coming in from the pph.
* gcc/testsuite/g++.dg/pph/c120060625-1.cc: Expect no asm difference.
* gcc/testsuite/g++.dg/pph/c1struct.cc: Likewise.
* gcc/testsuite/g++.dg/pph/c1variables.cc: Likewise.
* gcc/testsuite/g++.dg/pph/c1varorder.cc: Likewise.
* gcc/testsuite/g++.dg/pph/c2builtin1.cc: Likewise.
* gcc/testsuite/g++.dg/pph/c2builtin2.cc: Likewise.
* gcc/testsuite/g++.dg/pph/x1struct2.cc: Likewise.
* gcc/testsuite/g++.dg/pph/x1variables.cc: Likewise.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 3ac5243..0ddcc75 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -1157,6 +1157,9 @@ pph_add_bindings_to_namespace (struct cp_binding_level 
*bl, tree ns)
 Preserve it.  */
   chain = DECL_CHAIN (t);
   pushdecl_into_namespace (t, ns);
+
+  if (TREE_CODE (t) == VAR_DECL && TREE_STATIC (t) && !DECL_EXTERNAL (t))
+   varpool_finalize_decl (t);
 }
 
   for (t = bl->namespaces; t; t = chain)
diff --git a/gcc/testsuite/g++.dg/pph/c120060625-1.cc 
b/gcc/testsuite/g++.dg/pph/c120060625-1.cc
index d09be39..05c7929 100644
--- a/gcc/testsuite/g++.dg/pph/c120060625-1.cc
+++ b/gcc/testsuite/g++.dg/pph/c120060625-1.cc
@@ -1,2 +1 @@
-// pph asm xdiff
 #include "c120060625-1.h"
diff --git a/gcc/testsuite/g++.dg/pph/c1struct.cc 
b/gcc/testsuite/g++.dg/pph/c1struct.cc
index 88c215b..8de9166 100644
--- a/gcc/testsuite/g++.dg/pph/c1struct.cc
+++ b/gcc/testsuite/g++.dg/pph/c1struct.cc
@@ -1,5 +1,3 @@
-// pph asm xdiff
-
 #include "c1struct.h"
 
 thing var1;
diff --git a/gcc/testsuite/g++.dg/pph/c1variables.cc 
b/gcc/testsuite/g++.dg/pph/c1variables.cc
index 12a5f30..4d3c5a7 100644
--- a/gcc/testsuite/g++.dg/pph/c1variables.cc
+++ b/gcc/testsuite/g++.dg/pph/c1variables.cc
@@ -1,5 +1,3 @@
-// pph asm xdiff
-
 #include "c1variables.h"
 
 int gbl_initial = 1;
diff --git a/gcc/testsuite/g++.dg/pph/c1varorder.cc 
b/gcc/testsuite/g++.dg/pph/c1varorder.cc
index a7a65ec..2791427 100644
--- a/gcc/testsuite/g++.dg/pph/c1varorder.cc
+++ b/gcc/testsuite/g++.dg/pph/c1varorder.cc
@@ -1,5 +1,3 @@
-// pph asm xdiff
-
 #include "c1varorder.h"
 
 int foo(void)
diff --git a/gcc/testsuite/g++.dg/pph/c2builtin1.cc 
b/gcc/testsuite/g++.dg/pph/c2builtin1.cc
index 9a3a7a1..67327cb 100644
--- a/gcc/testsuite/g++.dg/pph/c2builtin1.cc
+++ b/gcc/testsuite/g++.dg/pph/c2builtin1.cc
@@ -1,5 +1,3 @@
-// pph asm xdiff
-
 #include "c2builtin1.h"
 #include "c2builtin2.h"
 #include "c2builtin3.h"
diff --git a/gcc/testsuite/g++.dg/pph/c2builtin2.cc 
b/gcc/testsuite/g++.dg/pph/c2builtin2.cc
index 186ebcf..0ccae57 100644
--- a/gcc/testsuite/g++.dg/pph/c2builtin2.cc
+++ b/gcc/testsuite/g++.dg/pph/c2builtin2.cc
@@ -1,4 +1,3 @@
-// pph asm xdiff
 #include "a2builtin4.h"
 #include "c2builtin5.h"
 #include "c2builtin6.h"
diff --git a/gcc/testsuite/g++.dg/pph/x1struct2.cc 
b/gcc/testsuite/g++.dg/pph/x1struct2.cc
index be1af39..f31fb8c 100644
--- a/gcc/testsuite/g++.dg/pph/x1struct2.cc
+++ b/gcc/testsuite/g++.dg/pph/x1struct2.cc
@@ -1,5 +1,3 @@
-// pph asm xdiff
-
 #include "x1struct2.h"
 
 type D::method()
diff --git a/gcc/testsuite/g++.dg/pph/x1variables.cc 
b/gcc/testsuite/g++.dg/pph/x1variables.cc
index 0f0814f..f9fd76e 100644
--- a/gcc/testsuite/g++.dg/pph/x1variables.cc
+++ b/gcc/testsuite/g++.dg/pph/x1variables.cc
@@ -1,5 +1,3 @@
-// pph asm xdiff
-
 #include "x1variables.h"
 
 int D::mbr_init_plain = 4;

--
This patch is available for review at http://codereview.appspot.com/4627087


Re: [pph] Stream and restore static_aggregates (issue4626096)

2011-07-06 Thread Gabriel Charette
On Tue, Jul 5, 2011 at 9:08 PM, Diego Novillo  wrote:

>        * pph-streamer-in.c (pph_add_bindings_to_namespace):
> diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
> index 72536a5..0bab93b 100644
> --- a/gcc/cp/pph-streamer-in.c
> +++ b/gcc/cp/pph-streamer-in.c
> @@ -1167,11 +1167,9 @@ pph_add_bindings_to_namespace (struct cp_binding_level 
> *bl, tree ns)
>       /* Pushing a decl into a scope clobbers its DECL_CHAIN.
>         Preserve it.  */
>       chain = DECL_CHAIN (t);
> -
> -      /* FIXME pph: we should first check to see if it isn't already there.
> -        If it is, we should use this function recursively to merge
> -        the bindings in T in the corresponding namespace.  */
>       pushdecl_into_namespace (t, ns);
> +      if (NAMESPACE_LEVEL (t))
> +       pph_add_bindings_to_namespace (NAMESPACE_LEVEL (t), t);
>     }
>  }

I had removed these two lines because that pretty much does nothing (I
think, at least removing them didn't make anything fail...)... When we
stream out the other namespaces (through the tree which's root is
scope_chain->bindings), we also stream out these namespaces' bindings.
This is all rebuilt when streaming in, so calling
pph_add_bindings_to_namespace (NAMESPACE_LEVEL (t), t);
seems like it's trying to add to namespace t all the bindings that are
already in it... (unless pushdecl_into_namespace does more magic then
adding the bindings to the namespace?)

To me this only made sense if we had found a corresponding namespace
we wanted to merge the streamed in bindings into...

Otherwise I agree we will need to modify
pph_add_bindings_to_namespace. It is still missing the merge of
"usings" and "using_directives". "static_decls" if I remember
correctly were automatically reinserted when doing
pushdecl_into_namespace for the static decls in "names".

Gab


[pph] Add FIXME comment to avoid finalizing decls when generating pph image. (issue4626099)

2011-07-06 Thread Gabriel Charette
We do not need to finalize decls and add them to the varpool when generating 
the pph image as we will do this when streaming in (lto also already does it 
this way).

I simply added a comment for now, because this will not fix anything, it will 
simply avoid streaming out unecessary stuff. Since this is not in the front-end 
it is not as easy as checking pph_out_file != NULL here.

Gab

diff --git a/gcc/ChangeLog.pph b/gcc/ChangeLog.pph
index b9aeb4d..2776bf0 100644
--- a/gcc/ChangeLog.pph
+++ b/gcc/ChangeLog.pph
@@ -1,3 +1,7 @@
+2011-07-06  Gabriel Charette  
+
+   * passes.c (rest_of_decl_compilation): Add FIXME pph comment.
+
 2011-07-05  Diego Novillo  
 
Merge from trunk rev 175832.
diff --git a/gcc/passes.c b/gcc/passes.c
index fc9767e..ce7f846 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -184,7 +184,9 @@ rest_of_decl_compilation (tree decl,
  && !DECL_EXTERNAL (decl))
{
  /* When reading LTO unit, we also read varpool, so do not
-rebuild it.  */
+rebuild it.
+FIXME pph: This is also true for pph and we should not
+call varpool_finalize_decl when generating a pph image.  */
  if (in_lto_p && !at_end)
;
  else if (TREE_CODE (decl) != FUNCTION_DECL)

--
This patch is available for review at http://codereview.appspot.com/4626099


Re: [pph] Test cleanup (issue4572050)

2011-07-06 Thread Gabriel Charette
After having a look at how pph.exp works last Friday I think I could
do this myself easily enough.

Or are you still modifying the tests and want me to avoid touching this for now?

Gab

On Fri, Jul 1, 2011 at 5:51 PM, Lawrence Crowl  wrote:
> On 7/1/11, Gabriel Charette  wrote:
>> One problem now though: `// pph asm xdiff`, only flags for asm diffs,
>> but those could be different diffs after a change (for the better or
>> worse) and this won't be caught. It's probably hard to get something
>> precise on this, but maybe we could simply add the # of lines of diff
>> expected, e.g. `// pph asm xdiff 32`. Then we XFAIL if the number of
>> expected lines in the diff match, but actually fail if the number of
>> lines in the diff is now different.
>>
>> I'm not very familiar with dg.. Is that doable? Would be very helpful
>> at this stage.
>
> That looks easy enough.  I need to finish the current test stuff
> before I get to that though.
>
> --
> Lawrence Crowl
>


[pph] Stream DECL_CHAIN only for VAR/FUNCTION_DECLs that are part of a RECORD_OR_UNION_TYPE (issue4672055)

2011-07-08 Thread Gabriel Charette
The fix of streaming DECL_CHAIN in pph for VAR_DECL and FUNCTION_DECL was 
introduced to fix "member not found" errors for structs (and we don't have any 
tests with unions (we probably should...), but I believe they work the same). 
The fix was too general and was actually interfering with something I'm trying 
to do as part of the bug fix I'm on.

This thus restricts the streaming of the DECL_CHAIN for those two types only 
when needed.

Again, this doesn't fix any tests, but helps me in the current bug I'm working 
on.

Tested with bootstrap and pph regression testing.

Gab

2011-07-08  Gabriel Charette  

* pph-streamer-in.c (pph_in_function_decl): Stream in
DECL_CHAIN of FUNCTION_DECL only if it's part of a RECORD_OR_UNION_TYPE
(pph_read_tree): Stream in DECL_CHAIN of VAR_DECL only if it's part
of a RECORD_OR_UNION_TYPE.
* pph-streamer-out.c (pph_out_function_decl): Stream out
DECL_CHAIN of FUNCTION_DECL only if it's part of a RECORD_OR_UNION_TYPE
(pph_write_tree): Stream out DECL_CHAIN of VAR_DECL only if it's part
of a RECORD_OR_UNION_TYPE.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 0bab93b..d78ee91 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -1396,7 +1396,8 @@ pph_in_function_decl (pph_stream *stream, tree fndecl)
   pph_in_lang_specific (stream, fndecl);
   DECL_SAVED_TREE (fndecl) = pph_in_tree (stream);
   DECL_STRUCT_FUNCTION (fndecl) = pph_in_struct_function (stream, fndecl);
-  DECL_CHAIN (fndecl) = pph_in_tree (stream);
+  if (DECL_CONTEXT (fndecl) && RECORD_OR_UNION_TYPE_P (DECL_CONTEXT (fndecl)))
+DECL_CHAIN (fndecl) = pph_in_tree (stream);
   if (DECL_SAVED_TREE (fndecl))
 VEC_safe_push (tree, gc, stream->fns_to_expand, fndecl);
 }
@@ -1436,7 +1437,9 @@ pph_read_tree (struct lto_input_block *ib 
ATTRIBUTE_UNUSED,
   DECL_INITIAL (expr) = pph_in_tree (stream);
   pph_in_lang_specific (stream, expr);
   /* DECL_CHAIN is handled by generic code, except for VAR_DECLs.  */
-  if (TREE_CODE (expr) == VAR_DECL)
+  if (TREE_CODE (expr) == VAR_DECL
+ && DECL_CONTEXT (expr)
+ && RECORD_OR_UNION_TYPE_P (DECL_CONTEXT (expr)))
DECL_CHAIN (expr) = pph_in_tree (stream);
   break;
 
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index 089bb13..d1e757f 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -1257,7 +1257,8 @@ pph_out_function_decl (pph_stream *stream, tree fndecl, 
bool ref_p)
   pph_out_lang_specific (stream, fndecl, ref_p);
   pph_out_tree_or_ref_1 (stream, DECL_SAVED_TREE (fndecl), ref_p, 3);
   pph_out_struct_function (stream, DECL_STRUCT_FUNCTION (fndecl), ref_p);
-  pph_out_tree_or_ref_1 (stream, DECL_CHAIN (fndecl), ref_p, 3);
+  if (DECL_CONTEXT (fndecl) && RECORD_OR_UNION_TYPE_P (DECL_CONTEXT (fndecl)))
+pph_out_tree_or_ref_1 (stream, DECL_CHAIN (fndecl), ref_p, 3);
 }
 
 /* Callback for writing ASTs to a stream.  This writes all the fields
@@ -1292,7 +1293,9 @@ pph_write_tree (struct output_block *ob, tree expr, bool 
ref_p)
   pph_out_tree_or_ref_1 (stream, DECL_INITIAL (expr), ref_p, 3);
   pph_out_lang_specific (stream, expr, ref_p);
   /* DECL_CHAIN is handled by generic code, except for VAR_DECLs.  */
-  if (TREE_CODE (expr) == VAR_DECL)
+  if (TREE_CODE (expr) == VAR_DECL
+ && DECL_CONTEXT (expr)
+ && RECORD_OR_UNION_TYPE_P (DECL_CONTEXT (expr)))
pph_out_tree_or_ref_1 (stream, DECL_CHAIN (expr), ref_p, 3);
   break;
 

--
This patch is available for review at http://codereview.appspot.com/4672055


[pph] Remove protection for NAMESPACE_LEVEL being null when adding namespaces (issue4675069)

2011-07-08 Thread Gabriel Charette
Diego, I know you're working in that area, but the bug fix I'm working on is 
kinda coming up to it too.

I realize you readded those two lines (in patch below) because of an ICE 
(although I still think they don't make sense, i.e. adding the bindings of a 
namespace to itself when they're already in there...). I checked and the only 
reason this fixes your ICE is because it goes through and calls 
varpool_finalize_decl for the names in that namespace bindings, the rest does 
absolutely nothing...

I know you're restructuring this right now, but just in case you're keeping 
some of that logic, I'm sharing my analysis on the matter now instead of 
patching it later...

Also as highlighted in this patch, I don't think we need to validate that 
NAMESPACE_LEVEL != NULL with the "if". It shouldn't be (I think... I even 
tested it with an empty namespace...), if anything maybe we want to assert, but 
not skip if it's NULL in my opinion.

Tested with bootstrap and pph regression testing.

Gab

2011-07-08  Gabriel Charette  

* gcc/cp/pph-streamer-in.c (pph_add_bindings_to_namespace):
NAMESPACE_LEVEL should never be null for a namespace, removed check.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index d78ee91..55f7e12 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -1168,8 +1168,7 @@ pph_add_bindings_to_namespace (struct cp_binding_level 
*bl, tree ns)
 Preserve it.  */
   chain = DECL_CHAIN (t);
   pushdecl_into_namespace (t, ns);
-  if (NAMESPACE_LEVEL (t))
-   pph_add_bindings_to_namespace (NAMESPACE_LEVEL (t), t);
+  pph_add_bindings_to_namespace (NAMESPACE_LEVEL (t), t);
 }
 }
 

--
This patch is available for review at http://codereview.appspot.com/4675069


[pph] Stream out chains backwards (issue4657092)

2011-07-11 Thread Gabriel Charette
**This patch goes on top of patches in issues 4672055 and 4675069 (which have 
yet to be committed)**

Some things are built as soon as a tree is streamed in, and since the chains 
are backwards, flipping them after streaming them in is not sufficient as some 
things (e.g. unique numbers given to functions) have already been allocated.

The solution is to stream out the chain backwards to begin with.

This fixes the assembly diffs in which the LFB# were different in the pph and 
non-pph assembly.

As noted by a FIXME comment, we probably want to do this for usings and 
using_directives as well, but I didn't for this patch as we don't handle those 
yet, and I'm not sure whether their chain is flipped or not.

Fixed tests x1functions and c1pr36533.
The c1pr44948-1a test changed from an ICE in lto_streamer_cache_get to an ICE 
in lto_get_pickled_tree, but lto_get_pickled_tree calls lto_streamer_cache_get 
and I'm pretty sure this is the same bug, not a new one introduced by this 
patch.

Tested with bootstrap build and pph regression testing.

2011-07-11  Gabriel Charette  

* pph-streamer-in.c (pph_add_bindings_to_namespace): Don't reverse 
names and namespaces chains. Reverse names and namespaces
only for the binding levels of namespaces streamed in as is.
* pph-streamer-out.c (pph_out_chained_tree): New.
(pph_out_chain_filtered): Add REVERSE parameter.
(pph_out_binding_level): Use REVERSE parameter of
pph_out_chain_filtered.
* g++.dg/pph/c1pr36533.cc: Expect no asm difference.
* g++.dg/pph/c1pr44948-1a.cc: Adjust XFAIL pattern.
* g++.dg/pph/x1functions.cc: Expect no asm difference.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index 55f7e12..fde1b93 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -1146,11 +1146,6 @@ pph_add_bindings_to_namespace (struct cp_binding_level 
*bl, tree ns)
 {
   tree t, chain;
 
-  /* The chains are built backwards (ref: add_decl_to_level),
- reverse them before putting them back in.  */
-  bl->names = nreverse (bl->names);
-  bl->namespaces = nreverse (bl->namespaces);
-
   for (t = bl->names; t; t = chain)
 {
   /* Pushing a decl into a scope clobbers its DECL_CHAIN.
@@ -1164,11 +1159,26 @@ pph_add_bindings_to_namespace (struct cp_binding_level 
*bl, tree ns)
 
   for (t = bl->namespaces; t; t = chain)
 {
+  struct cp_binding_level* ns_lvl;
+
   /* Pushing a decl into a scope clobbers its DECL_CHAIN.
 Preserve it.  */
   chain = DECL_CHAIN (t);
   pushdecl_into_namespace (t, ns);
-  pph_add_bindings_to_namespace (NAMESPACE_LEVEL (t), t);
+
+  /* FIXME pph: verify whether this namespace exists already,
+if it does we should merge it.  */
+  ns_lvl = NAMESPACE_LEVEL (t);
+  /* FIXME pph: the only benefit of making this call is the embedded call 
to
+varpool_finalize_decl for the names contained in this namespace and
+it's transitive closure of namespaces, the bindings themselves do NOT
+need to be added to this namespace as they are already part of it.  */
+  pph_add_bindings_to_namespace (ns_lvl, t);
+  /* Adding the bindings to another namespace automatically reverses them, 
but
+since these were already part of this namespace, they weren't: reverse
+them in place now.  */
+  ns_lvl->names = nreverse (ns_lvl->names);
+  ns_lvl->namespaces = nreverse (ns_lvl->namespaces);
 }
 }
 
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index d1e757f..445fca5 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -584,21 +584,44 @@ pph_out_label_binding (pph_stream *stream, 
cp_label_binding *lb, bool ref_p)
 }
 
 
+/* Outputs chained tree T by nulling out it's chain first and restoring it
+   after the streaming is done. STREAM and REF_P are as in
+   pph_out_chain_filtered.  */
+
+static inline void
+pph_out_chained_tree (pph_stream *stream, tree t, bool ref_p)
+{
+  tree saved_chain;
+
+  saved_chain = TREE_CHAIN (t);
+  TREE_CHAIN (t) = NULL_TREE;
+
+  pph_out_tree_or_ref_1 (stream, t, ref_p, 2);
+
+  TREE_CHAIN (t) = saved_chain;
+}
+
+
 /* Output a chain of nodes to STREAM starting with FIRST.  Skip any
nodes that do not match FILTER.  REF_P is true if nodes in the chain
-   should be emitted as references.  */
+   should be emitted as references.  Stream the chain in the reverse order
+   if REVERSE is true.*/
 
 static void
 pph_out_chain_filtered (pph_stream *stream, tree first, bool ref_p,
-  enum chain_filter filter)
+  enum chain_filter filter, bool reverse)
 {
   unsigned count;
+  int i;
   tree t;
+  tree *to_stream = NULL;
 
   /* Special case.  If the caller wants no filtering, it is much
  faster to just call pph_out_chain directly.  */
   if (filter == NONE)
   

Re: [pph] Mark c4pr36533.cc fixed (issue4708041)

2011-07-12 Thread Gabriel Charette
My patch at http://codereview.appspot.com/4657092/ was fixing this.

Did you apply that already? I didn't see it as part of your commits to date?

Gab

On Tue, Jul 12, 2011 at 5:55 AM, Diego Novillo  wrote:
>
> Not quite sure what patch fixed this one and I'm too lazy to figure it out
> now.
>
> Committed to branch.
>
>
> Diego.
>
>        * g++.dg/pph/c4pr36533.cc: Mark fixed.
>
> diff --git a/gcc/testsuite/g++.dg/pph/c4pr36533.cc 
> b/gcc/testsuite/g++.dg/pph/c4pr36533.cc
> index 0093db1..ce2bf1f 100644
> --- a/gcc/testsuite/g++.dg/pph/c4pr36533.cc
> +++ b/gcc/testsuite/g++.dg/pph/c4pr36533.cc
> @@ -1,3 +1,2 @@
>  /* { dg-options "-w -fpermissive" } */
> -// pph asm xdiff
>  #include "c4pr36533.h"
>
> --
> This patch is available for review at http://codereview.appspot.com/4708041


Re: [pph] Add alternate addresses to register in the cache (issue4685054)

2011-07-12 Thread Gabriel Charette
Re-adding gcc-patches (forgot to send plain text last time...sigh!)

On Tue, Jul 12, 2011 at 10:56 AM, Gabriel Charette  wrote:
> I like this implementation!
> Only one thing, if we ACTUALLY want "to_register" NULL instead of the read
> value we can't as in your current implementation NULL means don't do the
> alternate registration.
> Could that be a problem or do we expect the structures we pass to this to
> always be non-null? (i.e. for scope_chain->bindings this is definitely ok,
> but what about other potential uses?), if we keep it this way we should at
> least make it clear in the function's comment that NULL means don't do
> alternate registration I think.
> Gab
>
> On Mon, Jul 11, 2011 at 2:42 PM, Diego Novillo  wrote:
>>
>> This patch adapts an idea from Gab that allow us to register alternate
>> addresses in the cache.  The problem here is making sure that symbols
>> read from a PPH file reference the right bindings.
>>
>> If a symbol is in the global namespace when compiling a header file,
>> its bindings will point to NAMESPACE_LEVEL(global_namespace)->bindings,
>> but that global_namespace is the global_namespace instantiated for the
>> header file.  When reading that PPH image from a translation unit, we
>> need to refer to the bindings of the *current* global_namespace.
>>
>> In general we solve this by inserting the pointer in the streamer
>> cache.  For instance, to avoid instantiating a second global_namespace
>> decl, the initialization code of both the writer and the reader store
>> global_namespace into the streaming cache.  This way, all the
>> references to global_namespace point to the current global_namespace
>> as known by the writer and the reader.
>>
>> However, we cannot use the same trick on the bindings for
>> global_namespace.  If we simply inserted it into the cache then
>> writing out NAMESPACE_LEVEL(global_namespace)->bindings would simply
>> write a reference to the current one and on the reader side, it would
>> simply restore a pointer to the current translation unit's bindings.
>> Without ever actually writing or reading anything (since it was
>> satisified from the cache).
>>
>> Therefore, we want a mechanism that allows the reader to: (a) read all
>> the symbols in the global bindings, and (b) references to the
>> global binding made by the symbols should point to the global bindings
>> of the current translation unit (instead of the one in the PPH image).
>>
>> That's where ALLOC_AND_REGISTER_ALTERNATE comes in.  When called, it
>> allocates the data structure but registers another pointer in the
>> cache.  We use this trick when calling pph_in_binding_level from the
>> toplevel:
>>
>> +  new_bindings = pph_in_binding_level (stream, scope_chain->bindings);
>>
>> This way, when pph_in_binding_level tries to allocate the binding
>> structure read from STREAM, it registers scope_chain->bindings in the
>> cache.  This way, references to the original file's global binding are
>> automatically redirected to the current translation unit's global
>> bindings.
>>
>> Gab, I modified your original implementation to move all the logic to
>> the place where we need to make this decision.  This way, it is easier
>> to tell which functions need this alternate registration, instead of
>> relying on some status flag squirreled away in the STREAM data
>> structure.
>>
>>
>> Tested on x86_64.  Applied to branch.
>>
>> 2011-07-11   Diego Novillo  
>>             Gabriel Charette  
>>
>>        * pph-streamer-in.c (ALLOC_AND_REGISTER_ALTERNATE): Define.
>>        (pph_in_binding_level): Add argument TO_REGISTER.  Call
>>        ALLOC_AND_REGISTER_ALTERNATE if set.
>>        Update all users.
>>        (pph_register_decls_in_symtab): Call varpool_finalize_decl
>>        on all file-local symbols.
>>        (pph_in_scope_chain): Call pph_in_binding_level with
>>        scope_chain->bindings as the alternate pointer to
>>        register in the streaming cache.
>>
>> diff --git a/gcc/cp/ChangeLog.pph b/gcc/cp/ChangeLog.pph
>> index 1011902..f18c2f4 100644
>> --- a/gcc/cp/ChangeLog.pph
>> +++ b/gcc/cp/ChangeLog.pph
>> @@ -1,3 +1,16 @@
>> +2011-07-11   Diego Novillo  
>> +            Gabriel Charette  
>> +
>> +       * pph-streamer-in.c (ALLOC_AND_REGISTER_ALTERNATE): Define.
>> +       (pph_in_binding_level): Add argument TO_REGISTER.  Call
>> +       ALLOC_AND_REGISTER_ALTERNATE if set.
>> +       Update all users.
&g

Re: [pph] Add alternate addresses to register in the cache (issue4685054)

2011-07-12 Thread Gabriel Charette
Right, I remember my original implementation had the same behaviour,
but I'm pretty sure I had a comment mentioning that in the function
usage comment. I'm just saying it should be mentioned what passing
NULL means (especially since we do it all over the place).

On Tue, Jul 12, 2011 at 11:14 AM, Diego Novillo  wrote:
> On Tue, Jul 12, 2011 at 13:56, Gabriel Charette  wrote:
>> I like this implementation!
>> Only one thing, if we ACTUALLY want "to_register" NULL instead of the read
>> value we can't as in your current implementation NULL means don't do the
>> alternate registration.
>
> I don't think that's a problem.  Note too that the original
> implementation also treated NULL to mean "don't do alternate
> registration".
>
>
> Diego.
>


Re: [pph] Fix 3 asm differences (issue4695048)

2011-07-12 Thread Gabriel Charette
I like the modified implementation with VEC.

We probably want pph_register_decl_in_symtab to be inline as it does
so little now.

Now that you simply chainon bindings, you probably want to nreverse
them before you chain them on (this way we will stream them in from
first->last as this pacth does (to alloc stuff in order), but them in
the chain we want them to be last->first as they should be if they had
been pushed as they are in the original parser).

Gab

On Tue, Jul 12, 2011 at 12:19 PM, Diego Novillo  wrote:
>
> This patch is a slight adaptation of Gab's fix to the order in which
> we stream chains (http://codereview.appspot.com/4657092).  I mostly
> just changed how we keep the temporary list to reverse (it now uses a
> VEC instead of a custom-build linked list).
>
> The other change is in the reader.  We were not registering symbols in
> scope_chain->static_aggregates as they come from the PPH file (which
> would cause an ICE in x1hardlookup.cc).
>
> This fixes 3 tests, but we still have some asm differences that are
> similar in nature: when reinstantiating PPH images, the compiler emits
> some symbols in different order, causing different numbering and
> naming in the assembler output (we need to generate identical output
> from a pph or from text).
>
> Tested on x86_64.  Committed to branch.
>
>
> Diego.
>
> 2011-07-12   Diego Novillo  
>
>        * pph-streamer-in.c (pph_register_decl_in_symtab): New.
>        (pph_register_binding_in_symtab): Rename from
>        pph_register_decls_in_symtab.  Update all users.
>        Do not call nreverse on bl->names and bl->namespaces.
>        Call pph_register_decl_in_symtab.
>        (pph_read_file_contents): Register decls in
>        FILE_STATIC_AGGREGATES.
>
> 2011-07-12  Gabriel Charette  
>            Diego Novillo  
>
>        * pph-streamer-out.c (pph_out_chained_tree): New.
>        (pph_out_chain_filtered): Add REVERSE_P parameter.
>        If REVERSE_P is set, write the list in reverse order.
>        Update all users.
>        (pph_out_binding_level): Write out lists bl->names,
>        bl->namespaces, bl->usings and bl->using_directives in
>        reverse.
>
>
> testsuite/ChangeLog.pph
> 2011-07-12  Gabriel Charette  
>
>        * g++.dg/pph/c1pr44948-1a.cc: Mark fixed.
>        * g++.dg/pph/c2pr36533.cc: Mark fixed.
>        * g++.dg/pph/x2functions.cc: Mark fixed.
>
> diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
> index 63f8965..e7d1d00 100644
> --- a/gcc/cp/pph-streamer-in.c
> +++ b/gcc/cp/pph-streamer-in.c
> @@ -1175,29 +1175,33 @@ pph_in_lang_type (pph_stream *stream)
>  }
>
>
> +/* Register DECL with the middle end.  */
> +
> +static void
> +pph_register_decl_in_symtab (tree decl)
> +{
> +  if (TREE_CODE (decl) == VAR_DECL
> +      && TREE_STATIC (decl)
> +      && !DECL_EXTERNAL (decl))
> +    varpool_finalize_decl (decl);
> +}
> +
> +
>  /* Register all the symbols in binding level BL in the callgraph symbol
>    table.  */
>
>  static void
> -pph_register_decls_in_symtab (struct cp_binding_level *bl)
> +pph_register_binding_in_symtab (struct cp_binding_level *bl)
>  {
>   tree t;
>
> -  /* The chains are built backwards (ref: add_decl_to_level),
> -     reverse them before putting them back in.  */
> -  bl->names = nreverse (bl->names);
> -  bl->namespaces = nreverse (bl->namespaces);
> -
> +  /* Add file-local symbols to the varpool.  */
>   for (t = bl->names; t; t = DECL_CHAIN (t))
> -    {
> -      /* Add file-local symbols to the varpool.  */
> -      if (TREE_CODE (t) == VAR_DECL && TREE_STATIC (t) && !DECL_EXTERNAL (t))
> -       varpool_finalize_decl (t);
> -    }
> +    pph_register_decl_in_symtab (t);
>
>   /* Recurse into the namespaces contained in BL.  */
>   for (t = bl->namespaces; t; t = DECL_CHAIN (t))
> -    pph_register_decls_in_symtab (NAMESPACE_LEVEL (t));
> +    pph_register_binding_in_symtab (NAMESPACE_LEVEL (t));
>  }
>
>
> @@ -1220,7 +1224,7 @@ pph_in_scope_chain (pph_stream *stream)
>   new_bindings = pph_in_binding_level (stream, scope_chain->bindings);
>
>   /* Register all the symbols in STREAM with the call graph.  */
> -  pph_register_decls_in_symtab (new_bindings);
> +  pph_register_binding_in_symtab (new_bindings);
>
>   /* Merge the bindings from STREAM into saved_scope->bindings.  */
>   chainon (cur_bindings->names, new_bindings->names);
> @@ -1413,6 +1417,16 @@ pph_read_file_contents (pph_stream *stream)
>   file_static_aggregates = pph_in_tree (stream);
>   static_aggregates = chainon (file_static_aggregates, static_aggregates);
>
> +  /* Re

  1   2   >