From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 693C73858C62 for ; Wed, 11 Jan 2023 18:05:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 693C73858C62 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673460300; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=OeYzxKlWzOVMmrfYvtFjI2gOX5qnhPBvOLdLsi8fl4s=; b=apoCjIHHacYM4Rx4PBgaHONa15t4qpUbe/UWOo9LxqGfU22VqV6zSKZYidigHcqQw6XvHw 8MMGWrgB+xR8J1qj0mqSEnPW+aT9aUVBV74b8LjdD5PacWqg+p9hj6wUjZWEp20UVpOrDU EiiWUFZ2/L1lmWpfHlH02eAAIBqgWhM= Received: from mimecast-mx02.redhat.com (66.187.233.88 [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-639-Nt184xOOMLiQCuLyf0DCyg-1; Wed, 11 Jan 2023 13:04:56 -0500 X-MC-Unique: Nt184xOOMLiQCuLyf0DCyg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C597185CBE5; Wed, 11 Jan 2023 18:04:50 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1495F4078903; Wed, 11 Jan 2023 18:04:31 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 30BI4TSr3410004 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 11 Jan 2023 19:04:29 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30BI4RaX3410002; Wed, 11 Jan 2023 19:04:27 +0100 Date: Wed, 11 Jan 2023 19:04:27 +0100 From: Jakub Jelinek To: "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c: Don't emit DEBUG_BEGIN_STMTs for K&R function argument declarations [PR105972] Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 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