]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Set the locus of the function result decl
authorBernhard Reutner-Fischer <aldot@gcc.gnu.org>
Sat, 6 Nov 2021 05:48:00 +0000 (06:48 +0100)
committerBernhard Reutner-Fischer <aldot@gcc.gnu.org>
Thu, 17 Nov 2022 19:40:47 +0000 (20:40 +0100)
gcc/c/ChangeLog:

* c-decl.cc (start_function): Set the result decl source
location to the location of the typespec.

gcc/c/c-decl.cc

index 36de77814baa4786afe1f7a6c500b4589b4ca74d..098e475f65d593a4f56d687f272d6c7ea72146d4 100644 (file)
@@ -10059,6 +10059,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;
@@ -10285,8 +10286,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;