From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id ED8763858C00; Wed, 11 Jan 2023 21:20:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED8763858C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673472015; bh=3ZcrmORw2L7QVS5CznGTxKENX46quX5AjDlAjkpQ0WA=; h=From:To:Subject:Date:From; b=xJV/9ub/ivssWfBqJaarBqUR6vsIFZ+T71FzGZnwWo2mbYSjyvOS0JUnIET2zGDME ifnd31qc9VfTjsG46AR0M7ss/AmdlbkayDMtBramfxGGdkjwyxdNG+yTBxJRCBypPy Fzi1CpThUYtDo1iTu+ln9V2Bua1h1lE8vQDQOTZw= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5112] c: Don't emit DEBUG_BEGIN_STMTs for K&R function argument declarations [PR105972] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 98837d6e79dd27c15f5218f3f1ddf838cda4796c X-Git-Newrev: 23b4ce18379cd336d99d7c71701be28118905b57 Message-Id: <20230111212015.ED8763858C00@sourceware.org> Date: Wed, 11 Jan 2023 21:20:15 +0000 (GMT) List-Id: https://gcc.gnu.org/g:23b4ce18379cd336d99d7c71701be28118905b57 commit r13-5112-g23b4ce18379cd336d99d7c71701be28118905b57 Author: Jakub Jelinek Date: Wed Jan 11 22:18:42 2023 +0100 c: Don't emit DEBUG_BEGIN_STMTs for K&R function argument declarations [PR105972] 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. 2023-01-11 Jakub Jelinek 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. Diff: --- gcc/c/c-parser.cc | 3 +++ gcc/testsuite/gcc.dg/pr105972.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 3a5998007a9..3e2109bfd4f 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -2804,10 +2804,13 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, 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, diff --git a/gcc/testsuite/gcc.dg/pr105972.c b/gcc/testsuite/gcc.dg/pr105972.c new file mode 100644 index 00000000000..73f3385f7eb --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105972.c @@ -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); +}