From patchwork Thu Apr 30 12:54:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1280346 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Xlxadcqs; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Cb1x414nz9sSd for ; Thu, 30 Apr 2020 22:54:45 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77AFB395CC48; Thu, 30 Apr 2020 12:54:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77AFB395CC48 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588251283; bh=pxTXLxJ/aHhWYolQowzItfc5YXW/Ut0/pE8uDAGtKoo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=XlxadcqsTnx8yqNEMgffA4PuyDitJ30eBk0KU9DSnAJ5nkPq/RVwc8b/vwn2ZfIO8 xW10vBTeV1kf4ieDeeKoxYjgGL/CFvhnkfVgfYGq1lHosyp1/0+6QplgqpML3g3rg4 +KxEWL4LOZ3J3qrgFEnBStmwDdwHATvWTEqYntV4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id A6542395C871 for ; Thu, 30 Apr 2020 12:54:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A6542395C871 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-411-w1yiR_24Nt6cjpBPKSvw0Q-1; Thu, 30 Apr 2020 08:54:39 -0400 X-MC-Unique: w1yiR_24Nt6cjpBPKSvw0Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F0D6468; Thu, 30 Apr 2020 12:54:38 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-104.ams2.redhat.com [10.36.112.104]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D243B2855B; Thu, 30 Apr 2020 12:54:33 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 03UCsUeV030339; Thu, 30 Apr 2020 14:54:30 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 03UCsT83030338; Thu, 30 Apr 2020 14:54:29 +0200 Date: Thu, 30 Apr 2020 14:54:29 +0200 To: "Joseph S. Myers" , Marek Polacek Subject: [PATCH] c: Fix ICE with _Atomic side-effect in nested fn param decls [PR94842] Message-ID: <20200430125429.GU2424@tucnak> MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-16.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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 Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! If there are _Atomic side-effects in the parameter declarations of non-nested function, when they are parsed, current_function_decl is NULL, the create_artificial_label created labels during build_atomic* are then adjusted by store_parm_decls through set_labels_context_r callback. Unfortunately, if such thing happens in nested function parameter declarations, while those decls are parsed current_function_decl is the parent function (and am not sure it is a good idea to temporarily clear it, some code perhaps should be aware it is in a nested function, or it can refer to variables from the parent function etc.) and that means store_param_decls through set_labels_context_r doesn't adjust anything. As those labels are emitted in the nested function body rather than in the parent, I think it is ok to override the context in those cases. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2020-04-30 Jakub Jelinek PR c/94842 * c-decl.c (set_labels_context_r): In addition to context-less LABEL_DECLs adjust also LABEL_DECLs with context equal to parent function if any. (store_parm_decls): Adjust comment. * gcc.dg/pr94842.c: New test. Jakub --- gcc/c/c-decl.c.jj 2020-04-08 11:59:23.726461457 +0200 +++ gcc/c/c-decl.c 2020-04-30 12:19:35.918946543 +0200 @@ -9722,15 +9722,18 @@ store_parm_decls_from (struct c_arg_info store_parm_decls (); } -/* Called by walk_tree to look for and update context-less labels. */ +/* Called by walk_tree to look for and update context-less labels + or labels with context in the parent function. */ static tree set_labels_context_r (tree *tp, int *walk_subtrees, void *data) { + tree ctx = static_cast(data); if (TREE_CODE (*tp) == LABEL_EXPR - && DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == NULL_TREE) + && (DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == NULL_TREE + || DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) == DECL_CONTEXT (ctx))) { - DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) = static_cast(data); + DECL_CONTEXT (LABEL_EXPR_LABEL (*tp)) = ctx; *walk_subtrees = 0; } @@ -9800,7 +9803,11 @@ store_parm_decls (void) gotos, labels, etc. Because at that time the function decl for F has not been created yet, those labels do not have any function context. But we have the fndecl now, so update the - labels accordingly. gimplify_expr would crash otherwise. */ + labels accordingly. gimplify_expr would crash otherwise. + Or with nested functions the labels could be created with parent + function's context, while when the statement is emitted at the + start of the nested function, it needs the nested function's + context. */ walk_tree_without_duplicates (&arg_info->pending_sizes, set_labels_context_r, fndecl); add_stmt (arg_info->pending_sizes); --- gcc/testsuite/gcc.dg/pr94842.c.jj 2020-04-30 12:25:52.431360645 +0200 +++ gcc/testsuite/gcc.dg/pr94842.c 2020-04-30 12:24:47.522323298 +0200 @@ -0,0 +1,11 @@ +/* PR c/94842 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +_Atomic float x = 5; + +void +foo (void) +{ + void bar (float y[(int) (x += 2)]) {} +}