From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A10C03857C45; Sat, 25 Feb 2023 14:50:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A10C03857C45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677336619; bh=Wcrl7mkBOrns0MC/pXhC8WRHND6K87e764WPCD9ds10=; h=From:To:Subject:Date:In-Reply-To:References:From; b=k9UtZM5h0rZGy36v6z2q7rK2WxPSg01e3ZYLHzwk9iy1ZFDGUuX8a5HxUE5WsA7ew 0vXmUTHdZlo21r3s7uu9TOXhv2Hj2biSb1Hpc2Vdnv3D473trHoLgdYaSlRfgMJdTe 2U3kPP+wE57/pM6ldeARwtX+LTDuzuNftefsXMDA= From: "libin.dang at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: preprocessor X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: libin.dang at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108900 --- Comment #1 from Libin Dang --- 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 <=3D 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 <=3D 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 <=3D 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 <=3D loc < 1342178464', this do= es not look right. And Map 12 suppose to have location information for `header3 e= nds' 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 =3D=3D NULL) { + /* Adjust for LC_RENAME in some special cases */ + while (from->to_file =3D=3D from[1].to_file && from->included_fr= om =3D=3D 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_lin= e, && line_delta * map->m_column_and_range_bits > 1000) || (max_column_hint >=3D (1U << effective_column_bits)) || (max_column_hint <=3D 80 && effective_column_bits >=3D 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 >=3D LINE_MAP_MAX_LOCATION))) add_map =3D true; However, neither of them looks right.=