public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "libin.dang at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug preprocessor/108900] [libcpp] cpp gives wrong line number information with a file huge number of lines
Date: Sat, 25 Feb 2023 14:50:18 +0000	[thread overview]
Message-ID: <bug-108900-4-3aEqFcIy4d@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-108900-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108900

--- Comment #1 from Libin Dang <libin.dang at gmail dot com> ---
For this test case, `-fdump-internal-locations' gives:

...
header3.h:327614|loc:1342177760|#include "header2.h"
                               |77777778888888888888
                               |78889990001112223334
                               |92582581481470470360
                               |24680246802468024680

ORDINARY MAP: 10
  location_t interval: 1342178464 <= loc < 1342178464
  file: header3.h
  starting at line: 327615
  column and range bits: 7
  column bits: 7
  range bits: 0
  reason: 2 (LC_RENAME)
  included from location: 270816 (in ordinary map 8)

ORDINARY MAP: 11
  location_t interval: 1342178464 <= loc < 1342178496
  file: header2.h
  starting at line: 1
  column and range bits: 7
  column bits: 7
  range bits: 0
  reason: 0 (LC_ENTER)
  included from location: 1342178336 (in ordinary map 9)
header2.h:  1|loc:1342178464|
                            |
                            |
                            |
                            |

ORDINARY MAP: 12
  location_t interval: 1342178496 <= loc < 1342178528
  file: header3.h
  starting at line: 327614
  column and range bits: 7
  column bits: 7
  range bits: 0
  reason: 1 (LC_LEAVE)
  included from location: 270816 (in ordinary map 8)
header3.h:327614|loc:1342178496|#include "header2.h"
                               |88888888888888888888
                               |44455555555555555555
                               |99900000000001111111
                               |78901234567890123456
...

Map 10 has `location_t interval: 1342178464 <= loc < 1342178464', this does not
look right.  And Map 12 suppose to have location information for `header3 ends'
instead of `#include "header2.h"'.

Both the following changes can fix this issue (at least for this test case):

diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 8a390d0..991170e 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -524,6 +524,10 @@ linemap_add (line_maps *set, enum lc_reason reason,
       /* A TO_FILE of NULL is special - we use the natural values.  */
       if (to_file == NULL)
         {
+          /* Adjust for LC_RENAME in some special cases */
+          while (from->to_file == from[1].to_file && from->included_from ==
from[1].included_from)
+            ++from;
+


diff --git a/libcpp/line-map.cc b/libcpp/line-map.cc
index 62077c3857c0..452016f377c9 100644
--- a/libcpp/line-map.cc
+++ b/libcpp/line-map.cc
@@ -775,8 +775,6 @@ linemap_line_start (line_maps *set, linenum_type to_line,
          && line_delta * map->m_column_and_range_bits > 1000)
       || (max_column_hint >= (1U << effective_column_bits))
       || (max_column_hint <= 80 && effective_column_bits >= 10)
-      || (highest > LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES
-         && map->m_range_bits > 0)
       || (highest > LINE_MAP_MAX_LOCATION_WITH_COLS
          && (set->max_column_hint || highest >= LINE_MAP_MAX_LOCATION)))
     add_map = true;


However, neither of them looks right.

  reply	other threads:[~2023-02-25 14:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23  8:35 [Bug preprocessor/108900] New: [libcpp] cpp gives wrong line number information libin.dang at gmail dot com
2023-02-25 14:50 ` libin.dang at gmail dot com [this message]
2023-05-04 10:19 ` [Bug preprocessor/108900] [libcpp] cpp gives wrong line number information with a file huge number of lines libin.dang at gmail dot com
2023-12-28 14:10 ` libin.dang at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-108900-4-3aEqFcIy4d@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).