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 ESMTP id 16ACE385B805 for ; Thu, 22 Jul 2021 13:37:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 16ACE385B805 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-416-C_nJG0ciMQK4DKXKeDuhlw-1; Thu, 22 Jul 2021 09:37:00 -0400 X-MC-Unique: C_nJG0ciMQK4DKXKeDuhlw-1 Received: by mail-wr1-f70.google.com with SMTP id 5-20020a0560001565b029013fe432d176so2456079wrz.23 for ; Thu, 22 Jul 2021 06:37:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YUSiOmzMANBm7L3ED5Jdwe4uoMRjWGBqDJlAEo25Yz4=; b=OQWu0KEGBdlhqutzwSyTOfsaMPKg/KrSri7ovY8jfTd8gDcqb6UEHyiu4Izsq6G1x9 zVycH1T/OITaWqyusfyZuL1C77CA53HogH+owjzxUgKSOsGsjCT4bGL2lQ5Qhzqj43Lu E/Qd5IF1/vRu1icPseH53M4/mAzb9phLZJ8r2o1QWIgjrB+I3of5lDZ6KFJwPCXxYBpc KF4ZV4v2RpI3wk9ai8cxp9e/yox2tQICRTsukKDvuL3G50L/2U/apRB9TnsNfmqg9Cfe JYLXQN0qoCDQhKE3DAHWH6wI8D8bBIOfbA/ifBErAX2io3ewAk49kg2StesOWP2rvw95 UyjA== X-Gm-Message-State: AOAM530wHCKGG5U5GGhC0eUG3AZYFUU2c7wKCAkcIa56Ll64IjrdNshQ TPZsa7o5O2NodrwSv5ekGACV4pf98mmLfrNEjAKdjclY/JrAqXQARrWz7Kxd9T2huhjvtWGJZpQ JNenKSmTSYRH5PtzovBkQIbAdv+DVkTA= X-Received: by 2002:adf:e7c6:: with SMTP id e6mr48414086wrn.221.1626961019124; Thu, 22 Jul 2021 06:36:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMYgSVSxhM0Yf5diTinSD491yuWGlcHo3A/uo+Zxhcc+bc1Zrijv2O4bZv47Xf+JhanBUICltl1uOZ2iIW3G0= X-Received: by 2002:adf:e7c6:: with SMTP id e6mr48414065wrn.221.1626961018906; Thu, 22 Jul 2021 06:36:58 -0700 (PDT) MIME-Version: 1.0 References: <2a9e7039-b23b-b0d6-c34f-56a1957df591@redhat.com> In-Reply-To: From: Jonathan Wakely Date: Thu, 22 Jul 2021 14:36:47 +0100 Message-ID: Subject: Re: More aggressive GCC 12 -Wmaybe-uninitialized when using To: Stephan Bergmann Cc: gcc Mailing List , "libstdc++" , gcc Patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="00000000000098987105c7b661c2" X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Jul 2021 13:37:08 -0000 --00000000000098987105c7b661c2 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 22 Jul 2021 at 11:03, Jonathan Wakely wrote: > > On Thu, 22 Jul 2021 at 10:23, Stephan Bergmann via Libstdc++ > wrote: > > > > Compared to GCC 11 (at least gcc-c++-11.1.1-3.fc34.x86_64), recent GCC > > 12 trunk emits two "unhelpful" -Wmaybe-uninitialized for > > > > > $ cat test.cc > > > #include > > > using fn =3D std::function; > > > fn f(fn x) { > > > fn a; > > > a =3D x; > > > return x; > > > } > > > > > $ ~/gcc/trunk/inst/bin/g++ -c -Wmaybe-uninitialized -O2 test.cc > > > In file included from ~/gcc/trunk/inst/include/c++/12.0.0/bits/stl_fu= nction.h:60, > > > from ~/gcc/trunk/inst/include/c++/12.0.0/functional:= 49, > > > from test.cc:1: > > > In function =E2=80=98std::_Require >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std:= :swap(_Tp&, _Tp&) [with _Tp =3D void (*)(const std::_Any_data&)]=E2=80=99, > > > inlined from =E2=80=98void std::function<_Res(_ArgTypes ...)>::sw= ap(std::function<_Res(_ArgTypes ...)>&) [with _Res =3D void; _ArgTypes =3D = {}]=E2=80=99 at ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h:529= :11, > > > inlined from =E2=80=98std::function<_Res(_ArgTypes ...)>& std::fu= nction<_Res(_ArgTypes ...)>::operator=3D(const std::function<_Res(_ArgTypes= ...)>&) [with _Res =3D void; _ArgTypes =3D {}]=E2=80=99 at ~/gcc/trunk/ins= t/include/c++/12.0.0/bits/std_function.h:442:20, > > > inlined from =E2=80=98fn f(fn)=E2=80=99 at test.cc:5:9: > > > ~/gcc/trunk/inst/include/c++/12.0.0/bits/move.h:204:11: warning: =E2= =80=98.std::function::_M_invoker=E2=80=99 may be used unin= itialized [-Wmaybe-uninitialized] > > > 204 | _Tp __tmp =3D _GLIBCXX_MOVE(__a); > > > | ^~~~~ > > > In file included from ~/gcc/trunk/inst/include/c++/12.0.0/functional:= 59, > > > from test.cc:1: > > > ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h: In function = =E2=80=98fn f(fn)=E2=80=99: > > > ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h:442:9: note: = =E2=80=98=E2=80=99 declared here > > > 442 | function(__x).swap(*this); > > > | ^~~~~~~~~~~~~ > > > In file included from ~/gcc/trunk/inst/include/c++/12.0.0/bits/stl_fu= nction.h:60, > > > from ~/gcc/trunk/inst/include/c++/12.0.0/functional:= 49, > > > from test.cc:1: > > > In function =E2=80=98std::_Require >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std:= :swap(_Tp&, _Tp&) [with _Tp =3D std::_Any_data]=E2=80=99, > > > inlined from =E2=80=98void std::function<_Res(_ArgTypes ...)>::sw= ap(std::function<_Res(_ArgTypes ...)>&) [with _Res =3D void; _ArgTypes =3D = {}]=E2=80=99 at ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h:527= :11, > > > inlined from =E2=80=98std::function<_Res(_ArgTypes ...)>& std::fu= nction<_Res(_ArgTypes ...)>::operator=3D(const std::function<_Res(_ArgTypes= ...)>&) [with _Res =3D void; _ArgTypes =3D {}]=E2=80=99 at ~/gcc/trunk/ins= t/include/c++/12.0.0/bits/std_function.h:442:20, > > > inlined from =E2=80=98fn f(fn)=E2=80=99 at test.cc:5:9: > > > ~/gcc/trunk/inst/include/c++/12.0.0/bits/move.h:204:11: warning: =E2= =80=98*(std::_Any_data*)((char*)& + offsetof(std::function, std::f= unction::))=E2=80=99 may be used uninitialized [-Wmaybe-un= initialized] > > > 204 | _Tp __tmp =3D _GLIBCXX_MOVE(__a); > > > | ^~~~~ > > > In file included from ~/gcc/trunk/inst/include/c++/12.0.0/functional:= 59, > > > from test.cc:1: > > > ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h: In function = =E2=80=98fn f(fn)=E2=80=99: > > > ~/gcc/trunk/inst/include/c++/12.0.0/bits/std_function.h:442:9: note: = =E2=80=98=E2=80=99 declared here > > > 442 | function(__x).swap(*this); > > > | ^~~~~~~~~~~~~ > > > > This appears to be an issue with more aggressive -Wmaybe-uninitialized > > in GCC 12 vs. 11, rather than an issue with changes to in > > libstdc++ 12 vs. 11, as effectively the same warnings are emitted when = I > > use GCC 12 with libstdc++ 11 with > > > > > $ ~/gcc/trunk/inst/bin/g++ -c -Wmaybe-uninitialized -O2 -nostdinc++ -= isystem /usr/include/c++/11 -isystem /usr/include/c++/11/x86_64-redhat-linu= x test.cc > > > > The warnings may technically be correct, and I'm not sure whether this > > is something that should be addressed in the GCC code emitting the > > warnings or in the libstdc++ implementation. > > > > (I found this when building LibreOffice with recent GCC 12 trunk.) > > The problem is that the _Function_base default constructor is > user-provided, so when std::function value-initializes its base class, > that doesn't do zero-init first. It just calls the default ctor, which > doesn't initialize the _M_fucntor member. I've pushed the attached patch to trunk, after testing on powerpc64le-linux= . --00000000000098987105c7b661c2 Content-Type: text/plain; charset="US-ASCII"; name="patch.txt" Content-Disposition: attachment; filename="patch.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kreyk5g00 Y29tbWl0IGMyMmJjZmQyZjdkYzliYjVhZDM5NDcyMGY0YTYxMjMyN2RjODk4YmEKQXV0aG9yOiBK b25hdGhhbiBXYWtlbHkgPGp3YWtlbHlAcmVkaGF0LmNvbT4KRGF0ZTogICBUaHUgSnVsIDIyIDEx OjU3OjM4IDIwMjEKCiAgICBsaWJzdGRjKys6IEluaXRpYWxpemUgYWxsIHN1Ym9iamVjdHMgb2Yg c3RkOjpmdW5jdGlvbgogICAgCiAgICBUaGUgc3RkOjpmdW5jdGlvbjo6c3dhcCBtZW1iZXIgc3dh cHMgZWFjaCBkYXRhIG1lbWJlciB1bmNvbmRpdGlvbmFsbHksCiAgICByZXN1bHRpbmcgaW4gLVdt YXliZS11bmluaXRpYWxpemVkIHdhcm5pbmdzIGZvciBhIGRlZmF1bHQgY29uc3RydWN0ZWQKICAg IG9iamVjdC4gVGhpcyBoYXBwZW5zIGJlY2F1c2UgdGhlIF9NX2ludm9rZXIgYW5kIF9NX2Z1bmN0 b3IgbWVtYmVycyBhcmUKICAgIG9ubHkgaW5pdGlhbGl6ZWQgaWYgd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