aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2019-12-30 13:23:40 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2019-12-30 13:23:40 +0000
commit04e4997a567142f56dc83eba67b9590c0431d7da (patch)
tree4e9336e6cb50d2d78040a5f54b7d2abb69f7a81a /gcc/cp
parent9332e5acbf0d79cda8321365a688fc22d7b5e261 (diff)
downloadgcc-04e4997a567142f56dc83eba67b9590c0431d7da.zip
gcc-04e4997a567142f56dc83eba67b9590c0431d7da.tar.gz
gcc-04e4997a567142f56dc83eba67b9590c0431d7da.tar.bz2
decl2.c (delete_sanity): Add location_t parameter and use it throughout.
/gcc/cp 2019-12-30 Paolo Carlini <paolo.carlini@oracle.com> * decl2.c (delete_sanity): Add location_t parameter and use it throughout. * init.c (build_vec_delete_1): Likewise. (build_delete): Likewise. (build_vec_delete): Likewise. (perform_target_ctor): Adjust call. (perform_member_init): Likewise. (build_vec_init): Likewise. * decl.c (cxx_maybe_build_cleanup): Likewise. * pt.c (tsubst_copy_and_build): Likewise. * parser.c (cp_parser_delete_expression): Likewise, pass the combined_loc. * cp-tree.h: Update declarations. /libcc1 2019-12-30 Paolo Carlini <paolo.carlini@oracle.com> * libcp1plugin.cc (plugin_build_unary_expr): Update delete_sanity call. /gcc/testsuite 2019-12-30 Paolo Carlini <paolo.carlini@oracle.com> * g++.dg/init/delete1.C: Check locations too. * g++.dg/ipa/pr85607.C: Likewise. * g++.dg/warn/Wdelete-incomplete-1.C: Likewise. * g++.dg/warn/delete-non-virtual-dtor.C: Likewise. * g++.dg/warn/incomplete1.C: Likewise. From-SVN: r279768
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog16
-rw-r--r--gcc/cp/cp-tree.h7
-rw-r--r--gcc/cp/decl.c2
-rw-r--r--gcc/cp/decl2.c22
-rw-r--r--gcc/cp/init.c101
-rw-r--r--gcc/cp/parser.c3
-rw-r--r--gcc/cp/pt.c2
7 files changed, 90 insertions, 63 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 37d776c..9c30253 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,19 @@
+2019-12-30 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * decl2.c (delete_sanity): Add location_t parameter and use
+ it throughout.
+ * init.c (build_vec_delete_1): Likewise.
+ (build_delete): Likewise.
+ (build_vec_delete): Likewise.
+ (perform_target_ctor): Adjust call.
+ (perform_member_init): Likewise.
+ (build_vec_init): Likewise.
+ * decl.c (cxx_maybe_build_cleanup): Likewise.
+ * pt.c (tsubst_copy_and_build): Likewise.
+ * parser.c (cp_parser_delete_expression): Likewise, pass the
+ combined_loc.
+ * cp-tree.h: Update declarations.
+
2019-12-29 Marek Polacek <polacek@redhat.com>
PR c++/88337 - Implement P1327R1: Allow dynamic_cast in constexpr.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 50cd283..4b92829 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6583,7 +6583,8 @@ extern bool vague_linkage_p (tree);
extern void grokclassfn (tree, tree,
enum overload_flags);
extern tree grok_array_decl (location_t, tree, tree, bool);
-extern tree delete_sanity (tree, tree, bool, int, tsubst_flags_t);
+extern tree delete_sanity (location_t, tree, tree, bool,
+ int, tsubst_flags_t);
extern tree check_classfn (tree, tree, tree);
extern void check_member_template (tree);
extern tree grokfield (const cp_declarator *, cp_decl_specifier_seq *,
@@ -6725,11 +6726,11 @@ extern tree build_new (vec<tree, va_gc> **, tree, tree,
extern tree get_temp_regvar (tree, tree);
extern tree build_vec_init (tree, tree, tree, bool, int,
tsubst_flags_t);
-extern tree build_delete (tree, tree,
+extern tree build_delete (location_t, tree, tree,
special_function_kind,
int, int, tsubst_flags_t);
extern void push_base_cleanups (void);
-extern tree build_vec_delete (tree, tree,
+extern tree build_vec_delete (location_t, tree, tree,
special_function_kind, int,
tsubst_flags_t);
extern tree create_temporary_var (tree);
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c15cbfa..2760dba 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -17310,7 +17310,7 @@ cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
else
addr = build_address (decl);
- call = build_delete (TREE_TYPE (addr), addr,
+ call = build_delete (input_location, TREE_TYPE (addr), addr,
sfk_complete_destructor, flags, 0, complain);
if (call == error_mark_node)
cleanup = error_mark_node;
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 6ff8113..5847e6b 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -475,8 +475,8 @@ grok_array_decl (location_t loc, tree array_expr, tree index_exp,
Implements ARM $5.3.4. This is called from the parser. */
tree
-delete_sanity (tree exp, tree size, bool doing_vec, int use_global_delete,
- tsubst_flags_t complain)
+delete_sanity (location_t loc, tree exp, tree size, bool doing_vec,
+ int use_global_delete, tsubst_flags_t complain)
{
tree t, type;
@@ -489,21 +489,23 @@ delete_sanity (tree exp, tree size, bool doing_vec, int use_global_delete,
DELETE_EXPR_USE_GLOBAL (t) = use_global_delete;
DELETE_EXPR_USE_VEC (t) = doing_vec;
TREE_SIDE_EFFECTS (t) = 1;
+ SET_EXPR_LOCATION (t, loc);
return t;
}
+ location_t exp_loc = cp_expr_loc_or_loc (exp, loc);
+
/* An array can't have been allocated by new, so complain. */
if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
&& (complain & tf_warning))
- warning_at (cp_expr_loc_or_input_loc (exp), 0,
- "deleting array %q#E", exp);
+ warning_at (exp_loc, 0, "deleting array %q#E", exp);
t = build_expr_type_conversion (WANT_POINTER, exp, true);
if (t == NULL_TREE || t == error_mark_node)
{
if (complain & tf_error)
- error_at (cp_expr_loc_or_input_loc (exp),
+ error_at (exp_loc,
"type %q#T argument given to %<delete%>, expected pointer",
TREE_TYPE (exp));
return error_mark_node;
@@ -517,7 +519,7 @@ delete_sanity (tree exp, tree size, bool doing_vec, int use_global_delete,
if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
{
if (complain & tf_error)
- error_at (cp_expr_loc_or_input_loc (exp),
+ error_at (exp_loc,
"cannot delete a function. Only pointer-to-objects are "
"valid arguments to %<delete%>");
return error_mark_node;
@@ -527,21 +529,21 @@ delete_sanity (tree exp, tree size, bool doing_vec, int use_global_delete,
if (VOID_TYPE_P (TREE_TYPE (type)))
{
if (complain & tf_warning)
- warning_at (cp_expr_loc_or_input_loc (exp), OPT_Wdelete_incomplete,
+ warning_at (exp_loc, OPT_Wdelete_incomplete,
"deleting %qT is undefined", type);
doing_vec = 0;
}
/* Deleting a pointer with the value zero is valid and has no effect. */
if (integer_zerop (t))
- return build1 (NOP_EXPR, void_type_node, t);
+ return build1_loc (loc, NOP_EXPR, void_type_node, t);
if (doing_vec)
- return build_vec_delete (t, /*maxindex=*/NULL_TREE,
+ return build_vec_delete (loc, t, /*maxindex=*/NULL_TREE,
sfk_deleting_destructor,
use_global_delete, complain);
else
- return build_delete (type, t, sfk_deleting_destructor,
+ return build_delete (loc, type, t, sfk_deleting_destructor,
LOOKUP_NORMAL, use_global_delete,
complain);
}
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 6f4c918..5b48a0e 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -535,7 +535,8 @@ perform_target_ctor (tree init)
tf_warning_or_error));
if (type_build_dtor_call (type))
{
- tree expr = build_delete (type, decl, sfk_complete_destructor,
+ tree expr = build_delete (input_location,
+ type, decl, sfk_complete_destructor,
LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR,
@@ -980,7 +981,8 @@ perform_member_init (tree member, tree init)
/*access_path=*/NULL_TREE,
/*preserve_reference=*/false,
tf_warning_or_error);
- expr = build_delete (type, expr, sfk_complete_destructor,
+ expr = build_delete (input_location,
+ type, expr, sfk_complete_destructor,
LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0,
tf_warning_or_error);
@@ -3924,7 +3926,7 @@ build_new (vec<tree, va_gc> **placement, tree type, tree nelts,
}
static tree
-build_vec_delete_1 (tree base, tree maxindex, tree type,
+build_vec_delete_1 (location_t loc, tree base, tree maxindex, tree type,
special_function_kind auto_delete_vec,
int use_global_delete, tsubst_flags_t complain)
{
@@ -3958,7 +3960,7 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
if (base == error_mark_node || maxindex == error_mark_node)
return error_mark_node;
- if (!verify_type_context (input_location, TCTX_DEALLOCATION, type,
+ if (!verify_type_context (loc, TCTX_DEALLOCATION, type,
!(complain & tf_error)))
return error_mark_node;
@@ -3967,14 +3969,14 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
if (complain & tf_warning)
{
auto_diagnostic_group d;
- if (warning (OPT_Wdelete_incomplete,
- "possible problem detected in invocation of "
- "operator %<delete []%>"))
+ if (warning_at (loc, OPT_Wdelete_incomplete,
+ "possible problem detected in invocation of "
+ "operator %<delete []%>"))
{
cxx_incomplete_type_diagnostic (base, type, DK_WARNING);
- inform (input_location, "neither the destructor nor the "
- "class-specific operator %<delete []%> will be called, "
- "even if they are declared when the class is defined");
+ inform (loc, "neither the destructor nor the "
+ "class-specific operator %<delete []%> will be called, "
+ "even if they are declared when the class is defined");
}
}
/* This size won't actually be used. */
@@ -3991,7 +3993,7 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
/* Make sure the destructor is callable. */
if (type_build_dtor_call (type))
{
- tmp = build_delete (ptype, base, sfk_complete_destructor,
+ tmp = build_delete (loc, ptype, base, sfk_complete_destructor,
LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 1,
complain);
if (tmp == error_mark_node)
@@ -4006,30 +4008,30 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
tbase = create_temporary_var (ptype);
DECL_INITIAL (tbase)
- = fold_build_pointer_plus_loc (input_location, fold_convert (ptype, base),
+ = fold_build_pointer_plus_loc (loc, fold_convert (ptype, base),
virtual_size);
- tbase_init = build_stmt (input_location, DECL_EXPR, tbase);
+ tbase_init = build_stmt (loc, DECL_EXPR, tbase);
controller = build3 (BIND_EXPR, void_type_node, tbase, NULL_TREE, NULL_TREE);
TREE_SIDE_EFFECTS (controller) = 1;
body = build1 (EXIT_EXPR, void_type_node,
build2 (EQ_EXPR, boolean_type_node, tbase,
fold_convert (ptype, base)));
- tmp = fold_build1_loc (input_location, NEGATE_EXPR, sizetype, size_exp);
+ tmp = fold_build1_loc (loc, NEGATE_EXPR, sizetype, size_exp);
tmp = fold_build_pointer_plus (tbase, tmp);
- tmp = cp_build_modify_expr (input_location, tbase, NOP_EXPR, tmp, complain);
+ tmp = cp_build_modify_expr (loc, tbase, NOP_EXPR, tmp, complain);
if (tmp == error_mark_node)
return error_mark_node;
- body = build_compound_expr (input_location, body, tmp);
- tmp = build_delete (ptype, tbase, sfk_complete_destructor,
+ body = build_compound_expr (loc, body, tmp);
+ tmp = build_delete (loc, ptype, tbase, sfk_complete_destructor,
LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 1,
complain);
if (tmp == error_mark_node)
return error_mark_node;
- body = build_compound_expr (input_location, body, tmp);
+ body = build_compound_expr (loc, body, tmp);
loop = build1 (LOOP_EXPR, void_type_node, body);
- loop = build_compound_expr (input_location, tbase_init, loop);
+ loop = build_compound_expr (loc, tbase_init, loop);
no_destructor:
/* Delete the storage if appropriate. */
@@ -4049,7 +4051,7 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
tree cookie_size;
cookie_size = targetm.cxx.get_cookie_size (type);
- base_tbd = cp_build_binary_op (input_location,
+ base_tbd = cp_build_binary_op (loc,
MINUS_EXPR,
cp_convert (string_type_node,
base, complain),
@@ -4088,12 +4090,12 @@ build_vec_delete_1 (tree base, tree maxindex, tree type,
body = integer_zero_node;
/* Outermost wrapper: If pointer is null, punt. */
- tree cond = build2_loc (input_location, NE_EXPR, boolean_type_node, base,
+ tree cond = build2_loc (loc, NE_EXPR, boolean_type_node, base,
fold_convert (TREE_TYPE (base), nullptr_node));
/* This is a compiler generated comparison, don't emit
e.g. -Wnonnull-compare warning for it. */
TREE_NO_WARNING (cond) = 1;
- body = build3_loc (input_location, COND_EXPR, void_type_node,
+ body = build3_loc (loc, COND_EXPR, void_type_node,
cond, body, integer_zero_node);
COND_EXPR_IS_VEC_DELETE (body) = true;
body = build1 (NOP_EXPR, void_type_node, body);
@@ -4714,7 +4716,7 @@ build_vec_init (tree base, tree maxindex, tree init,
complain);
finish_cleanup_try_block (try_block);
- e = build_vec_delete_1 (rval, m,
+ e = build_vec_delete_1 (input_location, rval, m,
inner_elt_type, sfk_complete_destructor,
/*use_global_delete=*/0, complain);
if (e == error_mark_node)
@@ -4801,7 +4803,8 @@ build_dtor_call (tree exp, special_function_kind dtor_kind, int flags,
flags. See cp-tree.h for more info. */
tree
-build_delete (tree otype, tree addr, special_function_kind auto_delete,
+build_delete (location_t loc, tree otype, tree addr,
+ special_function_kind auto_delete,
int flags, int use_global_delete, tsubst_flags_t complain)
{
tree expr;
@@ -4824,10 +4827,10 @@ build_delete (tree otype, tree addr, special_function_kind auto_delete,
if (TYPE_DOMAIN (type) == NULL_TREE)
{
if (complain & tf_error)
- error ("unknown array size in delete");
+ error_at (loc, "unknown array size in delete");
return error_mark_node;
}
- return build_vec_delete (addr, array_type_nelts (type),
+ return build_vec_delete (loc, addr, array_type_nelts (type),
auto_delete, use_global_delete, complain);
}
@@ -4848,7 +4851,7 @@ build_delete (tree otype, tree addr, special_function_kind auto_delete,
{
complete_type (type);
if (deleting
- && !verify_type_context (input_location, TCTX_DEALLOCATION, type,
+ && !verify_type_context (loc, TCTX_DEALLOCATION, type,
!(complain & tf_error)))
return error_mark_node;
@@ -4857,12 +4860,12 @@ build_delete (tree otype, tree addr, special_function_kind auto_delete,
if (complain & tf_warning)
{
auto_diagnostic_group d;
- if (warning (OPT_Wdelete_incomplete,
- "possible problem detected in invocation of "
- "%<operator delete%>"))
+ if (warning_at (loc, OPT_Wdelete_incomplete,
+ "possible problem detected in invocation of "
+ "%<operator delete%>"))
{
cxx_incomplete_type_diagnostic (addr, type, DK_WARNING);
- inform (input_location,
+ inform (loc,
"neither the destructor nor the class-specific "
"%<operator delete%> will be called, even if "
"they are declared when the class is defined");
@@ -4877,15 +4880,15 @@ build_delete (tree otype, tree addr, special_function_kind auto_delete,
if (!dtor || !DECL_VINDEX (dtor))
{
if (CLASSTYPE_PURE_VIRTUALS (type))
- warning (OPT_Wdelete_non_virtual_dtor,
- "deleting object of abstract class type %qT"
- " which has non-virtual destructor"
- " will cause undefined behavior", type);
+ warning_at (loc, OPT_Wdelete_non_virtual_dtor,
+ "deleting object of abstract class type %qT"
+ " which has non-virtual destructor"
+ " will cause undefined behavior", type);
else
- warning (OPT_Wdelete_non_virtual_dtor,
- "deleting object of polymorphic class type %qT"
- " which has non-virtual destructor"
- " might cause undefined behavior", type);
+ warning_at (loc, OPT_Wdelete_non_virtual_dtor,
+ "deleting object of polymorphic class type %qT"
+ " which has non-virtual destructor"
+ " might cause undefined behavior", type);
}
}
}
@@ -4984,7 +4987,10 @@ build_delete (tree otype, tree addr, special_function_kind auto_delete,
return error_mark_node;
if (!deleting)
- return expr;
+ {
+ protected_set_expr_location (expr, loc);
+ return expr;
+ }
if (do_delete)
{
@@ -5010,7 +5016,7 @@ build_delete (tree otype, tree addr, special_function_kind auto_delete,
/* Handle deleting a null pointer. */
warning_sentinel s (warn_address);
- tree ifexp = cp_build_binary_op (input_location, NE_EXPR, addr,
+ tree ifexp = cp_build_binary_op (loc, NE_EXPR, addr,
nullptr_node, complain);
ifexp = cp_fully_fold (ifexp);
@@ -5024,6 +5030,7 @@ build_delete (tree otype, tree addr, special_function_kind auto_delete,
if (!integer_nonzerop (ifexp))
expr = build3 (COND_EXPR, void_type_node, ifexp, expr, void_node);
+ protected_set_expr_location (expr, loc);
return expr;
}
@@ -5112,7 +5119,7 @@ push_base_cleanups (void)
/*access_path=*/NULL_TREE,
/*preserve_reference=*/false,
tf_warning_or_error));
- expr = build_delete (this_type, this_member,
+ expr = build_delete (input_location, this_type, this_member,
sfk_complete_destructor,
LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL,
0, tf_warning_or_error);
@@ -5139,7 +5146,7 @@ push_base_cleanups (void)
be worth bothering.) */
tree
-build_vec_delete (tree base, tree maxindex,
+build_vec_delete (location_t loc, tree base, tree maxindex,
special_function_kind auto_delete_vec,
int use_global_delete, tsubst_flags_t complain)
{
@@ -5162,7 +5169,7 @@ build_vec_delete (tree base, tree maxindex,
base = TARGET_EXPR_SLOT (base_init);
}
type = strip_array_types (TREE_TYPE (type));
- cookie_addr = fold_build1_loc (input_location, NEGATE_EXPR,
+ cookie_addr = fold_build1_loc (loc, NEGATE_EXPR,
sizetype, TYPE_SIZE_UNIT (sizetype));
cookie_addr = fold_build_pointer_plus (fold_convert (size_ptr_type, base),
cookie_addr);
@@ -5186,15 +5193,17 @@ build_vec_delete (tree base, tree maxindex,
else
{
if (base != error_mark_node && !(complain & tf_error))
- error ("type to vector delete is neither pointer or array type");
+ error_at (loc,
+ "type to vector delete is neither pointer or array type");
return error_mark_node;
}
- rval = build_vec_delete_1 (base, maxindex, type, auto_delete_vec,
+ rval = build_vec_delete_1 (loc, base, maxindex, type, auto_delete_vec,
use_global_delete, complain);
if (base_init && rval != error_mark_node)
rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), base_init, rval);
+ protected_set_expr_location (rval, loc);
return rval;
}
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index c66ef34..2e39107 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -9046,9 +9046,8 @@ cp_parser_delete_expression (cp_parser* parser)
the end at the end of the final token we consumed. */
location_t combined_loc = make_location (start_loc, start_loc,
parser->lexer);
- expression = delete_sanity (expression, NULL_TREE, array_p,
+ expression = delete_sanity (combined_loc, expression, NULL_TREE, array_p,
global_scope_p, tf_warning_or_error);
- protected_set_expr_location (expression, combined_loc);
return expression;
}
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index dc01774..7f8ce1d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -19336,7 +19336,7 @@ tsubst_copy_and_build (tree t,
{
tree op0 = RECUR (TREE_OPERAND (t, 0));
tree op1 = RECUR (TREE_OPERAND (t, 1));
- RETURN (delete_sanity (op0, op1,
+ RETURN (delete_sanity (input_location, op0, op1,
DELETE_EXPR_USE_VEC (t),
DELETE_EXPR_USE_GLOBAL (t),
complain));