aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2018-10-11 12:42:37 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2018-10-11 12:42:37 +0000
commitc1b48b29294ed58e72129db4db42adab3d0d1a9a (patch)
tree32a29d7459eecd3699a84f59acf2073799e71dbc /libcpp
parentc7790bdbd97889b39fde3e0249b398a9bf5fb43b (diff)
downloadgcc-c1b48b29294ed58e72129db4db42adab3d0d1a9a.zip
gcc-c1b48b29294ed58e72129db4db42adab3d0d1a9a.tar.gz
gcc-c1b48b29294ed58e72129db4db42adab3d0d1a9a.tar.bz2
[PATCH] A couple of line map fixes
https://gcc.gnu.org/ml/gcc-patches/2018-10/msg00623.html * include/line-map.h (LINEMAPS_MACRO_LOWEST_LOCATION): Fix off-by-one error. * line-map.c (linemap_enter_macro): Use RAII. Clear all of the macro_locations. From-SVN: r265037
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog7
-rw-r--r--libcpp/include/line-map.h2
-rw-r--r--libcpp/line-map.c20
3 files changed, 15 insertions, 14 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 6681101..fe0dc8d 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,10 @@
+2018-10-11 Nathan Sidwell <nathan@acm.org>
+
+ * include/line-map.h (LINEMAPS_MACRO_LOWEST_LOCATION): Fix
+ off-by-one error.
+ * line-map.c (linemap_enter_macro): Use RAII. Clear all of the
+ macro_locations.
+
2018-10-09 David Malcolm <dmalcolm@redhat.com>
* charset.c (noop_error_cb): Rename to...
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index c479dfa..23f0e4a 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -1017,7 +1017,7 @@ LINEMAPS_MACRO_LOWEST_LOCATION (const line_maps *set)
{
return LINEMAPS_MACRO_USED (set)
? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set))
- : MAX_SOURCE_LOCATION;
+ : MAX_SOURCE_LOCATION + 1;
}
/* Returns the last macro map allocated in the line table SET. */
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 73d9444..66d92cf 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -612,30 +612,24 @@ const line_map_macro *
linemap_enter_macro (struct line_maps *set, struct cpp_hashnode *macro_node,
source_location expansion, unsigned int num_tokens)
{
- line_map_macro *map;
- source_location start_location;
- /* Cast away extern "C" from the type of xrealloc. */
- line_map_realloc reallocator = (set->reallocator
- ? set->reallocator
- : (line_map_realloc) xrealloc);
-
- start_location = LINEMAPS_MACRO_LOWEST_LOCATION (set) - num_tokens;
+ source_location start_location
+ = LINEMAPS_MACRO_LOWEST_LOCATION (set) - num_tokens;
if (start_location < LINE_MAP_MAX_LOCATION)
/* We ran out of macro map space. */
return NULL;
- map = linemap_check_macro (new_linemap (set, start_location));
+ line_map_macro *map = linemap_check_macro (new_linemap (set, start_location));
map->macro = macro_node;
map->n_tokens = num_tokens;
map->macro_locations
- = (source_location*) reallocator (NULL,
- 2 * num_tokens
- * sizeof (source_location));
+ = (source_location*) set->reallocator (NULL,
+ 2 * num_tokens
+ * sizeof (source_location));
map->expansion = expansion;
memset (MACRO_MAP_LOCATIONS (map), 0,
- num_tokens * sizeof (source_location));
+ 2 * num_tokens * sizeof (source_location));
LINEMAPS_MACRO_CACHE (set) = LINEMAPS_MACRO_USED (set) - 1;