diff mbox series

[1/5] c: Set the locus of the function result decl

Message ID 20221112234543.95441-2-aldot@gcc.gnu.org
State New
Headers show
Series function result decl location; type demotion | expand

Commit Message

Bernhard Reutner-Fischer Nov. 12, 2022, 11:45 p.m. UTC
Bootstrapped and regtested on x86_86-unknown-linux with no regressions.
Ok for trunk?

Cc: Joseph Myers <joseph@codesourcery.com>
---
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 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Joseph Myers Nov. 14, 2022, 9:25 p.m. UTC | #1
On Sun, 13 Nov 2022, Bernhard Reutner-Fischer via Gcc-patches wrote:

> Bootstrapped and regtested on x86_86-unknown-linux with no regressions.
> Ok for trunk?
> 
> Cc: Joseph Myers <joseph@codesourcery.com>
> ---
> gcc/c/ChangeLog:
> 
> 	* c-decl.cc (start_function): Set the result decl source
> 	location to the location of the typespec.

OK.
diff mbox series

Patch

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index a99b7456055..5250cb96c41 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -9980,6 +9980,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;
@@ -10206,8 +10207,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;