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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 91CEC385803D for ; Tue, 26 Jul 2022 20:24:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 91CEC385803D Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-570-KHeqf5-COhi8NpwVT3MRhw-1; Tue, 26 Jul 2022 16:24:21 -0400 X-MC-Unique: KHeqf5-COhi8NpwVT3MRhw-1 Received: by mail-qv1-f71.google.com with SMTP id ei6-20020ad45a06000000b004746f72008dso1107358qvb.11 for ; Tue, 26 Jul 2022 13:24:21 -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=MppVBr/1edxWwsDvREl3lXgeUZWjdnxGQav8joLoMTg=; b=ftlWsZCWRJgl2iJRoBl2rREQtBjskwaTyio5ZbZmsBvYkpO9gqMdVIt4drR7QcNkbJ D4zz512hC2yiQqQ8JFlYLSB0Ocyd/++AosPujmL+R1DMfs11s60PcX4kB8hTsaoL2PYy 4mEicO1tBV/MlDkusdDFDoO2Jnn+SIDXIBmpsM68hYbepxsTeNtUvsoq/sNnZlVgAU8j +aC1+8KpmWqbbE3UywtEzpuI9ifQc65i2iH2oueiACi4CnwkvdrpH/1QFAVBaM/A83+Q aWyeFyynYMQuZU+oX3hL0izUPsf5gcbJ3bLjWO36TCV9LDlj0HOttlEleeR56zltkFCn nL7A== X-Gm-Message-State: AJIora/MZ3sb9JXJmXJpSRJVqtFCYbSmS8TeQUgWST0wXvkDn+Aqy8o5 H4me1bDOzUuIySWOmCbPNqBrUWlpLM3PPYpS3UvxD73V+p0gtVZ0Nmu7EjU9B+TSVBga+mRVHnC jLBDBp3efF3gpSh4Ihw== X-Received: by 2002:ad4:594e:0:b0:474:4e75:3579 with SMTP id eo14-20020ad4594e000000b004744e753579mr9518758qvb.74.1658867059797; Tue, 26 Jul 2022 13:24:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1udiJLlqIknq4bsXY1XcTxGqzqRD2h7KrYuaYPpbNlP0bOCtN9czMNmd6jh+PYpsNAtUMT3fw== X-Received: by 2002:ad4:594e:0:b0:474:4e75:3579 with SMTP id eo14-20020ad4594e000000b004744e753579mr9518735qvb.74.1658867059459; Tue, 26 Jul 2022 13:24:19 -0700 (PDT) Received: from [192.168.1.100] (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 z14-20020ae9c10e000000b006a6c552736asm11072334qki.119.2022.07.26.13.24.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 Jul 2022 13:24:19 -0700 (PDT) Message-ID: <51485fa8-a1c0-c019-c2bb-f4599fe34ca4@redhat.com> Date: Tue, 26 Jul 2022 16:24:18 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] c-family: Honor -Wno-init-self for cv-qual vars [PR102633] To: Marek Polacek , GCC Patches Cc: Joseph Myers , Richard Biener References: <20220726190340.432777-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: <20220726190340.432777-1-polacek@redhat.com> 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: 7bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, 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-List-Received-Date: Tue, 26 Jul 2022 20:24:25 -0000 On 7/26/22 15:03, Marek Polacek wrote: > Since r11-5188-g32934a4f45a721, we drop qualifiers during l-to-r > conversion by creating a NOP_EXPR. For e.g. > > const int i = i; > > that means that the DECL_INITIAL is '(int) i' and not 'i' anymore. > Consequently, we don't suppress_warning here: > > 711 case DECL_EXPR: > 715 if (VAR_P (DECL_EXPR_DECL (*expr_p)) > 716 && !DECL_EXTERNAL (DECL_EXPR_DECL (*expr_p)) > 717 && !TREE_STATIC (DECL_EXPR_DECL (*expr_p)) > 718 && (DECL_INITIAL (DECL_EXPR_DECL (*expr_p)) == DECL_EXPR_DECL (*expr_p)) > 719 && !warn_init_self) > 720 suppress_warning (DECL_EXPR_DECL (*expr_p), OPT_Winit_self); > > because of the check on line 718 -- (int) i is not i. So -Wno-init-self > doesn't disable the warning as it's supposed to. > > The following patch fixes it...except it doesn't, for volatile variables > in C++. The problem is that for > > volatile int k = k; > > we see that the initializer has TREE_SIDE_EFFECTS, so we perform dynamic > initialization. So there's no DECL_INITIAL and the suppress_warning > call above is never done. I suppose we could amend get_no_uninit_warning > to return true for volatile-qualified expressions. I mean, can we ever > say for a fact that a volatile variable is uninitialized? > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > PR middle-end/102633 > > gcc/c-family/ChangeLog: > > * c-gimplify.cc (c_gimplify_expr): Strip NOPs of DECL_INITIAL. I wonder if we want to handle this i = i case earlier, like in finish_decl. > gcc/testsuite/ChangeLog: > > * c-c++-common/Winit-self1.c: New test. > * c-c++-common/Winit-self2.c: New test. > --- > gcc/c-family/c-gimplify.cc | 18 +++++++------ > gcc/testsuite/c-c++-common/Winit-self1.c | 32 ++++++++++++++++++++++++ > gcc/testsuite/c-c++-common/Winit-self2.c | 31 +++++++++++++++++++++++ > 3 files changed, 74 insertions(+), 7 deletions(-) > create mode 100644 gcc/testsuite/c-c++-common/Winit-self1.c > create mode 100644 gcc/testsuite/c-c++-common/Winit-self2.c > > diff --git a/gcc/c-family/c-gimplify.cc b/gcc/c-family/c-gimplify.cc > index a6f26c9b0d3..2e011830846 100644 > --- a/gcc/c-family/c-gimplify.cc > +++ b/gcc/c-family/c-gimplify.cc > @@ -712,13 +712,17 @@ c_gimplify_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED, > /* This is handled mostly by gimplify.cc, but we have to deal with > not warning about int x = x; as it is a GCC extension to turn off > this warning but only if warn_init_self is zero. */ > - if (VAR_P (DECL_EXPR_DECL (*expr_p)) > - && !DECL_EXTERNAL (DECL_EXPR_DECL (*expr_p)) > - && !TREE_STATIC (DECL_EXPR_DECL (*expr_p)) > - && (DECL_INITIAL (DECL_EXPR_DECL (*expr_p)) == DECL_EXPR_DECL (*expr_p)) > - && !warn_init_self) > - suppress_warning (DECL_EXPR_DECL (*expr_p), OPT_Winit_self); > - break; > + { > + tree &decl = DECL_EXPR_DECL (*expr_p); > + if (VAR_P (decl) > + && !DECL_EXTERNAL (decl) > + && !TREE_STATIC (decl) > + && (DECL_INITIAL (decl) > + && tree_strip_nop_conversions (DECL_INITIAL (decl)) == decl) > + && !warn_init_self) > + suppress_warning (decl, OPT_Winit_self); > + break; > + } > > case PREINCREMENT_EXPR: > case PREDECREMENT_EXPR: > diff --git a/gcc/testsuite/c-c++-common/Winit-self1.c b/gcc/testsuite/c-c++-common/Winit-self1.c > new file mode 100644 > index 00000000000..2a1a755fc71 > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/Winit-self1.c > @@ -0,0 +1,32 @@ > +/* PR middle-end/102633 */ > +/* { dg-do compile } */ > +/* { dg-options "-Wuninitialized -Wno-init-self" } */ > + > +int > +fn1 (void) > +{ > + int i = i; > + return i; > +} > + > +int > +fn2 () > +{ > + const int j = j; > + return j; > +} > + > +int > +fn3 () > +{ > + /* ??? Do we want this warning in C++? Probably not with -Wno-init-self. */ > + volatile int k = k; /* { dg-warning "used uninitialized" "" { target c++ } } */ > + return k; > +} > + > +int > +fn4 () > +{ > + const volatile int l = l; /* { dg-warning "used uninitialized" "" { target c++ } } */ > + return l; > +} > diff --git a/gcc/testsuite/c-c++-common/Winit-self2.c b/gcc/testsuite/c-c++-common/Winit-self2.c > new file mode 100644 > index 00000000000..13aa9efdf26 > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/Winit-self2.c > @@ -0,0 +1,31 @@ > +/* PR middle-end/102633 */ > +/* { dg-do compile } */ > +/* { dg-options "-Wuninitialized -Winit-self" } */ > + > +int > +fn1 (void) > +{ > + int i = i; /* { dg-warning "used uninitialized" } */ > + return i; > +} > + > +int > +fn2 () > +{ > + const int j = j; /* { dg-warning "used uninitialized" } */ > + return j; > +} > + > +int > +fn3 () > +{ > + volatile int k = k; /* { dg-warning "used uninitialized" } */ > + return k; > +} > + > +int > +fn4 () > +{ > + const volatile int l = l; /* { dg-warning "used uninitialized" } */ > + return l; > +} > > base-commit: 600956c81c784f4a0cc9d10f6e03e01847afd961