aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2019-09-27 14:19:55 -0400
committerJason Merrill <jason@gcc.gnu.org>2019-09-27 14:19:55 -0400
commitc872f1506d46ceba10776d0ebc86b4126273a419 (patch)
tree2a0a2e3ea4616da4030026f5092c505936d412e3
parent975d043ff6b6f8a9e9ff0be799701fc1d842bb83 (diff)
downloadgcc-c872f1506d46ceba10776d0ebc86b4126273a419.zip
gcc-c872f1506d46ceba10776d0ebc86b4126273a419.tar.gz
gcc-c872f1506d46ceba10776d0ebc86b4126273a419.tar.bz2
cp-tree.h (class iloc_sentinel): New.
* cp-tree.h (class iloc_sentinel): New. We didn't already have a sentinel for input_location, and while temp_override would work, it would also happily set input_location to 0, which breaks things that try to look up the associated filename. * decl.c (grokdeclarator, finish_enum_value_list): Use it. * mangle.c (mangle_decl_string): Use it. * pt.c (perform_typedefs_access_check): Use it. From-SVN: r276191
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/cp-tree.h18
-rw-r--r--gcc/cp/decl.c15
-rw-r--r--gcc/cp/mangle.c4
-rw-r--r--gcc/cp/pt.c5
5 files changed, 32 insertions, 17 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3a3ef9e..8e92d91 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2019-09-27 Jason Merrill <jason@redhat.com>
+
+ * cp-tree.h (class iloc_sentinel): New.
+ * decl.c (grokdeclarator, finish_enum_value_list): Use it.
+ * mangle.c (mangle_decl_string): Use it.
+ * pt.c (perform_typedefs_access_check): Use it.
+
2019-09-27 Richard Sandiford <richard.sandiford@arm.com>
* cp-tree.h (build_cxx_call): Take the original function decl
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 8fc3fc1..be1a44e 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1762,6 +1762,24 @@ public:
~warning_sentinel() { flag = val; }
};
+/* RAII sentinel to temporarily override input_location. This will not set
+ input_location to UNKNOWN_LOCATION or BUILTINS_LOCATION. */
+
+class iloc_sentinel
+{
+ location_t saved_loc;
+public:
+ iloc_sentinel (location_t loc): saved_loc (input_location)
+ {
+ if (loc >= RESERVED_LOCATION_COUNT)
+ input_location = loc;
+ }
+ ~iloc_sentinel ()
+ {
+ input_location = saved_loc;
+ }
+};
+
/* RAII sentinel that saves the value of a variable, optionally
overrides it right away, and restores its value when the sentinel
id destructed. */
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index b753796..67c4521 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10523,7 +10523,6 @@ grokdeclarator (const cp_declarator *declarator,
bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
bool late_return_type_p = false;
bool array_parameter_p = false;
- location_t saved_loc = input_location;
tree reqs = NULL_TREE;
signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
@@ -11514,9 +11513,10 @@ grokdeclarator (const cp_declarator *declarator,
/* Declaring a function type. */
- input_location = declspecs->locations[ds_type_spec];
- abstract_virtuals_error (ACU_RETURN, type);
- input_location = saved_loc;
+ {
+ iloc_sentinel ils (declspecs->locations[ds_type_spec]);
+ abstract_virtuals_error (ACU_RETURN, type);
+ }
/* Pick up type qualifiers which should be applied to `this'. */
memfn_quals = declarator->u.function.qualifiers;
@@ -15061,11 +15061,8 @@ finish_enum_value_list (tree enumtype)
type of the enumeration. */
for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
{
- location_t saved_location;
-
decl = TREE_VALUE (values);
- saved_location = input_location;
- input_location = DECL_SOURCE_LOCATION (decl);
+ iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
if (fixed_underlying_type_p)
/* If the enumeration type has a fixed underlying type, we
already checked all of the enumerator values. */
@@ -15074,8 +15071,6 @@ finish_enum_value_list (tree enumtype)
value = perform_implicit_conversion (underlying_type,
DECL_INITIAL (decl),
tf_warning_or_error);
- input_location = saved_location;
-
/* Do not clobber shared ints. */
if (value != error_mark_node)
{
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 4d6f580..a9333b8 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -3791,7 +3791,6 @@ static tree
mangle_decl_string (const tree decl)
{
tree result;
- location_t saved_loc = input_location;
tree saved_fn = NULL_TREE;
bool template_p = false;
@@ -3809,7 +3808,7 @@ mangle_decl_string (const tree decl)
current_function_decl = NULL_TREE;
}
}
- input_location = DECL_SOURCE_LOCATION (decl);
+ iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
start_mangling (decl);
@@ -3828,7 +3827,6 @@ mangle_decl_string (const tree decl)
pop_tinst_level ();
current_function_decl = saved_fn;
}
- input_location = saved_loc;
return result;
}
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index e5d6498..5a2dfbb 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10941,7 +10941,6 @@ apply_late_template_attributes (tree *decl_p, tree attributes, int attr_flags,
static void
perform_typedefs_access_check (tree tmpl, tree targs)
{
- location_t saved_location;
unsigned i;
qualified_typedef_usage_t *iter;
@@ -10950,7 +10949,6 @@ perform_typedefs_access_check (tree tmpl, tree targs)
&& TREE_CODE (tmpl) != FUNCTION_DECL))
return;
- saved_location = input_location;
FOR_EACH_VEC_SAFE_ELT (get_types_needing_access_check (tmpl), i, iter)
{
tree type_decl = iter->typedef_decl;
@@ -10966,12 +10964,11 @@ perform_typedefs_access_check (tree tmpl, tree targs)
/* Make access check error messages point to the location
of the use of the typedef. */
- input_location = iter->locus;
+ iloc_sentinel ils (iter->locus);
perform_or_defer_access_check (TYPE_BINFO (type_scope),
type_decl, type_decl,
tf_warning_or_error);
}
- input_location = saved_location;
}
static tree