From patchwork Wed Jan 11 18:04:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 42127 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3464499wrt; Wed, 11 Jan 2023 10:06:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXvtXMko/XO+Eqcqo+C/yOfpCGclvG1xO910jBq9ablpH3SHflwkdVswVbp4XFQSGVqcmkGS X-Received: by 2002:a17:906:edd6:b0:84d:138a:316 with SMTP id sb22-20020a170906edd600b0084d138a0316mr19591873ejb.36.1673460373931; Wed, 11 Jan 2023 10:06:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673460373; cv=none; d=google.com; s=arc-20160816; b=vBcREkX1wDucAHgwRBJj8FDb7g44LkJTyaB1G6FnGNpa7C0VseVVIW+AzSCs4A5y4q 2RJIKQIPPEyLUJFlK4DfFhUhRUzwxg3s9bvLX+ktIWMf3LIshGg+Y0c32T848uGKX+mu tq7H9fy+wDtCrYsGNwZe3gmURgToZwfz5mk+J1yocL3h+80AmULp9LhrKxjW2EDkC0Lo 02q+bQ8ABZd+8SPZzRx15SM9zLp7HQlV+p1WDntY7gijXo4YvZdoBpcdsNoEL/PuY+jO Lk7I2TgbzUMB+nbI7/olCRhJfsMuBEwt56xRDZAc7dOHJJpIX990F5xSyzmcfuq6Hg7u OxuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=OeYzxKlWzOVMmrfYvtFjI2gOX5qnhPBvOLdLsi8fl4s=; b=VGWVPTxroIjPh93bOyAZkmMcCwS7QbR4MITOP/FALLZE473x1HIJexeb2O2XSbVykJ eIZ1NxFqE87RgLGdgrY8SpRNzyfmHuAxAeAJi07qJsedXfzDSlgbyunjMJoqELBx8/Sr e9Tww9v0/q00MKp7EqoEskALN10mDryIfxi8wMtGOrB3d7KegZ3JIjpe8AhclQ8LJ2zg 6G2Z8XHz02Buoky1ho6b1Z6vnc3stNmn6CSio+4cSR+R7M/LZ673lniDLrOO6i+cIsux qTGXaXFzVhgWOlrMOdehCseHUP9LTs1BvztC49xwC6WWZy7EZgSzunqgml1JFUCDoZkk k1HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="e/xmm2dM"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qf20-20020a1709077f1400b0084b895b6a1csi16758875ejc.798.2023.01.11.10.06.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 10:06:13 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="e/xmm2dM"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3209638493CF for ; Wed, 11 Jan 2023 18:05:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3209638493CF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673460356; bh=OeYzxKlWzOVMmrfYvtFjI2gOX5qnhPBvOLdLsi8fl4s=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=e/xmm2dMW3tkbN1c0pvDU0PpUu/tsNT5oU11AFL4zIeoUSxSH/Yiv/ZqL0e/Z5Vy+ SLpLkY/5OVh/9OJaJSzub8PQ0T0vLtoznGY99vvZqBOAeasIvNghxO+bd+10TTq9k/ GtAfHcbJWByxECfIMt8Q3kGhmnDIwJtitLIUHCZo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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 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: 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-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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754750384660085661?= X-GMAIL-MSGID: =?utf-8?q?1754750384660085661?= 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. Jakub --- 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); +}