From patchwork Fri Jan 13 00:32:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 42883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2876wrt; Thu, 12 Jan 2023 16:33:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXs0rNlY6b4YS1yZCrZccH7wHGj276rR0Sog7KFWmkm3A3oRB4b9YQfV+KEseZyiX9uUBUl9 X-Received: by 2002:a17:906:3544:b0:84d:3fa7:12e5 with SMTP id s4-20020a170906354400b0084d3fa712e5mr14483593eja.32.1673570012346; Thu, 12 Jan 2023 16:33:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673570012; cv=none; d=google.com; s=arc-20160816; b=aXPy/KsyiDYpeEsu507gSyDRLxGB9jOlRRnZgyNzSh/1s8tOXPACxuV96CKpHllNbw yoqhioJex/auShsNEqVydREf7VRhlRZP00ZW6uJXUzI3DQtslpuNzD6ACTkbPwKm+n7g nm4ezB/MLRSrjFmYoq+I5srXo1ur2TUeu+yv8oSozLlH5EG3+/cHaU7aFmCreYysQ6dm L+kJB7Q2UCL/dscX8xALn+zoaLsxzabhcYkpvDH1egPCc8ZYL63Ph67eRuIWtV4ID4dE vDFS6rVcag8vKPnuoSnu5OiJGhfk10/1kyYutx8IuXoZpbphXYa/MGns1Y/VbGKhW5xo G/4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=TNdOLN/9l/9smaEXzzDotBsqVD7edCGoSt3XF1SaWss=; b=J5E/R/70K36nXZ9WrmTxlk4Exuf3/hSJ406ba/eIUABth17Xi/E/LlmXS8Tu21RtoR fyjB7xuLJ751e7/t6hVXcmuQOAn0diXGNe17rMX9r4HrwfW/csDRtNTNX5pB2xflaql4 pBfK/+rhi8qfsdbpNApfbAdK18qnIk6u6UslJRWn0vfZ7S/w6Yw/At7Ose9iXdUJ/Ogq p1CxCeS2/I0WsNtXkXVybJraoHjl8zIbQKq+1yKM6E+VXAmkJKNb6it1175QftSmIEui drBzmFLLEjyYocacmPMXkUW+z0GpXjl7VmO91UhcAG3KEPQUtAisSA8Jp1W042VFqcs9 1LwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uJLwqI3P; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gt37-20020a1709072da500b0084d34979415si18403053ejc.326.2023.01.12.16.33.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 16:33:32 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uJLwqI3P; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 426F23860744 for ; Fri, 13 Jan 2023 00:33:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 426F23860744 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673570011; bh=TNdOLN/9l/9smaEXzzDotBsqVD7edCGoSt3XF1SaWss=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=uJLwqI3POEsYApDlllDhT1KmIHr/WvfGBQNeVYBj2Tvcl7n2ah1qXR2q7lVhsqEuD vtkQEM1gl2bK3bmZcc0gZ00lZ+RhyWoM+qykvqNRKQqUo2M5R5C2m0QD2ruRuGrmSC Geat13R6mikCoPzrI3bepNSiwUGf8dUFrwh36OQI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 258EB3858418 for ; Fri, 13 Jan 2023 00:32:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 258EB3858418 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-570-kwrY7gg0NpGCHbWD5E-_yQ-1; Thu, 12 Jan 2023 19:32:43 -0500 X-MC-Unique: kwrY7gg0NpGCHbWD5E-_yQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6ADA0183B3C3; Fri, 13 Jan 2023 00:32:43 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0588E2026D68; Fri, 13 Jan 2023 00:32:42 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 30D0Wecm1350315 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 13 Jan 2023 01:32:40 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30D0WdsX1350314; Fri, 13 Jan 2023 01:32:39 +0100 Date: Fri, 13 Jan 2023 01:32:38 +0100 To: Jason Merrill , "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c, c++: Allow ignoring -Winit-self through pragmas [PR105593] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754865349326594427?= X-GMAIL-MSGID: =?utf-8?q?1754865349326594427?= Hi! As mentioned in the PR, various x86 intrinsics need to return an uninitialized vector. Currently they use self initialization to avoid -Wuninitialized warnings, which works fine in C, but doesn't work in C++ where -Winit-self is enabled in -Wall. We don't have an attribute to mark a variable as knowingly uninitialized (the uninitialized attribute exists but means something else, only in the -ftrivial-auto-var-init context), and trying to suppress either -Wuninitialized or -Winit-self inside of the _mm_undefined_ps etc. intrinsic definitions doesn't work, one needs to currently disable through pragmas -Wuninitialized warning at the point where _mm_undefined_ps etc. result is actually used, but that goes against the intent of those intrinsics. The -Winit-self warning option actually doesn't do any warning, all we do is record a suppression for -Winit-self if !warn_init_self on the decl definition and later look that up in uninit pass. The following patch changes those !warn_init_self tests which are true only based on the command line option setting, not based on GCC diagnostic pragma overrides to !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self) such that it takes them into account. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Will post incremental patch for the intrinsic headers. 2023-01-13 Jakub Jelinek PR c++/105593 gcc/c/ * c-parser.cc (c_parser_initializer): Check warning_enabled_at at the DECL_SOURCE_LOCATION (decl) for OPT_Winit_self instead of warn_init_self. gcc/cp/ * decl.cc (cp_finish_decl): Check warning_enabled_at at the DECL_SOURCE_LOCATION (decl) for OPT_Winit_self instead of warn_init_self. gcc/testsuite/ * c-c++-common/Winit-self3.c: New test. * c-c++-common/Winit-self4.c: New test. * c-c++-common/Winit-self5.c: New test. Jakub --- gcc/c/c-parser.cc.jj 2023-01-11 22:18:25.560492345 +0100 +++ gcc/c/c-parser.cc 2023-01-12 15:30:10.460233783 +0100 @@ -5701,7 +5701,7 @@ c_parser_initializer (c_parser *parser, && !DECL_EXTERNAL (decl) && !TREE_STATIC (decl) && ret.value == decl - && !warn_init_self) + && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self)) suppress_warning (decl, OPT_Winit_self); if (TREE_CODE (ret.value) != STRING_CST && (TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR --- gcc/cp/decl.cc.jj 2023-01-04 18:42:24.597997547 +0100 +++ gcc/cp/decl.cc 2023-01-12 15:26:01.257817526 +0100 @@ -8407,7 +8407,7 @@ cp_finish_decl (tree decl, tree init, bo if (!DECL_EXTERNAL (decl) && !TREE_STATIC (decl) && decl == tree_strip_any_location_wrapper (init) - && !warn_init_self) + && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self)) suppress_warning (decl, OPT_Winit_self); } --- gcc/testsuite/c-c++-common/Winit-self3.c.jj 2023-01-12 15:49:56.759172518 +0100 +++ gcc/testsuite/c-c++-common/Winit-self3.c 2023-01-12 15:50:51.512384963 +0100 @@ -0,0 +1,36 @@ +/* PR c++/105593 */ +/* { dg-do compile } */ +/* { dg-options "-W -Wall" } */ + +void bar (int); + +static inline int +baz (void) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Winit-self" + int u = u; /* { dg-bogus "'u' is used uninitialized" } */ +#pragma GCC diagnostic pop + return u; +} + +void +foo (void) +{ + int u = baz (); + bar (u); +} + +static inline int +qux (void) +{ + int u = u; /* { dg-warning "'u' is used uninitialized" "" { target c++ } } */ + return u; /* { dg-message "'u' was declared here" "" { target c++ } .-1 } */ +} + +void +corge (void) +{ + int u = qux (); + bar (u); +} --- gcc/testsuite/c-c++-common/Winit-self4.c.jj 2023-01-12 15:50:15.233906776 +0100 +++ gcc/testsuite/c-c++-common/Winit-self4.c 2023-01-12 15:50:42.445515372 +0100 @@ -0,0 +1,36 @@ +/* PR c++/105593 */ +/* { dg-do compile } */ +/* { dg-options "-W -Wall -Winit-self" } */ + +void bar (int); + +static inline int +baz (void) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Winit-self" + int u = u; /* { dg-bogus "'u' is used uninitialized" } */ +#pragma GCC diagnostic pop + return u; +} + +void +foo (void) +{ + int u = baz (); + bar (u); +} + +static inline int +qux (void) +{ + int u = u; /* { dg-warning "'u' is used uninitialized" } */ + return u; /* { dg-message "'u' was declared here" "" { target *-*-* } .-1 } */ +} + +void +corge (void) +{ + int u = qux (); + bar (u); +} --- gcc/testsuite/c-c++-common/Winit-self5.c.jj 2023-01-12 15:51:01.045247847 +0100 +++ gcc/testsuite/c-c++-common/Winit-self5.c 2023-01-12 15:51:12.929076923 +0100 @@ -0,0 +1,36 @@ +/* PR c++/105593 */ +/* { dg-do compile } */ +/* { dg-options "-W -Wall -Wno-init-self" } */ + +void bar (int); + +static inline int +baz (void) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Winit-self" + int u = u; /* { dg-bogus "'u' is used uninitialized" } */ +#pragma GCC diagnostic pop + return u; +} + +void +foo (void) +{ + int u = baz (); + bar (u); +} + +static inline int +qux (void) +{ + int u = u; /* { dg-bogus "'u' is used uninitialized" } */ + return u; +} + +void +corge (void) +{ + int u = qux (); + bar (u); +}