This is the right patch that I bootstrapped and tested. * line-map.c (linemap_macro_map_lookup): Make sure to always pick the map with the highest MAP_START_LOCATION. --- libcpp/line-map.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/libcpp/line-map.c b/libcpp/line-map.c index 352d697..ecfcfd0 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -588,14 +588,19 @@ linemap_macro_map_lookup (struct line_maps *set, source_location line) mn = 0; } - do + while (mx - mn > 1) { md = (mx + mn) / 2; if (MAP_START_LOCATION (LINEMAPS_MACRO_MAP_AT (set, md)) > line) mn = md; else mx = md; - } while (mx - mn > 1); + } + + /* There are cases where mx - mn = 1 and where the map we want is + mn. Let's not miss it. */ + if (MAP_START_LOCATION (LINEMAPS_MACRO_MAP_AT (set, mn)) <= line) + mx = mn; LINEMAPS_MACRO_CACHE (set) = mx; result = LINEMAPS_MACRO_MAP_AT (set, LINEMAPS_MACRO_CACHE (set)); -- 1.7.6.4 -- Dodji