public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c: Don't emit DEBUG_BEGIN_STMTs for K&R function argument declarations [PR105972]
@ 2023-01-11 18:04 Jakub Jelinek
  2023-01-11 20:26 ` Joseph Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2023-01-11 18:04 UTC (permalink / raw)
  To: Joseph S. Myers, Marek Polacek; +Cc: gcc-patches

Hi!

K&R function parameter declarations are handled by calling
recursively c_parser_declaration_or_fndef in a loop, where each such
call will add_debug_begin_stmt at the start.
Now, if the K&R function definition is not a nested function,
building_stmt_list_p () is false and so we don't emit the DEBUG_BEGIN_STMTs
anywhere, but if it is a nested function, we emit it in the containing
function at the point of the nested function definition.
As the following testcase shows, it can cause ICEs if the containing
function has var-tracking disabled but nested function has them enabled,
as the DEBUG_BEGIN_STMTs are added to the containing function which
shouldn't have them but MAY_HAVE_DEBUG_MARKER_STMTS is checked already
for the nested function, or just wrong experience in the debugger.

The following patch ensures we don't emit any such DEBUG_BEGIN_STMTs for the
K&R function parameter declarations even in nested functions.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-01-11  Jakub Jelinek  <jakub@redhat.com>

	PR c/105972
	* c-parser.cc (c_parser_declaration_or_fndef): Disable debug non-bind
	markers for K&R function parameter declarations of nested functions.

	* gcc.dg/pr105972.c: New test.

--- gcc/c/c-parser.cc.jj	2023-01-09 13:30:46.873347238 +0100
+++ gcc/c/c-parser.cc	2023-01-11 14:55:39.161287717 +0100
@@ -2804,10 +2804,13 @@ c_parser_declaration_or_fndef (c_parser
 	 declarator with a nonempty identifier list in a definition;
 	 and postfix attributes have never been accepted here in
 	 function definitions either.  */
+      int save_debug_nonbind_markers_p = debug_nonbind_markers_p;
+      debug_nonbind_markers_p = 0;
       while (c_parser_next_token_is_not (parser, CPP_EOF)
 	     && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
 	c_parser_declaration_or_fndef (parser, false, false, false,
 				       true, false);
+      debug_nonbind_markers_p = save_debug_nonbind_markers_p;
       store_parm_decls ();
       if (omp_declare_simd_clauses)
 	c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
--- gcc/testsuite/gcc.dg/pr105972.c.jj	2023-01-11 15:06:55.377366557 +0100
+++ gcc/testsuite/gcc.dg/pr105972.c	2023-01-11 15:04:47.817238069 +0100
@@ -0,0 +1,15 @@
+/* PR c/105972 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -g" } */
+
+__attribute__((optimize (0))) int
+foo (void)
+{
+  int
+  bar (x)
+    int x;
+  {
+    return x;
+  }
+  return bar (0);
+}

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c: Don't emit DEBUG_BEGIN_STMTs for K&R function argument declarations [PR105972]
  2023-01-11 18:04 [PATCH] c: Don't emit DEBUG_BEGIN_STMTs for K&R function argument declarations [PR105972] Jakub Jelinek
@ 2023-01-11 20:26 ` Joseph Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Myers @ 2023-01-11 20:26 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Marek Polacek, gcc-patches

On Wed, 11 Jan 2023, Jakub Jelinek via Gcc-patches wrote:

> The following patch ensures we don't emit any such DEBUG_BEGIN_STMTs for the
> K&R function parameter declarations even in nested functions.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2023-01-11  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c/105972
> 	* c-parser.cc (c_parser_declaration_or_fndef): Disable debug non-bind
> 	markers for K&R function parameter declarations of nested functions.
> 
> 	* gcc.dg/pr105972.c: New test.

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-11 20:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-11 18:04 [PATCH] c: Don't emit DEBUG_BEGIN_STMTs for K&R function argument declarations [PR105972] Jakub Jelinek
2023-01-11 20:26 ` Joseph Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).