Patchwork [libcpp] Do not decrease highest_location if the included file has be included twice.

login
register
mail settings
Submitter Dehao Chen
Date June 4, 2013, 5:02 p.m.
Message ID <CAO2gOZWUNmH343ZF6sACs66o5KY51KSgSaF4izqKTM_fUSnJCQ@mail.gmail.com>
Download mbox | patch
Permalink /patch/248767/
State New
Headers show

Comments

Dehao Chen - June 4, 2013, 5:02 p.m.
Hi, Dodji,

Thanks for helping update the patch. The new patch passed all
regression test and can fix the problem in my huge source file. I
added ChangeLog entry to the patch. Could any libcpp maintainers help
check if it is ok for trunk?

Thanks,
Dehao

libcpp/ChangeLog:

2013-06-04  Dehao Chen  <dehao@google.com>

 * files.c (_cpp_stack_include): Fix the highest_location when header
 file is guarded by #ifndef and is included twice.
Dehao Chen - June 7, 2013, 4:22 a.m.
ping...

On Tue, Jun 4, 2013 at 10:02 AM, Dehao Chen <dehao@google.com> wrote:
> Hi, Dodji,
>
> Thanks for helping update the patch. The new patch passed all
> regression test and can fix the problem in my huge source file. I
> added ChangeLog entry to the patch. Could any libcpp maintainers help
> check if it is ok for trunk?
>
> Thanks,
> Dehao
>
> libcpp/ChangeLog:
>
> 2013-06-04  Dehao Chen  <dehao@google.com>
>
>  * files.c (_cpp_stack_include): Fix the highest_location when header
>  file is guarded by #ifndef and is included twice.
>
> Index: libcpp/files.c
> ===================================================================
> --- libcpp/files.c (revision 199570)
> +++ libcpp/files.c (working copy)
> @@ -983,6 +983,7 @@ _cpp_stack_include (cpp_reader *pfile, const char
>  {
>    struct cpp_dir *dir;
>    _cpp_file *file;
> +  bool stacked;
>
>    dir = search_path_head (pfile, fname, angle_brackets, type);
>    if (!dir)
> @@ -993,19 +994,26 @@ _cpp_stack_include (cpp_reader *pfile, const char
>    if (type == IT_DEFAULT && file == NULL)
>      return false;
>
> -  /* Compensate for the increment in linemap_add that occurs in
> -     _cpp_stack_file.  In the case of a normal #include, we're
> -     currently at the start of the line *following* the #include.  A
> -     separate source_location for this location makes no sense (until
> -     we do the LC_LEAVE), and complicates LAST_SOURCE_LINE_LOCATION.
> -     This does not apply if we found a PCH file (in which case
> -     linemap_add is not called) or we were included from the
> -     command-line.  */
> +  /* Compensate for the increment in linemap_add that occurs if
> +      _cpp_stack_file actually stacks the file.  In the case of a
> +     normal #include, we're currently at the start of the line
> +     *following* the #include.  A separate source_location for this
> +     location makes no sense (until we do the LC_LEAVE), and
> +     complicates LAST_SOURCE_LINE_LOCATION.  This does not apply if we
> +     found a PCH file (in which case linemap_add is not called) or we
> +     were included from the command-line.  */
>    if (file->pchname == NULL && file->err_no == 0
>        && type != IT_CMDLINE && type != IT_DEFAULT)
>      pfile->line_table->highest_location--;
>
> -  return _cpp_stack_file (pfile, file, type == IT_IMPORT);
> +  stacked = _cpp_stack_file (pfile, file, type == IT_IMPORT);
> +
> +  if (!stacked)
> +    /* _cpp_stack_file didn't stack the file, so let's rollback the
> +       compensation dance we performed above.  */
> +    pfile->line_table->highest_location++;
> +
> +  return stacked;
>  }
>
>  /* Could not open FILE.  The complication is dependency output.  */
Dehao Chen - June 15, 2013, 4:49 p.m.
ping ^2

On Tue, Jun 4, 2013 at 10:02 AM, Dehao Chen <dehao@google.com> wrote:
> Hi, Dodji,
>
> Thanks for helping update the patch. The new patch passed all
> regression test and can fix the problem in my huge source file. I
> added ChangeLog entry to the patch. Could any libcpp maintainers help
> check if it is ok for trunk?
>
> Thanks,
> Dehao
>
> libcpp/ChangeLog:
>
> 2013-06-04  Dehao Chen  <dehao@google.com>
>
>  * files.c (_cpp_stack_include): Fix the highest_location when header
>  file is guarded by #ifndef and is included twice.
>
> Index: libcpp/files.c
> ===================================================================
> --- libcpp/files.c (revision 199570)
> +++ libcpp/files.c (working copy)
> @@ -983,6 +983,7 @@ _cpp_stack_include (cpp_reader *pfile, const char
>  {
>    struct cpp_dir *dir;
>    _cpp_file *file;
> +  bool stacked;
>
>    dir = search_path_head (pfile, fname, angle_brackets, type);
>    if (!dir)
> @@ -993,19 +994,26 @@ _cpp_stack_include (cpp_reader *pfile, const char
>    if (type == IT_DEFAULT && file == NULL)
>      return false;
>
> -  /* Compensate for the increment in linemap_add that occurs in
> -     _cpp_stack_file.  In the case of a normal #include, we're
> -     currently at the start of the line *following* the #include.  A
> -     separate source_location for this location makes no sense (until
> -     we do the LC_LEAVE), and complicates LAST_SOURCE_LINE_LOCATION.
> -     This does not apply if we found a PCH file (in which case
> -     linemap_add is not called) or we were included from the
> -     command-line.  */
> +  /* Compensate for the increment in linemap_add that occurs if
> +      _cpp_stack_file actually stacks the file.  In the case of a
> +     normal #include, we're currently at the start of the line
> +     *following* the #include.  A separate source_location for this
> +     location makes no sense (until we do the LC_LEAVE), and
> +     complicates LAST_SOURCE_LINE_LOCATION.  This does not apply if we
> +     found a PCH file (in which case linemap_add is not called) or we
> +     were included from the command-line.  */
>    if (file->pchname == NULL && file->err_no == 0
>        && type != IT_CMDLINE && type != IT_DEFAULT)
>      pfile->line_table->highest_location--;
>
> -  return _cpp_stack_file (pfile, file, type == IT_IMPORT);
> +  stacked = _cpp_stack_file (pfile, file, type == IT_IMPORT);
> +
> +  if (!stacked)
> +    /* _cpp_stack_file didn't stack the file, so let's rollback the
> +       compensation dance we performed above.  */
> +    pfile->line_table->highest_location++;
> +
> +  return stacked;
>  }
>
>  /* Could not open FILE.  The complication is dependency output.  */
Dehao Chen - June 22, 2013, 1:04 a.m.
ping ^3

Thx,
Dehao

On Sat, Jun 15, 2013 at 9:48 AM, Dehao Chen <dehao@google.com> wrote:
> ping ^2
>
>
> On Thu, Jun 6, 2013 at 9:22 PM, Dehao Chen <dehao@google.com> wrote:
>>
>> ping...
>>
>> On Tue, Jun 4, 2013 at 10:02 AM, Dehao Chen <dehao@google.com> wrote:
>> > Hi, Dodji,
>> >
>> > Thanks for helping update the patch. The new patch passed all
>> > regression test and can fix the problem in my huge source file. I
>> > added ChangeLog entry to the patch. Could any libcpp maintainers help
>> > check if it is ok for trunk?
>> >
>> > Thanks,
>> > Dehao
>> >
>> > libcpp/ChangeLog:
>> >
>> > 2013-06-04  Dehao Chen  <dehao@google.com>
>> >
>> >  * files.c (_cpp_stack_include): Fix the highest_location when header
>> >  file is guarded by #ifndef and is included twice.
>> >
>> > Index: libcpp/files.c
>> > ===================================================================
>> > --- libcpp/files.c (revision 199570)
>> > +++ libcpp/files.c (working copy)
>> > @@ -983,6 +983,7 @@ _cpp_stack_include (cpp_reader *pfile, const char
>> >  {
>> >    struct cpp_dir *dir;
>> >    _cpp_file *file;
>> > +  bool stacked;
>> >
>> >    dir = search_path_head (pfile, fname, angle_brackets, type);
>> >    if (!dir)
>> > @@ -993,19 +994,26 @@ _cpp_stack_include (cpp_reader *pfile, const char
>> >    if (type == IT_DEFAULT && file == NULL)
>> >      return false;
>> >
>> > -  /* Compensate for the increment in linemap_add that occurs in
>> > -     _cpp_stack_file.  In the case of a normal #include, we're
>> > -     currently at the start of the line *following* the #include.  A
>> > -     separate source_location for this location makes no sense (until
>> > -     we do the LC_LEAVE), and complicates LAST_SOURCE_LINE_LOCATION.
>> > -     This does not apply if we found a PCH file (in which case
>> > -     linemap_add is not called) or we were included from the
>> > -     command-line.  */
>> > +  /* Compensate for the increment in linemap_add that occurs if
>> > +      _cpp_stack_file actually stacks the file.  In the case of a
>> > +     normal #include, we're currently at the start of the line
>> > +     *following* the #include.  A separate source_location for this
>> > +     location makes no sense (until we do the LC_LEAVE), and
>> > +     complicates LAST_SOURCE_LINE_LOCATION.  This does not apply if we
>> > +     found a PCH file (in which case linemap_add is not called) or we
>> > +     were included from the command-line.  */
>> >    if (file->pchname == NULL && file->err_no == 0
>> >        && type != IT_CMDLINE && type != IT_DEFAULT)
>> >      pfile->line_table->highest_location--;
>> >
>> > -  return _cpp_stack_file (pfile, file, type == IT_IMPORT);
>> > +  stacked = _cpp_stack_file (pfile, file, type == IT_IMPORT);
>> > +
>> > +  if (!stacked)
>> > +    /* _cpp_stack_file didn't stack the file, so let's rollback the
>> > +       compensation dance we performed above.  */
>> > +    pfile->line_table->highest_location++;
>> > +
>> > +  return stacked;
>> >  }
>> >
>> >  /* Could not open FILE.  The complication is dependency output.  */
>
>
Tom Tromey - June 24, 2013, 3:09 p.m.
>>>>> "Dehao" == Dehao Chen <dehao@google.com> writes:

Dehao> Thanks for helping update the patch. The new patch passed all
Dehao> regression test and can fix the problem in my huge source file. I
Dehao> added ChangeLog entry to the patch. Could any libcpp maintainers help
Dehao> check if it is ok for trunk?

I'm sorry about the delay on this.

Dehao> 2013-06-04  Dehao Chen  <dehao@google.com>
Dehao>  * files.c (_cpp_stack_include): Fix the highest_location when header
Dehao>  file is guarded by #ifndef and is included twice.

This is ok.  Thanks.

Tom

Patch

Index: libcpp/files.c
===================================================================
--- libcpp/files.c (revision 199570)
+++ libcpp/files.c (working copy)
@@ -983,6 +983,7 @@  _cpp_stack_include (cpp_reader *pfile, const char
 {
   struct cpp_dir *dir;
   _cpp_file *file;
+  bool stacked;

   dir = search_path_head (pfile, fname, angle_brackets, type);
   if (!dir)
@@ -993,19 +994,26 @@  _cpp_stack_include (cpp_reader *pfile, const char
   if (type == IT_DEFAULT && file == NULL)
     return false;

-  /* Compensate for the increment in linemap_add that occurs in
-     _cpp_stack_file.  In the case of a normal #include, we're
-     currently at the start of the line *following* the #include.  A
-     separate source_location for this location makes no sense (until
-     we do the LC_LEAVE), and complicates LAST_SOURCE_LINE_LOCATION.
-     This does not apply if we found a PCH file (in which case
-     linemap_add is not called) or we were included from the
-     command-line.  */
+  /* Compensate for the increment in linemap_add that occurs if
+      _cpp_stack_file actually stacks the file.  In the case of a
+     normal #include, we're currently at the start of the line
+     *following* the #include.  A separate source_location for this
+     location makes no sense (until we do the LC_LEAVE), and
+     complicates LAST_SOURCE_LINE_LOCATION.  This does not apply if we
+     found a PCH file (in which case linemap_add is not called) or we
+     were included from the command-line.  */
   if (file->pchname == NULL && file->err_no == 0
       && type != IT_CMDLINE && type != IT_DEFAULT)
     pfile->line_table->highest_location--;

-  return _cpp_stack_file (pfile, file, type == IT_IMPORT);
+  stacked = _cpp_stack_file (pfile, file, type == IT_IMPORT);
+
+  if (!stacked)
+    /* _cpp_stack_file didn't stack the file, so let's rollback the
+       compensation dance we performed above.  */
+    pfile->line_table->highest_location++;
+
+  return stacked;
 }

 /* Could not open FILE.  The complication is dependency output.  */