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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 88D483858C39 for ; Thu, 30 Sep 2021 04:27:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 88D483858C39 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-555-s_weNJWmOjuj4eU_GvAeww-1; Thu, 30 Sep 2021 00:27:20 -0400 X-MC-Unique: s_weNJWmOjuj4eU_GvAeww-1 Received: by mail-qv1-f72.google.com with SMTP id e8-20020a0cf348000000b0037a350958f2so9916070qvm.7 for ; Wed, 29 Sep 2021 21:27:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=M9KWI3M3jJ1NW87fV4wrFC7x+gKZiXavNc6goL1p7OI=; b=dQOQ0npFHrsiUi0b1E/oH76EYcZqtaFjTE1BnJf5sTx1Inx2dVcMcptVk/BcAjbV/w FO8QM/87HPGT/CqNMonlVCd4IC+tnze4sMLqUaREfFt+A7ORbLWIqDe+KF4FhwL06HCt +sLcgZbezkzF63A7MxbhdXz4+8XbM20H0TNj1PX2iOOCgFTnmrmv+X/+wlofjmq+Wmc4 mEd7n7XS0wbMNwcqith2erv0wOVC2DuqgplXNvIYg8ZN/8+FzXfcU/hONlPKtoWIOGRZ mY4pc2rG/WjbjZHk4l9fIogt4edC0kjnb1uQCStvYXsYi52oAOLgG5pw1Hes18stZi/I 1UCA== X-Gm-Message-State: AOAM530MEMCz6IDYrPZFyHoidin0hOjEMLxsPblNoQCJgGgOAu+gyr3s 45MivWH+xF2rio8mpG8mL03vCb9TxNZnc0PGKoRfkUKGfa0x0Z3usdHhxmA3PBYeX2wr0AfJD3R GCRF0/KWlKwy0TFlPHA== X-Received: by 2002:a37:a7d5:: with SMTP id q204mr3149515qke.236.1632976039953; Wed, 29 Sep 2021 21:27:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKGRC/FmOU5o2XjEKVeCLZxdHJZf8dyKBahvrP9yjhR+D4jgww0y8htrDZe5HMiX8Q63p9rA== X-Received: by 2002:a37:a7d5:: with SMTP id q204mr3149499qke.236.1632976039642; Wed, 29 Sep 2021 21:27:19 -0700 (PDT) Received: from [192.168.1.149] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id l1sm1061709qti.94.2021.09.29.21.27.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Sep 2021 21:27:19 -0700 (PDT) Message-ID: <788c04d7-6e87-4eff-decb-a13abf0b4058@redhat.com> Date: Thu, 30 Sep 2021 00:27:18 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 Subject: Re: [RFC][Patch][middle-end/PR102359]Not add initialization for READONLY variables with -ftrivial-auto-var-init To: Qing Zhao , richard Biener Cc: gcc-patches Nick Alcock via References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, 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-List-Received-Date: Thu, 30 Sep 2021 04:27:27 -0000 On 9/29/21 17:30, Qing Zhao wrote: > Hi, > > PR102359 (ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a) > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102359 > > Is due to -ftrivial-auto-var-init adding initialization for READONLY variable “this” in the following routine: (t.cpp.005t.original) > > ======= > > ;; Function A::foo():: (null) > ;; enabled by -tree-original > > { > const struct A * const this [value-expr: &__closure->__this]; > const struct A * const this [value-expr: &__closure->__this]; > return = (double) ((const struct A *) this)->a; > } > ======= > > However, in the above routine, “this” is NOT marked as READONLY, but its value-expr "&__closure->__this” is marked as READONLY. > > There are two major issues: > > 1. In the routine “is_var_need_auto_init”, we should exclude “decl” that is marked as READONLY; > 2. In the C++ FE, “this” should be marked as READONLY. > > The idea solution will be: > > 1. Fix “is_var_need_auto_init” to exclude TREE_READONLY (decl); > 2. Fix C++ FE to mark “this” as TREE_READONLY (decl)==true; > > Not sure whether it’s hard for C++ FE to fix the 2nd issue or not? > > In the case it’s not a quick fix in C++FE, I proposed the following fix in middle end: > > Let me know your comments or suggestions on this. > > Thanks a lot for the help. I'd think is_var_need_auto_init should be false for any variable with DECL_HAS_VALUE_EXPR_P, as they aren't really variables, just ways of naming objects that are initialized elsewhere. > Qing > > ============================== > From 0a5982cd61bc4610655d3df00ae8d2fbcb3c8e9b Mon Sep 17 00:00:00 2001 > From: Qing Zhao > Date: Wed, 29 Sep 2021 20:49:59 +0000 > Subject: [PATCH] Fix PR102359 > > --- > gcc/gimplify.c | 15 +++++++++++++++ > gcc/testsuite/g++.dg/pr102359.C | 13 +++++++++++++ > 2 files changed, 28 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/pr102359.C > > diff --git a/gcc/gimplify.c b/gcc/gimplify.c > index 1067113b1639..a2587869b35d 100644 > --- a/gcc/gimplify.c > +++ b/gcc/gimplify.c > @@ -1819,12 +1819,27 @@ 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 READONLY. > + This is to workaround a C++ FE bug that only mark the value_expr of "this" > + as readonly but does not mark "this" as readonly. > + C++ FE should fix this issue before replacing this routine with > + TREE_READONLY (decl). */ > + > +static bool > +is_decl_readonly (tree decl) > +{ > + return (TREE_READONLY (decl) > + || (DECL_HAS_VALUE_EXPR_P (decl) > + && TREE_READONLY (DECL_VALUE_EXPR (decl)))); > +} > + > /* Return true if the DECL need to be automaticly initialized by the > compiler. */ > static bool > is_var_need_auto_init (tree decl) > { > if (auto_var_p (decl) > + && !is_decl_readonly (decl) > && (flag_auto_var_init > AUTO_INIT_UNINITIALIZED) > && (!lookup_attribute ("uninitialized", DECL_ATTRIBUTES (decl))) > && !is_empty_type (TREE_TYPE (decl))) > diff --git a/gcc/testsuite/g++.dg/pr102359.C b/gcc/testsuite/g++.dg/pr102359.C > new file mode 100644 > index 000000000000..da643cde7bed > --- /dev/null > +++ b/gcc/testsuite/g++.dg/pr102359.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()(); >