@@ -1709,11 +1709,7 @@ gimple_block (const gimple *g)
static inline void
gimple_set_block (gimple *g, tree block)
{
- if (block)
- g->location =
- COMBINE_LOCATION_DATA (line_table, g->location, block);
- else
- g->location = LOCATION_LOCUS (g->location);
+ g->location = set_block (g->location, block);
}
@@ -6739,10 +6739,7 @@ move_block_to_fn (struct function *dest_cfun, basic_block bb,
continue;
if (d->orig_block == NULL_TREE || block == d->orig_block)
{
- if (d->new_block == NULL_TREE)
- locus = LOCATION_LOCUS (locus);
- else
- locus = COMBINE_LOCATION_DATA (line_table, locus, d->new_block);
+ locus = set_block (locus, d->new_block);
gimple_phi_arg_set_location (phi, i, locus);
}
}
@@ -6802,9 +6799,7 @@ move_block_to_fn (struct function *dest_cfun, basic_block bb,
tree block = LOCATION_BLOCK (e->goto_locus);
if (d->orig_block == NULL_TREE
|| block == d->orig_block)
- e->goto_locus = d->new_block ?
- COMBINE_LOCATION_DATA (line_table, e->goto_locus, d->new_block) :
- LOCATION_LOCUS (e->goto_locus);
+ e->goto_locus = set_block (e->goto_locus, d->new_block);
}
}
@@ -2352,10 +2352,7 @@ copy_phis_for_bb (basic_block bb, copy_body_data *id)
tree *n;
n = id->decl_map->get (LOCATION_BLOCK (locus));
gcc_assert (n);
- if (*n)
- locus = COMBINE_LOCATION_DATA (line_table, locus, *n);
- else
- locus = LOCATION_LOCUS (locus);
+ locus = set_block (locus, *n);
}
else
locus = LOCATION_LOCUS (locus);
@@ -11669,10 +11669,7 @@ tree_set_block (tree t, tree b)
if (IS_EXPR_CODE_CLASS (c))
{
- if (b)
- t->exp.locus = COMBINE_LOCATION_DATA (line_table, t->exp.locus, b);
- else
- t->exp.locus = LOCATION_LOCUS (t->exp.locus);
+ t->exp.locus = set_block (t->exp.locus, b);
}
else
gcc_unreachable ();
@@ -13656,5 +13653,11 @@ nonnull_arg_p (const_tree arg)
return false;
}
+location_t
+set_block (location_t loc, tree block)
+{
+ source_range src_range = get_range_from_loc (line_table, loc);
+ return COMBINE_LOCATION_DATA (line_table, loc, src_range, block);
+}
#include "gt-tree.h"
@@ -5139,6 +5139,9 @@ type_with_alias_set_p (const_tree t)
return false;
}
+extern location_t
+set_block (location_t loc, tree block);
+
extern void gt_ggc_mx (tree &);
extern void gt_pch_nx (tree &);
extern void gt_pch_nx (tree &, gt_pointer_operator, void *);
@@ -237,7 +237,8 @@ struct GTY(()) cpp_identifier {
/* A preprocessing token. This has been carefully packed and should
occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts. */
struct GTY(()) cpp_token {
- source_location src_loc; /* Location of first char of token. */
+ source_location src_loc; /* Location of first char of token,
+ together with range of full token. */
ENUM_BITFIELD(cpp_ttype) type : CHAR_BIT; /* token type */
unsigned short flags; /* flags - see above */
@@ -512,9 +512,11 @@ struct GTY(()) maps_info_macro {
unsigned int cache;
};
-/* Data structure to associate an arbitrary data to a source location. */
+/* Data structure to associate a source_range together with an arbitrary
+ data pointer with a source location. */
struct GTY(()) location_adhoc_data {
source_location locus;
+ source_range src_range;
void * GTY((skip)) data;
};
@@ -813,10 +815,14 @@ LINEMAPS_LAST_ALLOCATED_MACRO_MAP (const line_maps *set)
extern void location_adhoc_data_fini (struct line_maps *);
extern source_location get_combined_adhoc_loc (struct line_maps *,
- source_location, void *);
+ source_location,
+ source_range,
+ void *);
extern void *get_data_from_adhoc_loc (struct line_maps *, source_location);
extern source_location get_location_from_adhoc_loc (struct line_maps *,
source_location);
+extern source_range get_range_from_adhoc_loc (struct line_maps *,
+ source_location);
/* Get whether location LOC is an ad-hoc location. */
@@ -826,14 +832,25 @@ IS_ADHOC_LOC (source_location loc)
return (loc & MAX_SOURCE_LOCATION) != loc;
}
+inline source_range
+get_range_from_loc (struct line_maps *set,
+ source_location loc)
+{
+ if (IS_ADHOC_LOC (loc))
+ return get_range_from_adhoc_loc (set, loc);
+ else
+ return source_range::from_location (loc);
+}
+
/* Combine LOC and BLOCK, giving a combined adhoc location. */
inline source_location
COMBINE_LOCATION_DATA (struct line_maps *set,
source_location loc,
+ source_range src_range,
void *block)
{
- return get_combined_adhoc_loc (set, loc, block);
+ return get_combined_adhoc_loc (set, loc, src_range, block);
}
extern void rebuild_location_adhoc_htab (struct line_maps *);
@@ -2723,6 +2723,16 @@ _cpp_lex_direct (cpp_reader *pfile)
break;
}
+ source_range tok_range;
+ tok_range.m_start = result->src_loc;
+ tok_range.m_finish =
+ linemap_position_for_column (pfile->line_table,
+ CPP_BUF_COLUMN (buffer, buffer->cur));
+
+ result->src_loc = COMBINE_LOCATION_DATA (pfile->line_table,
+ result->src_loc,
+ tok_range, NULL);
+
return result;
}
@@ -69,7 +69,10 @@ location_adhoc_data_hash (const void *l)
{
const struct location_adhoc_data *lb =
(const struct location_adhoc_data *) l;
- return (hashval_t) lb->locus + (size_t) lb->data;
+ return ((hashval_t) lb->locus
+ + (hashval_t) lb->src_range.m_start
+ + (hashval_t) lb->src_range.m_finish
+ + (size_t) lb->data);
}
/* Compare function for location_adhoc_data hashtable. */
@@ -81,7 +84,10 @@ location_adhoc_data_eq (const void *l1, const void *l2)
(const struct location_adhoc_data *) l1;
const struct location_adhoc_data *lb2 =
(const struct location_adhoc_data *) l2;
- return lb1->locus == lb2->locus && lb1->data == lb2->data;
+ return (lb1->locus == lb2->locus
+ && lb1->src_range.m_start == lb2->src_range.m_start
+ && lb1->src_range.m_finish == lb2->src_range.m_finish
+ && lb1->data == lb2->data);
}
/* Update the hashtable when location_adhoc_data is reallocated. */
@@ -110,19 +116,20 @@ rebuild_location_adhoc_htab (struct line_maps *set)
source_location
get_combined_adhoc_loc (struct line_maps *set,
- source_location locus, void *data)
+ source_location locus,
+ source_range src_range,
+ void *data)
{
struct location_adhoc_data lb;
struct location_adhoc_data **slot;
- linemap_assert (data);
-
if (IS_ADHOC_LOC (locus))
locus
= set->location_adhoc_data_map.data[locus & MAX_SOURCE_LOCATION].locus;
if (locus == 0 && data == NULL)
return 0;
lb.locus = locus;
+ lb.src_range = src_range;
lb.data = data;
slot = (struct location_adhoc_data **)
htab_find_slot (set->location_adhoc_data_map.htab, &lb, INSERT);
@@ -177,6 +184,13 @@ get_location_from_adhoc_loc (struct line_maps *set, source_location loc)
return set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus;
}
+source_range
+get_range_from_adhoc_loc (struct line_maps *set, source_location loc)
+{
+ linemap_assert (IS_ADHOC_LOC (loc));
+ return set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].src_range;
+}
+
/* Finalize the location_adhoc_data structure. */
void
location_adhoc_data_fini (struct line_maps *set)
@@ -1478,9 +1492,9 @@ linemap_expand_location (struct line_maps *set,
memset (&xloc, 0, sizeof (xloc));
if (IS_ADHOC_LOC (loc))
{
- loc = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus;
xloc.data
= set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].data;
+ loc = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus;
}
if (loc < RESERVED_LOCATION_COUNT)