public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Eric Botcazou <ebotcazou@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-9701] Fix thinko in libcpp preparation patch for modules
Date: Tue, 13 Apr 2021 11:37:47 +0000 (GMT)	[thread overview]
Message-ID: <20210413113747.281FF3857C48@sourceware.org> (raw)

https://gcc.gnu.org/g:63d4c1b5a4333b8ed709b2c6fd1ef030a1c601b8

commit r10-9701-g63d4c1b5a4333b8ed709b2c6fd1ef030a1c601b8
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Tue Apr 13 11:57:55 2021 +0200

    Fix thinko in libcpp preparation patch for modules
    
    The problem is that the new IS_MACRO_LOC macro:
    
    inline bool
    IS_MACRO_LOC (location_t loc)
    {
      return !IS_ORDINARY_LOC (loc) && !IS_ADHOC_LOC (loc);
    }
    
    is not fully correct since the position of the macro lines is not fixed:
    
    /* Returns the lowest location [of a token resulting from macro
       expansion] encoded in this line table.  */
    inline location_t
    LINEMAPS_MACRO_LOWEST_LOCATION (const line_maps *set)
    {
      return LINEMAPS_MACRO_USED (set)
             ? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set))
             : MAX_LOCATION_T + 1;
    }
    
    In Ada, LINEMAPS_MACRO_USED is false so LINEMAPS_MACRO_LOWEST_LOCATION is
    MAX_LOCATION_T + 1, but IS_MACRO_LOC nevertheless returns true for anything
    in the range [LINE_MAP_MAX_LOCATION; MAX_LOCATION_T], thus yielding an ICE
    in linemap_macro_map_lookup for very large files.
    
    libcpp/
            * include/line-map.h (IS_MACRO_LOC): Delete.
            * line-map.c (linemap_location_from_macro_expansion_p): Test
            LINEMAPS_MACRO_LOWEST_LOCATION of the linemap.

Diff:
---
 libcpp/include/line-map.h | 10 +++-------
 libcpp/line-map.c         |  2 +-
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index dbbc13762e3..916cdebcd6a 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -561,7 +561,7 @@ struct GTY((tag ("2"))) line_map_macro : public line_map {
 #define linemap_assert_fails(EXPR) (! (EXPR))
 #endif
 
-/* Get whether location LOC is an ad-hoc, ordinary or macro location.  */
+/* Get whether location LOC is an ordinary location.  */
 
 inline bool
 IS_ORDINARY_LOC (location_t loc)
@@ -569,18 +569,14 @@ IS_ORDINARY_LOC (location_t loc)
   return loc < LINE_MAP_MAX_LOCATION;
 }
 
+/* Get whether location LOC is an ad-hoc location.  */
+
 inline bool
 IS_ADHOC_LOC (location_t loc)
 {
   return loc > MAX_LOCATION_T;
 }
 
-inline bool
-IS_MACRO_LOC (location_t loc)
-{
-  return !IS_ORDINARY_LOC (loc) && !IS_ADHOC_LOC (loc);
-}
-
 /* Categorize line map kinds.  */
 
 inline bool
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 8a390d0857b..1dce2292522 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -1244,7 +1244,7 @@ linemap_location_from_macro_expansion_p (const class line_maps *set,
   if (IS_ADHOC_LOC (location))
     location = get_location_from_adhoc_loc (set, location);
 
-  return IS_MACRO_LOC (location);
+  return location >= LINEMAPS_MACRO_LOWEST_LOCATION (set);
 }
 
 /* Given two virtual locations *LOC0 and *LOC1, return the first


                 reply	other threads:[~2021-04-13 11:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210413113747.281FF3857C48@sourceware.org \
    --to=ebotcazou@gcc.gnu.org \
    --cc=gcc-cvs@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).