Commit 61f5369f by Jason Merrill

c++: Fix -Wreturn-local-addr location.

	* typeck.c (maybe_warn_about_returning_address_of_local): Add
	location parameter.
parent c151a342
2020-02-08 Jason Merrill <jason@redhat.com> 2020-02-08 Jason Merrill <jason@redhat.com>
* typeck.c (maybe_warn_about_returning_address_of_local): Add
location parameter.
* typeck2.c (process_init_constructor): Also clear TREE_SIDE_EFFECTS * typeck2.c (process_init_constructor): Also clear TREE_SIDE_EFFECTS
if appropriate. if appropriate.
......
...@@ -58,7 +58,7 @@ static tree pointer_diff (location_t, tree, tree, tree, tsubst_flags_t, tree *); ...@@ -58,7 +58,7 @@ static tree pointer_diff (location_t, tree, tree, tree, tsubst_flags_t, tree *);
static tree get_delta_difference (tree, tree, bool, bool, tsubst_flags_t); static tree get_delta_difference (tree, tree, bool, bool, tsubst_flags_t);
static void casts_away_constness_r (tree *, tree *, tsubst_flags_t); static void casts_away_constness_r (tree *, tree *, tsubst_flags_t);
static bool casts_away_constness (tree, tree, tsubst_flags_t); static bool casts_away_constness (tree, tree, tsubst_flags_t);
static bool maybe_warn_about_returning_address_of_local (tree); static bool maybe_warn_about_returning_address_of_local (tree, location_t = UNKNOWN_LOCATION);
static void error_args_num (location_t, tree, bool); static void error_args_num (location_t, tree, bool);
static int convert_arguments (tree, vec<tree, va_gc> **, tree, int, static int convert_arguments (tree, vec<tree, va_gc> **, tree, int,
tsubst_flags_t); tsubst_flags_t);
...@@ -9466,11 +9466,12 @@ convert_for_initialization (tree exp, tree type, tree rhs, int flags, ...@@ -9466,11 +9466,12 @@ convert_for_initialization (tree exp, tree type, tree rhs, int flags,
temporary give an appropriate warning and return true. */ temporary give an appropriate warning and return true. */
static bool static bool
maybe_warn_about_returning_address_of_local (tree retval) maybe_warn_about_returning_address_of_local (tree retval, location_t loc)
{ {
tree valtype = TREE_TYPE (DECL_RESULT (current_function_decl)); tree valtype = TREE_TYPE (DECL_RESULT (current_function_decl));
tree whats_returned = fold_for_warn (retval); tree whats_returned = fold_for_warn (retval);
location_t loc = cp_expr_loc_or_input_loc (retval); if (!loc)
loc = cp_expr_loc_or_input_loc (retval);
for (;;) for (;;)
{ {
...@@ -9504,7 +9505,7 @@ maybe_warn_about_returning_address_of_local (tree retval) ...@@ -9504,7 +9505,7 @@ maybe_warn_about_returning_address_of_local (tree retval)
|| is_std_forward_p (whats_returned))) || is_std_forward_p (whats_returned)))
{ {
tree arg = CALL_EXPR_ARG (whats_returned, 0); tree arg = CALL_EXPR_ARG (whats_returned, 0);
return maybe_warn_about_returning_address_of_local (arg); return maybe_warn_about_returning_address_of_local (arg, loc);
} }
if (TREE_CODE (whats_returned) != ADDR_EXPR) if (TREE_CODE (whats_returned) != ADDR_EXPR)
...@@ -9550,7 +9551,7 @@ maybe_warn_about_returning_address_of_local (tree retval) ...@@ -9550,7 +9551,7 @@ maybe_warn_about_returning_address_of_local (tree retval)
if (TYPE_REF_P (TREE_TYPE (base))) if (TYPE_REF_P (TREE_TYPE (base)))
{ {
if (tree init = DECL_INITIAL (base)) if (tree init = DECL_INITIAL (base))
return maybe_warn_about_returning_address_of_local (init); return maybe_warn_about_returning_address_of_local (init, loc);
else else
return false; return false;
} }
...@@ -10077,7 +10078,7 @@ check_return_expr (tree retval, bool *no_warning) ...@@ -10077,7 +10078,7 @@ check_return_expr (tree retval, bool *no_warning)
retval = build2 (COMPOUND_EXPR, TREE_TYPE (retval), retval, retval = build2 (COMPOUND_EXPR, TREE_TYPE (retval), retval,
TREE_OPERAND (retval, 0)); TREE_OPERAND (retval, 0));
else if (!processing_template_decl else if (!processing_template_decl
&& maybe_warn_about_returning_address_of_local (retval) && maybe_warn_about_returning_address_of_local (retval, loc)
&& INDIRECT_TYPE_P (valtype)) && INDIRECT_TYPE_P (valtype))
retval = build2 (COMPOUND_EXPR, TREE_TYPE (retval), retval, retval = build2 (COMPOUND_EXPR, TREE_TYPE (retval), retval,
build_zero_cst (TREE_TYPE (retval))); build_zero_cst (TREE_TYPE (retval)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment