gcc/c/ChangeLog: * c-decl.cc (start_function): Set the result decl location. gcc/cp/ChangeLog: * decl.cc (start_function): Set the result decl location. (finish_function): XXX locus sample gcc/ChangeLog: * tree-pretty-print.cc (dump_location): Use pp_colon and pp_right_bracket where applicable. diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index c701f07befe..a441d187c1b 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -9487,6 +9487,7 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, tree decl1, old_decl; tree restype, resdecl; location_t loc; + location_t result_loc; current_function_returns_value = 0; /* Assume, until we see it does. */ current_function_returns_null = 0; @@ -9712,8 +9713,11 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, push_scope (); declare_parm_level (); + /* Set the result decl source location to the location of the typespec. */ + result_loc = (declspecs->locations[cdw_typespec] == UNKNOWN_LOCATION + ? loc : declspecs->locations[cdw_typespec]); restype = TREE_TYPE (TREE_TYPE (current_function_decl)); - resdecl = build_decl (loc, RESULT_DECL, NULL_TREE, restype); + resdecl = build_decl (result_loc, RESULT_DECL, NULL_TREE, restype); DECL_ARTIFICIAL (resdecl) = 1; DECL_IGNORED_P (resdecl) = 1; DECL_RESULT (current_function_decl) = resdecl; diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index c136dbbba1a..38874bf1558 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -17361,6 +17361,8 @@ start_function (cp_decl_specifier_seq *declspecs, tree attrs) { tree decl1; + tree result; + bool ret; decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs); invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1); @@ -17373,7 +17375,18 @@ start_function (cp_decl_specifier_seq *declspecs, gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)), integer_type_node)); - return start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT); + ret = start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT); + + /* decl1 might be ggc_freed here. */ + //decl1 = current_function_decl; + + /* Set the result decl source location to the location of the typespec. */ + if (TREE_CODE (decl1) == FUNCTION_DECL + && declspecs->locations[ds_type_spec] != UNKNOWN_LOCATION + && (result = DECL_RESULT (decl1)) != NULL_TREE + && DECL_SOURCE_LOCATION (result) == input_location) + DECL_SOURCE_LOCATION (result) = declspecs->locations[ds_type_spec]; + return ret; } /* Returns true iff an EH_SPEC_BLOCK should be created in the body of @@ -17942,6 +17955,13 @@ finish_function (bool inline_p) "non-void")) suppress_warning (fndecl, OPT_Wreturn_type); } + if (getenv("XXX") != NULL) + { + location_t result_loc = DECL_SOURCE_LOCATION (DECL_RESULT (fndecl)); + gcc_rich_location richloc (result_loc); + richloc.add_fixit_replace (result_loc, "the return type"); + warning_at (&richloc, 0, "result dec%c locus sample", 'l'); + } /* Lambda closure members are implicitly constexpr if possible. */ if (cxx_dialect >= cxx17 diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc index 99af977979d..591883c4063 100644 --- a/gcc/tree-pretty-print.cc +++ b/gcc/tree-pretty-print.cc @@ -1412,12 +1412,12 @@ dump_location (pretty_printer *pp, location_t loc) if (xloc.file) { pp_string (pp, xloc.file); - pp_string (pp, ":"); + pp_colon (pp); } pp_decimal_int (pp, xloc.line); pp_colon (pp); pp_decimal_int (pp, xloc.column); - pp_string (pp, "] "); + pp_right_bracket (pp); }