Message ID | ZB7IBe1ytkKihzTP@tucnak |
---|---|
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 4CE5C384F01A for <patchwork@sourceware.org>; Sat, 25 Mar 2023 11:54:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CE5C384F01A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679745270; bh=jPTJ1XPH9dXD1TEjNna97/y3iCyrmj4UDsdwM006gmc=; h=Resent-From:Resent-Date:Resent-To:Date:To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=GD8uoWlx0yl5sRQ2fih0sAiSWLe4HtiKG7I7oVHfJshID1G5T6UF08jX/vQ2Wakzy Ru6O7+W/GnXvryYNCjsTy5L9Fa/zZkPgQNj4kqdCcdIzqameocz88xt+IyfQ5TaOBH CgQd46ZuEVymZFuqd7mmh3flt/EoIBnXFChoowSQ= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 0CF923858D1E for <gcc-patches@gcc.gnu.org>; Sat, 25 Mar 2023 11:54:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0CF923858D1E 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-481-RIJ5tlNXPn-6Urg6PLnqnQ-1; Sat, 25 Mar 2023 07:54:00 -0400 X-MC-Unique: RIJ5tlNXPn-6Urg6PLnqnQ-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 581D78533DF for <gcc-patches@gcc.gnu.org>; Sat, 25 Mar 2023 11:54:00 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1BC48202701E for <gcc-patches@gcc.gnu.org>; Sat, 25 Mar 2023 11:54:00 +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 32PBrqhZ3360549 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for <gcc-patches@gcc.gnu.org>; Sat, 25 Mar 2023 12:53:53 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32PBrqL53360548 for gcc-patches@gcc.gnu.org; Sat, 25 Mar 2023 12:53:52 +0100 Resent-From: Jakub Jelinek <jakub@redhat.com> Resent-Date: Sat, 25 Mar 2023 12:53:52 +0100 Resent-Message-ID: <ZB7g0M1pigQdlt6Q@tucnak> Resent-To: gcc-patches@gcc.gnu.org Date: Sat, 25 Mar 2023 11:10:54 +0100 To: Jason Merrill <jason@redhat.com>, gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Avoid informs without a warning [PR109278] Message-ID: <ZB7IBe1ytkKihzTP@tucnak> 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-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.3 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 <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: Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Jakub Jelinek <jakub@redhat.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
c++: Avoid informs without a warning [PR109278]
|
|
Commit Message
Jakub Jelinek
March 25, 2023, 10:10 a.m. UTC
Hi! On the following testcase we emit notes in maybe_inform_about_fndecl_for_bogus_argument_init despite no warning/error being printed before it. This is for the extended floating point type conversions where pedwarn is used, and complained is used there for 2 different purposes, one is whether an unspecific error should be emitted if we haven't complained otherwise, and one whether maybe_inform_about_fndecl_for_bogus_argument_init should be called. For the 2 pedwarns, currently it sets complained to true regardless of whether pedwarn succeeded, which results in the undesirable notes printed with -w. If complained is initialized to result of pedwarn, we would emit an error later on. So, the following patch makes complained a tristate, the additional error isn't printed if complained != 0, and maybe_inform_about_fndecl_for_bogus_argument_init is called only if complained == 1, so if pedwarn returns false, we can use complained = -1 to tell later code not to emit an error and not to call maybe_inform_about_fndecl_for_bogus_argument_init. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-03-25 Jakub Jelinek <jakub@redhat.com> PR c++/109278 * call.cc (convert_like_internal): If pedwarn for extended float type conversions doesn't report anything, avoid calling maybe_inform_about_fndecl_for_bogus_argument_init. * g++.dg/cpp23/ext-floating15.C: New test. Jakub
Comments
On 3/25/23 06:08, Jakub Jelinek wrote: > Hi! > > On the following testcase we emit notes in > maybe_inform_about_fndecl_for_bogus_argument_init > despite no warning/error being printed before it. > This is for the extended floating point type conversions where pedwarn > is used, and complained is used there for 2 different purposes, > one is whether an unspecific error should be emitted if we haven't > complained otherwise, and one whether > maybe_inform_about_fndecl_for_bogus_argument_init should be called. > For the 2 pedwarns, currently it sets complained to true regardless of > whether pedwarn succeeded, which results in the undesirable notes printed > with -w. If complained is initialized to result of pedwarn, we would > emit an error later on. > > So, the following patch makes complained a tristate, the additional > error isn't printed if complained != 0, and > maybe_inform_about_fndecl_for_bogus_argument_init is called only if > complained == 1, so if pedwarn returns false, we can use complained = -1 > to tell later code not to emit an error and not to call > maybe_inform_about_fndecl_for_bogus_argument_init. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2023-03-25 Jakub Jelinek <jakub@redhat.com> > > PR c++/109278 > * call.cc (convert_like_internal): If pedwarn for extended float > type conversions doesn't report anything, avoid calling > maybe_inform_about_fndecl_for_bogus_argument_init. I think we want the same handling for all the complained = permerror cases as well. > * g++.dg/cpp23/ext-floating15.C: New test. > > --- gcc/cp/call.cc.jj 2023-03-23 15:24:33.074801422 +0100 > +++ gcc/cp/call.cc 2023-03-24 22:29:06.328140170 +0100 > @@ -8296,7 +8296,7 @@ convert_like_internal (conversion *convs > || SCALAR_TYPE_P (totype)) > && convs->kind != ck_base) > { > - bool complained = false; > + int complained = 0; > conversion *t = convs; > > /* Give a helpful error if this is bad because of excess braces. */ > @@ -8328,14 +8328,18 @@ convert_like_internal (conversion *convs > totype)) > { > case 2: > - pedwarn (loc, 0, "converting to %qH from %qI with greater " > - "conversion rank", totype, TREE_TYPE (expr)); > - complained = true; > + if (pedwarn (loc, 0, "converting to %qH from %qI with greater " > + "conversion rank", totype, TREE_TYPE (expr))) > + complained = 1; > + else if (!complained) > + complained = -1; > break; > case 3: > - pedwarn (loc, 0, "converting to %qH from %qI with unordered " > - "conversion ranks", totype, TREE_TYPE (expr)); > - complained = true; > + if (pedwarn (loc, 0, "converting to %qH from %qI with unordered " > + "conversion ranks", totype, TREE_TYPE (expr))) > + complained = 1; > + else if (!complained) > + complained = -1; > break; > default: > break; > @@ -8389,7 +8393,7 @@ convert_like_internal (conversion *convs > "invalid conversion from %qH to %qI", > TREE_TYPE (expr), totype); > } > - if (complained) > + if (complained == 1) > maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum); > > return cp_convert (totype, expr, complain); > --- gcc/testsuite/g++.dg/cpp23/ext-floating15.C.jj 2023-03-24 22:38:40.358890548 +0100 > +++ gcc/testsuite/g++.dg/cpp23/ext-floating15.C 2023-03-24 22:38:18.484204916 +0100 > @@ -0,0 +1,11 @@ > +// PR c++/109278 > +// { dg-do compile { target float128 } } > +// { dg-options "-w" } > + > +void foo (long double); // { dg-bogus "initializing argument 1 of" } > + > +void > +bar (_Float128 x) > +{ > + foo (x); > +} > > Jakub >
On Wed, Mar 29, 2023 at 04:35:15PM -0400, Jason Merrill wrote: > > On the following testcase we emit notes in > > maybe_inform_about_fndecl_for_bogus_argument_init > > despite no warning/error being printed before it. > > This is for the extended floating point type conversions where pedwarn > > is used, and complained is used there for 2 different purposes, > > one is whether an unspecific error should be emitted if we haven't > > complained otherwise, and one whether > > maybe_inform_about_fndecl_for_bogus_argument_init should be called. > > For the 2 pedwarns, currently it sets complained to true regardless of > > whether pedwarn succeeded, which results in the undesirable notes printed > > with -w. If complained is initialized to result of pedwarn, we would > > emit an error later on. > > > > So, the following patch makes complained a tristate, the additional > > error isn't printed if complained != 0, and > > maybe_inform_about_fndecl_for_bogus_argument_init is called only if > > complained == 1, so if pedwarn returns false, we can use complained = -1 > > to tell later code not to emit an error and not to call > > maybe_inform_about_fndecl_for_bogus_argument_init. > > > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > > > 2023-03-25 Jakub Jelinek <jakub@redhat.com> > > > > PR c++/109278 > > * call.cc (convert_like_internal): If pedwarn for extended float > > type conversions doesn't report anything, avoid calling > > maybe_inform_about_fndecl_for_bogus_argument_init. > > I think we want the same handling for all the complained = permerror cases > as well. I think it isn't really needed in those cases. If I have say: int foo (int); int a = foo ({ { 1 } }); int bar (bool); decltype (nullptr) n; int b = bar (n); and compile with -fpermissive -w (which is I think the only way how to get permerror return false), then it will later reach that: if (!complained && expr != error_mark_node) { range_label_for_type_mismatch label (TREE_TYPE (expr), totype); gcc_rich_location richloc (loc, &label); complained = permerror (&richloc, "invalid conversion from %qH to %qI", TREE_TYPE (expr), totype); } if (complained) maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum); in current trunk or complained == 1 in the latter condition with the patch. !complained is true, so it will call permerror, but because of -fpermissive -w neither that permerror will emit anything and will set complained to false, so maybe_inform_about_fndecl_for_bogus_argument_init is not called. If I compile the above just with -fpermissive, it prints the 2 warnings and 2 informs, if without -fpermissive, it prints the 2 errors and 2 informs. If you want, I can add the above snippet as 3 testcases (normal, -fpermissive and -fpermissive -w). Jakub
On 3/29/23 16:57, Jakub Jelinek wrote: > On Wed, Mar 29, 2023 at 04:35:15PM -0400, Jason Merrill wrote: >>> On the following testcase we emit notes in >>> maybe_inform_about_fndecl_for_bogus_argument_init >>> despite no warning/error being printed before it. >>> This is for the extended floating point type conversions where pedwarn >>> is used, and complained is used there for 2 different purposes, >>> one is whether an unspecific error should be emitted if we haven't >>> complained otherwise, and one whether >>> maybe_inform_about_fndecl_for_bogus_argument_init should be called. >>> For the 2 pedwarns, currently it sets complained to true regardless of >>> whether pedwarn succeeded, which results in the undesirable notes printed >>> with -w. If complained is initialized to result of pedwarn, we would >>> emit an error later on. >>> >>> So, the following patch makes complained a tristate, the additional >>> error isn't printed if complained != 0, and >>> maybe_inform_about_fndecl_for_bogus_argument_init is called only if >>> complained == 1, so if pedwarn returns false, we can use complained = -1 >>> to tell later code not to emit an error and not to call >>> maybe_inform_about_fndecl_for_bogus_argument_init. >>> >>> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? >>> >>> 2023-03-25 Jakub Jelinek <jakub@redhat.com> >>> >>> PR c++/109278 >>> * call.cc (convert_like_internal): If pedwarn for extended float >>> type conversions doesn't report anything, avoid calling >>> maybe_inform_about_fndecl_for_bogus_argument_init. >> >> I think we want the same handling for all the complained = permerror cases >> as well. > > I think it isn't really needed in those cases. > If I have say: > int foo (int); > int a = foo ({ { 1 } }); > int bar (bool); > decltype (nullptr) n; > int b = bar (n); > and compile with -fpermissive -w (which is I think the only way how to get > permerror return false), then it will later reach that: > if (!complained && expr != error_mark_node) > { > range_label_for_type_mismatch label (TREE_TYPE (expr), totype); > gcc_rich_location richloc (loc, &label); > complained = permerror (&richloc, > "invalid conversion from %qH to %qI", > TREE_TYPE (expr), totype); > } > if (complained) > maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum); > in current trunk or complained == 1 in the latter condition with the > patch. !complained is true, so it will call permerror, but because > of -fpermissive -w neither that permerror will emit anything and will set > complained to false, so maybe_inform_about_fndecl_for_bogus_argument_init > is not called. If I compile the above just with -fpermissive, it prints > the 2 warnings and 2 informs, if without -fpermissive, it prints the 2 > errors and 2 informs. Ah, makes sense. The patch is OK. > If you want, I can add the above snippet as 3 testcases (normal, > -fpermissive and -fpermissive -w). > > Jakub >
--- gcc/cp/call.cc.jj 2023-03-23 15:24:33.074801422 +0100 +++ gcc/cp/call.cc 2023-03-24 22:29:06.328140170 +0100 @@ -8296,7 +8296,7 @@ convert_like_internal (conversion *convs || SCALAR_TYPE_P (totype)) && convs->kind != ck_base) { - bool complained = false; + int complained = 0; conversion *t = convs; /* Give a helpful error if this is bad because of excess braces. */ @@ -8328,14 +8328,18 @@ convert_like_internal (conversion *convs totype)) { case 2: - pedwarn (loc, 0, "converting to %qH from %qI with greater " - "conversion rank", totype, TREE_TYPE (expr)); - complained = true; + if (pedwarn (loc, 0, "converting to %qH from %qI with greater " + "conversion rank", totype, TREE_TYPE (expr))) + complained = 1; + else if (!complained) + complained = -1; break; case 3: - pedwarn (loc, 0, "converting to %qH from %qI with unordered " - "conversion ranks", totype, TREE_TYPE (expr)); - complained = true; + if (pedwarn (loc, 0, "converting to %qH from %qI with unordered " + "conversion ranks", totype, TREE_TYPE (expr))) + complained = 1; + else if (!complained) + complained = -1; break; default: break; @@ -8389,7 +8393,7 @@ convert_like_internal (conversion *convs "invalid conversion from %qH to %qI", TREE_TYPE (expr), totype); } - if (complained) + if (complained == 1) maybe_inform_about_fndecl_for_bogus_argument_init (fn, argnum); return cp_convert (totype, expr, complain); --- gcc/testsuite/g++.dg/cpp23/ext-floating15.C.jj 2023-03-24 22:38:40.358890548 +0100 +++ gcc/testsuite/g++.dg/cpp23/ext-floating15.C 2023-03-24 22:38:18.484204916 +0100 @@ -0,0 +1,11 @@ +// PR c++/109278 +// { dg-do compile { target float128 } } +// { dg-options "-w" } + +void foo (long double); // { dg-bogus "initializing argument 1 of" } + +void +bar (_Float128 x) +{ + foo (x); +}