[middle-end/PR102359] Not add initialization for DECL_VALUE_EXPR variables with -ftrivial-auto-var-init
Message ID | 0FFDE9ED-74C7-4A66-8DD1-2AD8B55AB303@oracle.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68C0C385AC12 for <patchwork@sourceware.org>; Tue, 5 Oct 2021 04:53:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68C0C385AC12 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633409606; 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=mgMEcbowSkB2P/xW4rgHTAau4vozVFn18PhXSiw/14nsj3Pdg6v1T2z1aFLZiyokl fmHtVU+xvLMq4Fxiu6d2EA1NWzKTWZ0ACM5xsFv0QikwYhu1JuDt1XZy17A4HCQ4q/ +111U1psrTDy5vOf2OgJKdPMcwEwjNXnHEb2yDok= 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 <gcc-patches@gcc.gnu.org>; 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 <rguenther@suse.de> 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: <CH0PR10MB5082F08596C06D38E201682180AF9@CH0PR10MB5082.namprd10.prod.outlook.com> 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-Type: text/plain; charset="us-ascii" Content-ID: <4817D5EA9090444CACF28EB757F5AC81@namprd10.prod.outlook.com> Content-Transfer-Encoding: quoted-printable 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Qing Zhao via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Qing Zhao <qing.zhao@oracle.com> Cc: gcc-patches Nick Alcock via <gcc-patches@gcc.gnu.org> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[middle-end/PR102359] Not add initialization for DECL_VALUE_EXPR variables with -ftrivial-auto-var-init
|
|
Commit Message
Qing Zhao
Oct. 5, 2021, 4:52 a.m. UTC
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 <qing.zhao@oracle.com>
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 <qing.zhao@oracle.com>
* 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 <qing.zhao@oracle.com>
* 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
Comments
On Tue, 5 Oct 2021, Qing Zhao wrote: > 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 <qing.zhao@oracle.com> > 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 <qing.zhao@oracle.com> > > * 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 <qing.zhao@oracle.com> > > * 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; no need for the = false, it's always initialized below. > 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); That looks a bit weird when looking at ... > + > 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)) ... which just expands to if (DECL_HAS_VALUE_EXPR_P (decl) && DECL_HAS_VALUE_EXPR_P (decl)) can you please name 'is_value_expr_created_by_fe' as 'decl_had_value_expr_p' and check && !decl_had_value_expr_p here? So sth like diff --git a/gcc/gimplify.c b/gcc/gimplify.c index b27776af7c8..9013f385f13 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1872,6 +1872,7 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) { tree init = DECL_INITIAL (decl); bool is_vla = false; + bool decl_had_value_expr_p = DECL_HAS_VALUE_EXPR_P (decl); poly_uint64 size; if (!poly_int_tree_p (DECL_SIZE_UNIT (decl), &size) @@ -1934,7 +1935,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) + && !decl_had_value_expr_p) { gimple_add_init_for_auto_var (decl, flag_auto_var_init, OK with that change. Thanks, Richard. > { > 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 (); > +} >
> On Oct 5, 2021, at 3:19 AM, Richard Biener <rguenther@suse.de> wrote: > > On Tue, 5 Oct 2021, Qing Zhao wrote: > >> 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 <qing.zhao@oracle.com> >> 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 <qing.zhao@oracle.com> >> >> * 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 <qing.zhao@oracle.com> >> >> * 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; > > no need for the = false, it's always initialized below. > >> 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); > > That looks a bit weird when looking at ... > >> + >> 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)) > > ... which just expands to > > if (DECL_HAS_VALUE_EXPR_P (decl) && DECL_HAS_VALUE_EXPR_P (decl)) > > can you please name 'is_value_expr_created_by_fe' as > 'decl_had_value_expr_p' and check && !decl_had_value_expr_p here? > So sth like I can do this -:) I agree that the change will make the code simpler. However, my major concern with this change is: later when people look at this change, they might ask: Why we should not initialize a variable with VALUE_EXPR? And whether the variable whose VALUE_EXPR was created by “gimplify_vla_decl” should be excluded? My new function and comments were all for this purpose. If I go with this change, at least we should add some comments to explain this as following, what do you think? > > diff --git a/gcc/gimplify.c b/gcc/gimplify.c > index b27776af7c8..9013f385f13 100644 > --- a/gcc/gimplify.c > +++ b/gcc/gimplify.c > @@ -1872,6 +1872,7 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) > { > tree init = DECL_INITIAL (decl); > bool is_vla = false; + /* Check whether a decl has FE created VALUE_EXPR here BEFORE + gimplify_vla_decl creates VALUE_EXPR for vla decl. */ > + bool decl_had_value_expr_p = DECL_HAS_VALUE_EXPR_P (decl); > > poly_uint64 size; > if (!poly_int_tree_p (DECL_SIZE_UNIT (decl), &size) > @@ -1934,7 +1935,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) + /* 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. */ > + && !decl_had_value_expr_p) > { > gimple_add_init_for_auto_var (decl, > flag_auto_var_init, > > OK with that change. thanks. Qing > > Thanks, > Richard. > > >> { >> 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 (); >> +} >> > > -- > Richard Biener <rguenther@suse.de> > SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, > Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)
This is the updated patch, I will push it after done with testing.
Let me know if you see any issue.
Thanks.
Qing.
============================
From 1f07c20ecdc9a015369c8bb472ebbd3bcaabdf17 Mon Sep 17 00:00:00 2001
From: qing zhao <qing.zhao@oracle.com>
Date: Tue, 5 Oct 2021 08:10:02 -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-05 qing zhao <qing.zhao@oracle.com>
* gimplify.c (gimplify_decl_expr): Not add initialization for an
auto variable when it has been initialized by frontend.
gcc/testsuite/ChangeLog:
2021-10-05 qing zhao <qing.zhao@oracle.com>
* g++.dg/pr102359_1.C: New test.
* g++.dg/pr102359_2.C: New test.
---
gcc/gimplify.c | 9 ++++++++-
gcc/testsuite/g++.dg/pr102359_1.C | 13 +++++++++++++
gcc/testsuite/g++.dg/pr102359_2.C | 13 +++++++++++++
3 files changed, 34 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..d96fca4 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -1872,6 +1872,9 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p)
{
tree init = DECL_INITIAL (decl);
bool is_vla = false;
+ /* Check whether a decl has FE created VALUE_EXPR here BEFORE
+ gimplify_vla_decl creates VALUE_EXPR for a vla decl. */
+ bool decl_had_value_expr_p = DECL_HAS_VALUE_EXPR_P (decl);
poly_uint64 size;
if (!poly_int_tree_p (DECL_SIZE_UNIT (decl), &size)
@@ -1934,7 +1937,11 @@ 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)
+ /* If the decl has VALUE_EXPR that was created by FE (usually
+ C++FE), it's a proxy varaible, and FE already initialized
+ the VALUE_EXPR of it, we should not initialize it here. */
+ && !decl_had_value_expr_p)
{
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 ();
+}
On 10/5/21 10:32, Qing Zhao wrote: > > >> On Oct 5, 2021, at 3:19 AM, Richard Biener <rguenther@suse.de> wrote: >> >> On Tue, 5 Oct 2021, Qing Zhao wrote: >> >>> 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 <qing.zhao@oracle.com> >>> 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 <qing.zhao@oracle.com> >>> >>> * 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 <qing.zhao@oracle.com> >>> >>> * 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; >> >> no need for the = false, it's always initialized below. >> >>> 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); >> >> That looks a bit weird when looking at ... >> >>> + >>> 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)) >> >> ... which just expands to >> >> if (DECL_HAS_VALUE_EXPR_P (decl) && DECL_HAS_VALUE_EXPR_P (decl)) >> >> can you please name 'is_value_expr_created_by_fe' as >> 'decl_had_value_expr_p' and check && !decl_had_value_expr_p here? >> So sth like > > I can do this -:) I agree that the change will make the code simpler. > > However, my major concern with this change is: later when people look at this change, they might ask: > Why we should not initialize a variable with VALUE_EXPR? And whether the variable whose VALUE_EXPR > was created by “gimplify_vla_decl” should be excluded? > > My new function and comments were all for this purpose. > > If I go with this change, at least we should add some comments to explain this as following, what do you think? >> >> diff --git a/gcc/gimplify.c b/gcc/gimplify.c >> index b27776af7c8..9013f385f13 100644 >> --- a/gcc/gimplify.c >> +++ b/gcc/gimplify.c >> @@ -1872,6 +1872,7 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) >> { >> tree init = DECL_INITIAL (decl); >> bool is_vla = false; > > + /* Check whether a decl has FE created VALUE_EXPR here BEFORE > + gimplify_vla_decl creates VALUE_EXPR for vla decl. */ >> + bool decl_had_value_expr_p = DECL_HAS_VALUE_EXPR_P (decl); >> >> poly_uint64 size; >> if (!poly_int_tree_p (DECL_SIZE_UNIT (decl), &size) >> @@ -1934,7 +1935,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) > > + /* 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. */ I'd suggest merging this comment into the comment on the variable declaration. >> + && !decl_had_value_expr_p) >> { >> gimple_add_init_for_auto_var (decl, >> flag_auto_var_init, >> >> OK with that change. > > thanks. > > Qing >> >> Thanks, >> Richard. >> >> >>> { >>> 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 (); >>> +} >>> >> >> -- >> Richard Biener <rguenther@suse.de> >> SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, >> Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg) >
> On Oct 5, 2021, at 1:30 PM, Jason Merrill <jason@redhat.com> wrote: > >>> 'decl_had_value_expr_p' and check && !decl_had_value_expr_p here? >>> So sth like >> I can do this -:) I agree that the change will make the code simpler. >> However, my major concern with this change is: later when people look at this change, they might ask: >> Why we should not initialize a variable with VALUE_EXPR? And whether the variable whose VALUE_EXPR >> was created by “gimplify_vla_decl” should be excluded? >> My new function and comments were all for this purpose. >> If I go with this change, at least we should add some comments to explain this as following, what do you think? >>> >>> diff --git a/gcc/gimplify.c b/gcc/gimplify.c >>> index b27776af7c8..9013f385f13 100644 >>> --- a/gcc/gimplify.c >>> +++ b/gcc/gimplify.c >>> @@ -1872,6 +1872,7 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) >>> { >>> tree init = DECL_INITIAL (decl); >>> bool is_vla = false; >> + /* Check whether a decl has FE created VALUE_EXPR here BEFORE >> + gimplify_vla_decl creates VALUE_EXPR for vla decl. */ >>> + bool decl_had_value_expr_p = DECL_HAS_VALUE_EXPR_P (decl); >>> >>> poly_uint64 size; >>> if (!poly_int_tree_p (DECL_SIZE_UNIT (decl), &size) >>> @@ -1934,7 +1935,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) >> + /* 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. */ > > I'd suggest merging this comment into the comment on the variable declaration. Okay, will merge these two comments into one and put it on the variable declaration. thanks. Qing
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 (); +}