From patchwork Tue Oct 5 04:52:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 1536467 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=hYwzB+Ov; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HNlbZ67GDz9sR4 for ; Tue, 5 Oct 2021 15:53:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BEB18385AC26 for ; Tue, 5 Oct 2021 04:53:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEB18385AC26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633409618; bh=Im3214LIRDPv5KaCNgfVrO9pLk+yyRfJkubJkp6r/OY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=hYwzB+OvdGuR3cCjCOQIsis2XQp+6SBUtffcK+DT/q+cubxLAeTg4e7LThp13m7BX dnd2kgNnNlbIe8m8GDmw9khypKR4NXYSKa3ktfgifjXiCr/i5o0pvTKG0OSVxD86BC bKp97+YDBP11SvhNEmXECu6LQBfqPXPn1eEJzfb8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 9E6B83858D39 for ; Tue, 5 Oct 2021 04:52:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9E6B83858D39 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1953TPIJ023948; Tue, 5 Oct 2021 04:52:49 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3bg43gmcvs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 05 Oct 2021 04:52:49 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1954orL0002742; Tue, 5 Oct 2021 04:52:48 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by userp3030.oracle.com with ESMTP id 3bf0s5w0h3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 05 Oct 2021 04:52:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WRsm8wPAnwoy+T1EmMETrb8goryvU+Fo4rQVm2al2GNvZN0fHz7d7MAxt0rn6zrKTF5yhBQb18ZRObqqAs40RzJkzQOO/GUBDB7DzHUblAiUGTCEG8o3ETvjBOC6pXCs/LHJhgbbvzZcEKlURCN00aHh3smkQtMecaZlFN3a1k1DRfrXHT1nBKT6xc/8Com8DEnVv8WkMwrtQQNcRYc4mZ0qYQt4VMjtyk38Nvkj8cMhsbyjCTD8prady8tJsW4wCOXCc1OEhmDU2pS3927rsS52T5j1d1HOl5u63bEoAyEfeS8yBPKRyJ2mfbpdTS+N2hXnXvIQFj5gG6qQQLIDYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Im3214LIRDPv5KaCNgfVrO9pLk+yyRfJkubJkp6r/OY=; b=T+mK57fecJk1y5Bn0i5Gq6M5I1BO/zRLDkT9roJ2h9f7hmk0Lh6oEUCyguW/P5D9T5WbhaR06fzi+95W0ipzgPoZ1BNOKDLjAiTLAR54ZGzi8kJMzrN6wShAZWspenBQz8IAKwv4Pl2jJgywdlbTDOlh6Tzh2xmpw5KRN19cOXV9IIPjX3BiO18WPH2kIla9iCbmRnaaJJVtcF3hB4c4mhBtnS5Cn565Pya0kATNRxW6mRV5v/Ix5TmD4Pn343OxyjErvaSxlheUxvzGIIYliEG28SSqzrA4THzJH1VidC6u2Q6ECr7AIUIaXfGkdCqYDeETmObS+KSt2PARf9KhDA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from CH2PR10MB4344.namprd10.prod.outlook.com (2603:10b6:610:af::19) by CH0PR10MB5082.namprd10.prod.outlook.com (2603:10b6:610:c1::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.13; Tue, 5 Oct 2021 04:52:46 +0000 Received: from CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::25f8:eaf:a3b9:fe86]) by CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::25f8:eaf:a3b9:fe86%3]) with mapi id 15.20.4566.022; Tue, 5 Oct 2021 04:52:46 +0000 To: Richard Biener Subject: [patch][middle-end/PR102359]Not add initialization for DECL_VALUE_EXPR variables with -ftrivial-auto-var-init Thread-Topic: [patch][middle-end/PR102359]Not add initialization for DECL_VALUE_EXPR variables with -ftrivial-auto-var-init Thread-Index: AQHXuaTX+4yDFlq9S0W3LVV8v5PQnw== Date: Tue, 5 Oct 2021 04:52:46 +0000 Message-ID: <0FFDE9ED-74C7-4A66-8DD1-2AD8B55AB303@oracle.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3608.120.23.2.7) x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 925c8553-6429-497a-39f8-08d987bbf995 x-ms-traffictypediagnostic: CH0PR10MB5082: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: mdvSxI3sHi1/pc+YWYpfGZtSaXfNwD9Csqnl0HVymQXLyIpoNkRCim2c5iyr0AQW9X26VVH/gLQVXsy1bRoo17CBvBEK0Twy9sD53GdIsLUFBPshaJtkpxCS89l8grxsEi7/SVTPkusCfPp3jbQwgiN9H7bntlyei12RL+LCluoG52pjzwe1oyfTGSan5fMywMfz1i1i9KkXGCMAqAeNdz9STsVt5m2VE87/DqvSC/dlPQ4mCGLWZR6fL4TWbuAR+nQ0ZtLuohAy6HOm9RZhBzlykpjBkzVnleMpl7PzLh7hK865MjNMW+20TXXH2M5gw+Gd8K2oYXIoODrICEZEVZyL0s4Z2g31CiPqx8k2nXYHNlKtjYgm8LWH/OjDQNtH9r53FB09pojNiieOA2AnFuUmuz0VE4+ow+gojHiDpNeXLf7jhcsSF6D/0tTKY4eDLgmg7g8lcJ0Id11MX29mJMFZAxqGj94J5JtZDhzMlE3977MqY+N692lh5QbLnyofn9IuHLsRcqqFIqSB+jDQmMVj8+IGp0vC2QCtdbXoDTwfE1cl2KRi9S1j/ZaQ78lKggk7XWcsN/N6gxk3YTfHMDRj6bAg9PP0oAgz1mRr/iXUGVl2eMJV0T3tjyfn7e6c5G/C8xU2ebRNIai+64mLhUuydAHfUpuQkOiQqSiLdp4+IDh7Nt1mRqPgsTdfdy4EU8CfiUHSRa9c6vHcXTWR+1NxPTQieoWm4KYBHU4O3c2uVQrmJoQGw7mBZP6t9tV0 x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4344.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(83380400001)(4326008)(122000001)(76116006)(8936002)(33656002)(66946007)(66446008)(6486002)(64756008)(186003)(66476007)(66556008)(71200400001)(8676002)(5660300002)(38100700002)(91956017)(508600001)(6512007)(2616005)(316002)(44832011)(2906002)(6916009)(86362001)(54906003)(36756003)(38070700005)(6506007)(53546011)(45980500001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 45QHOlBN5k8VzosxHAG8C49mUhZC41GF8TQjPmA+4PX3izyBwvxCmgb/au8NwPfHq71PNSORY0c6/C7ChPRROiOweKx7xs8xL/P15jK+M7T6ZyHhqjXC5KKAoNNtzUayaAq+2Bu8yD2IZgGQFonENPCvdwVf7H14vX70bVa19BBXZyJhs4fxKgAr5tsljhLFlwseGaxkXRYgJGfQFBH9yPapSDfZdj8kpDB8RFICfnXFtnz/DSDMhhSXgfdXEkONC/JWOyuoId2ceBsStNVyOySbqT214GYM0Pm8DZEBNVYTkxvzKUxuqZodtN05F1x2tzM4wXF/rZaKA4NBQP4yAXf5qQ8E4iCGzr/2y4BYOI/DYgGjLyQY/znz0M88NutGjcrg80mUQcxBRpxlDCoXQ7YKaEjhWZfdDIEmmsCnKR5gS9vyV7zhJSLIX/WKYyRiGsHOTP4ob2KehO5dSsi1RCoUPRo12c/Zgt0PpyqBnZdvp7Rp5Lg94F+izcdMuYoMyF6n9lfUq50R/ATSqML2RIwpzpd1S79qbuWVetqvEIJrx2jLjwnVzzA1KxEyb3qGAqPke9ul8AGuNlX7p8i9oB7A05pJ1XBdH/wNd6FtEyCGdPD5k48QDgl9DtHOgePr/FBXTCzmPh/0O7ogZF57CF5MwISiUlXxb66fJ4Tq5CV51EOm3Bj+V0UDcsAmtI8nrhfKUixTvzgT2v4DsmatCYeodR53fNZfRK4yygTp8fwrqUmDfXR4rG2PdIiFtrBhwV00N1Z9aDmaSgcqViTgGnSnoA/w2t2oOUHZGMGCeRJDOjOKEuivS8xVQFfRGKxMCHZjagKARDy/97EVoOXLHXJ6cIbGMOObU4eBpx5t4J15VBgTInurxkmo0Q1c6LyXRpe4wga5wTuZ+PqrFipus/0p5DkQsh0iFZW3ZUuTDYTuONTkywuOQfAHN00R6tlV8wPyLXIaLAUgAAiMbiUL8Cj59iT+3jYmx6zI1rdpiHB9COsN8ttzdOOGQR+0mzCQk7A2IGSnEQL5a50IYrBf+P9MyBsnzkyth3ECI6E6+iS94n9eYZ2i2RpzGzgS6wAn2f2RRg7iUpOB+1LxYsgCzIuYorTCPEry+XUIofC0DXxJIJTaQemJXL3h6/qDosbb1ep0VxDCcZ5+eGqdL7LQ3RrKPkuq/jEifNZmx/tynEShLtnRRXK2cckeGB96wNxIXRFynwdILCOZW5fSW2i7Uq33cxFaKLKnCg2iD+3YqpGcRDLhgaubsKTJh2RqRK1oe1IQOd9/xyg719LI6j4OfFVh54Azd8wYVcazBwYohCPHNHVS/SDNTRQik15JNBK5JPb7rFBpkyBXNxO5CQEpEVuwMXax1hu3JCg3RpzGc1w= x-ms-exchange-transport-forked: True Content-ID: <4817D5EA9090444CACF28EB757F5AC81@namprd10.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4344.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 925c8553-6429-497a-39f8-08d987bbf995 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Oct 2021 04:52:46.4282 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: AuHAZKx6b4IzWl/PfAd6AwS84H3ghpQuXWjEUbCUxu16RScOYngT7329Nuzls1alX3TwNWM/kIBdyvSJ4sKM6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5082 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10127 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 adultscore=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110050026 X-Proofpoint-GUID: 7Go6WSzp3ouuZW_NHKkDeU4AD51I2Imo X-Proofpoint-ORIG-GUID: 7Go6WSzp3ouuZW_NHKkDeU4AD51I2Imo X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Qing Zhao via Gcc-patches From: Qing Zhao Reply-To: Qing Zhao Cc: gcc-patches Nick Alcock via Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This is the patch to fix this issue based on our discussion. I have tested it on aarch64 with bootstrap and regtests. X86 bootstrap was done, regtests is ongoing. Okay for trunk? Thanks. Qing ====================== From d349ef0145512efe7f9af2c6bbd01f636475bce3 Mon Sep 17 00:00:00 2001 From: qing zhao Date: Mon, 4 Oct 2021 15:26:03 -0700 Subject: [PATCH] middle-end/102359 Not add initialization for variables that have been initialized by FEs. C++ FE creates proxy variables, which have associated DECL_VALUE_EXPR and have been initialized by FE. For such auto variable, we should not add initialization when -ftrivial-auto-var-init presents. gcc/ChangeLog: 2021-10-04 qing zhao * gimplify.c (is_decl_init_by_fe): New function. (gimplify_decl_expr): Not add initialization for an auto variable when it has been initialized by frontend. gcc/testsuite/ChangeLog: 2021-10-04 qing zhao * g++.dg/pr102359_1.C: New test. * g++.dg/pr102359_2.C: New test. --- gcc/gimplify.c | 21 ++++++++++++++++++++- gcc/testsuite/g++.dg/pr102359_1.C | 13 +++++++++++++ gcc/testsuite/g++.dg/pr102359_2.C | 13 +++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/pr102359_1.C create mode 100644 gcc/testsuite/g++.dg/pr102359_2.C diff --git a/gcc/gimplify.c b/gcc/gimplify.c index b27776a..d6865ad 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1819,6 +1819,19 @@ gimple_add_padding_init_for_auto_var (tree decl, bool is_vla, gimplify_seq_add_stmt (seq_p, call); } +/* Return true if the DECL is initialized by FE. + If the VAR_DECL has DECL_VALUE_EXPR that was created by FE (usually C++FE), + it's a proxy varaible, and FE already initializd the DECL_VALUE_EXPR of it. +*/ +static bool +is_decl_init_by_fe (tree decl, bool is_created_by_fe) +{ + if (DECL_HAS_VALUE_EXPR_P (decl) + && is_created_by_fe) + return true; + return false; +} + /* Return true if the DECL need to be automaticly initialized by the compiler. */ static bool @@ -1871,8 +1884,13 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) if (VAR_P (decl) && !DECL_EXTERNAL (decl)) { tree init = DECL_INITIAL (decl); + bool is_value_expr_created_by_fe = false; bool is_vla = false; + /* Check whether a decl has FE created VALUE_EXPR here BEFORE + gimplify_vla_decl creates VALUE_EXPR for vla decl. */ + is_value_expr_created_by_fe = DECL_HAS_VALUE_EXPR_P (decl); + poly_uint64 size; if (!poly_int_tree_p (DECL_SIZE_UNIT (decl), &size) || (!TREE_STATIC (decl) @@ -1934,7 +1952,8 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) /* When there is no explicit initializer, if the user requested, We should insert an artifical initializer for this automatic variable. */ - else if (is_var_need_auto_init (decl)) + else if (is_var_need_auto_init (decl) + && !is_decl_init_by_fe (decl, is_value_expr_created_by_fe)) { gimple_add_init_for_auto_var (decl, flag_auto_var_init, diff --git a/gcc/testsuite/g++.dg/pr102359_1.C b/gcc/testsuite/g++.dg/pr102359_1.C new file mode 100644 index 0000000..da643cd --- /dev/null +++ b/gcc/testsuite/g++.dg/pr102359_1.C @@ -0,0 +1,13 @@ +/* PR middle-end/102359 ICE gimplification failed since + r12-3433-ga25e0b5e6ac8a77a. */ +/* { dg-do compile } */ +/* { dg-options "-ftrivial-auto-var-init=zero" } */ +/* { dg-require-effective-target c++17 } */ + +struct A { + double a = 111; + auto foo() { + return [*this] { return a; }; + } +}; +int X = A{}.foo()(); diff --git a/gcc/testsuite/g++.dg/pr102359_2.C b/gcc/testsuite/g++.dg/pr102359_2.C new file mode 100644 index 0000000..d026d72 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr102359_2.C @@ -0,0 +1,13 @@ +/* PR middle-end/102359 ICE gimplification failed since + r12-3433-ga25e0b5e6ac8a77a. */ +/* { dg-do run} */ +/* { dg-options "-ftrivial-auto-var-init=zero" } */ +/* { dg-require-effective-target c++17 } */ + +int main() +{ + int i = 42; + auto l = [=]() mutable { return i; }; + if (l() != i) + __builtin_abort (); +}