Message ID | Y1juZu+TsIub4jZj@tucnak |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp137773wru; Wed, 26 Oct 2022 01:54:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5XLpDtjbX+H3b8kE4JvTA/YNDC44W+b4ulWZHdJAPzg57i7oUL+gFqth3ES335letAyQHp X-Received: by 2002:a17:907:3e11:b0:78d:9918:217f with SMTP id hp17-20020a1709073e1100b0078d9918217fmr35406131ejc.742.1666774493141; Wed, 26 Oct 2022 01:54:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666774493; cv=none; d=google.com; s=arc-20160816; b=z09YpqJIZRwwqsTdq2U8DiHMXqytlPI+uvHDpU3pJqkYreCjoZWOeLGPNXFtE3IM2g 0DG+5i1vMousur4oRcgl0gIZI+PeXEQ+C/vwbOPQWnEiVnKQpkYCxp0q6bgmbBMAcljw wbHwQE6SW5CC1UR4fLKi157e4qcbef6T58QeEP40qTTpWVGH88ganapUZTcqIHSaPm1F K3C+2L3h8KJaYNzVnbPDK5aVLQ73OZJ5XQuOBnK2XkVzsUAO/guV8a2Fe4UVT8Ro0gTb ZQc3Jhli5q3Qb0NhwYn344lcfAE5NZctiyiy+OIOBggQlhB4TjVSDAyH8cvuTQTYyIAK pddQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=uScUFzvFoJp63QLSJmlbySJ9O2fJX6EtC5teVdi9Y2I=; b=ypHlt5WtC2ftu+5h72dk+93rPNU59xwLu9XW73dCke0JD8g8znGgpvi3SAiq3KnH9e tyMMBFANaCqDAU35yzgCpZFATTjBxlqvBFOzbtQZLXYXJU+tXXO1Js5Crr0wBqddJAyu ZxWT9PFf3iY3r6LloKB4Xo5svLZrBRqKeg0UJgue5rDgaLQjhzoQD+bOZ+sO3omoiDDw 9CXWwnJ0DOLlyPawfQJ9Xaukfd4CEAfFd+ur4LmxiZq35Ogp2iZN35ACuEmu52r6aSda U+QiVIXz2CH/WIJqMYu6AXiRxnSzZ8aavh1m3h4XSMVhmE5e0Fa5ZGjtzyuvBftipjaN qEsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=v5WcIMio; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qb15-20020a1709077e8f00b0078198611a45si4999228ejc.980.2022.10.26.01.54.52 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 01:54:53 -0700 (PDT) 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=v5WcIMio; 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 90DDD383038E for <ouuuleilei@gmail.com>; Wed, 26 Oct 2022 08:41:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 90DDD383038E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666773706; bh=uScUFzvFoJp63QLSJmlbySJ9O2fJX6EtC5teVdi9Y2I=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=v5WcIMioMBrDEwph/U5sewZJPVVi3yEMyQyHIyMFox/MQFN2qNOZxkUleXk9NnZue h2bH6jkkAjPOw/PA9m3f0igEQ6PMqG+sOBzOe7Ct8eDGTVOO5vCL+mT0VfQxZl8l13 BXFH9OPsU5PqqtmYD7wBfBgKdU70vpYXckKtn3lE= 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 7BD4838983BC for <gcc-patches@gcc.gnu.org>; Wed, 26 Oct 2022 08:23:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7BD4838983BC Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-263-0qQenB3jOriLwZuO3ZVEkg-1; Wed, 26 Oct 2022 04:23:06 -0400 X-MC-Unique: 0qQenB3jOriLwZuO3ZVEkg-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 7812F29AB448 for <gcc-patches@gcc.gnu.org>; Wed, 26 Oct 2022 08:23:05 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.252]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3971D2027064; Wed, 26 Oct 2022 08:23:05 +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 29Q8N24U2560643 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 26 Oct 2022 10:23:03 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 29Q8N2eM2560642; Wed, 26 Oct 2022 10:23:02 +0200 Date: Wed, 26 Oct 2022 10:23:02 +0200 To: Jason Merrill <jason@redhat.com> Subject: [PATCH] c++: Fix excess precision related ICE on invalid binop [PR107382, PR107383] Message-ID: <Y1juZu+TsIub4jZj@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=-4.2 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> Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747739730570756191?= X-GMAIL-MSGID: =?utf-8?q?1747739730570756191?= |
Series |
c++: Fix excess precision related ICE on invalid binop [PR107382, PR107383]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Jakub Jelinek
Oct. 26, 2022, 8:23 a.m. UTC
Hi! The following tests ICE in the gcc_assert (common); in cp_build_binary_op. I've missed that while for * common is set always, while for +, - and / it is in some cases not. If it is not, then if (!result_type && arithmetic_types_p && (shorten || common || short_compare)) condition is false, then the following if (may_need_excess_precision && (orig_type0 != type0 || orig_type1 != type1) && build_type == NULL_TREE) would fail the assertion there and if there wouldn't be excess precision, if (code == SPACESHIP_EXPR) would be false (for SPACESHIP_EXPR we always have build_type set like for other comparisons) and then trigger if (!result_type) { if (complain & tf_error) { binary_op_rich_location richloc (location, orig_op0, orig_op1, true); error_at (&richloc, "invalid operands of types %qT and %qT to binary %qO", TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), code); } return error_mark_node; } So, if result_type is NULL, we don't really need to compute semantic_result_type because nothing will use it anyway and can get fall through into the error/return error_mark_node; case. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-10-26 Jakub Jelinek <jakub@redhat.com> PR c++/107382 PR c++/107383 * typeck.cc (cp_build_binary_op): Don't compute semantic_result_type if result_type is NULL. * g++.dg/diagnostic/bad-binary-ops2.C: New test. Jakub
Comments
On 10/26/22 04:23, Jakub Jelinek wrote: > Hi! > > The following tests ICE in the gcc_assert (common); in cp_build_binary_op. > I've missed that while for * common is set always, while for +, - and / > it is in some cases not. > If it is not, then > if (!result_type > && arithmetic_types_p > && (shorten || common || short_compare)) > condition is false, then the following > if (may_need_excess_precision > && (orig_type0 != type0 || orig_type1 != type1) > && build_type == NULL_TREE) > would fail the assertion there and if there wouldn't be excess precision, > if (code == SPACESHIP_EXPR) > would be false (for SPACESHIP_EXPR we always have build_type set like for > other comparisons) and then trigger > if (!result_type) > { > if (complain & tf_error) > { > binary_op_rich_location richloc (location, > orig_op0, orig_op1, true); > error_at (&richloc, > "invalid operands of types %qT and %qT to binary %qO", > TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), code); > } > return error_mark_node; > } > So, if result_type is NULL, we don't really need to compute > semantic_result_type because nothing will use it anyway and can get > fall through into the error/return error_mark_node; case. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. > 2022-10-26 Jakub Jelinek <jakub@redhat.com> > > PR c++/107382 > PR c++/107383 > * typeck.cc (cp_build_binary_op): Don't compute semantic_result_type > if result_type is NULL. > > * g++.dg/diagnostic/bad-binary-ops2.C: New test. > > --- gcc/cp/typeck.cc.jj 2022-10-25 10:37:28.008533040 +0200 > +++ gcc/cp/typeck.cc 2022-10-25 19:18:20.951846806 +0200 > @@ -6179,7 +6179,8 @@ cp_build_binary_op (const op_location_t > } > if (may_need_excess_precision > && (orig_type0 != type0 || orig_type1 != type1) > - && build_type == NULL_TREE) > + && build_type == NULL_TREE > + && result_type) > { > gcc_assert (common); > semantic_result_type = cp_common_type (orig_type0, orig_type1); > --- gcc/testsuite/g++.dg/diagnostic/bad-binary-ops2.C.jj 2022-10-25 19:49:49.190198057 +0200 > +++ gcc/testsuite/g++.dg/diagnostic/bad-binary-ops2.C 2022-10-25 20:10:35.266264891 +0200 > @@ -0,0 +1,26 @@ > +// PR c++/107382 > +// PR c++/107383 > +// { dg-do compile } > +// { dg-options "-O2 -fexcess-precision=standard" } > + > +void > +foo () > +{ > + float t[2] = { 1, 2 }; > + int const *s = 0; > + t[1] / s; // { dg-error "invalid operands of types 'float' and 'const int\\\*' to binary 'operator/'" } > +} > + > +void > +bar () > +{ > + float t[2] = { 1, 2 }; > + int const *s[2] = { 0, 0 }; > + t[1] / s[0]; // { dg-error "invalid operands of types 'float' and 'const int\\\*' to binary 'operator/'" } > +} > + > +void > +baz (float a, int* b) > +{ > + a -= b; // { dg-error "invalid operands of types 'float' and 'int\\\*' to binary 'operator-'" } > +} > > Jakub >
--- gcc/cp/typeck.cc.jj 2022-10-25 10:37:28.008533040 +0200 +++ gcc/cp/typeck.cc 2022-10-25 19:18:20.951846806 +0200 @@ -6179,7 +6179,8 @@ cp_build_binary_op (const op_location_t } if (may_need_excess_precision && (orig_type0 != type0 || orig_type1 != type1) - && build_type == NULL_TREE) + && build_type == NULL_TREE + && result_type) { gcc_assert (common); semantic_result_type = cp_common_type (orig_type0, orig_type1); --- gcc/testsuite/g++.dg/diagnostic/bad-binary-ops2.C.jj 2022-10-25 19:49:49.190198057 +0200 +++ gcc/testsuite/g++.dg/diagnostic/bad-binary-ops2.C 2022-10-25 20:10:35.266264891 +0200 @@ -0,0 +1,26 @@ +// PR c++/107382 +// PR c++/107383 +// { dg-do compile } +// { dg-options "-O2 -fexcess-precision=standard" } + +void +foo () +{ + float t[2] = { 1, 2 }; + int const *s = 0; + t[1] / s; // { dg-error "invalid operands of types 'float' and 'const int\\\*' to binary 'operator/'" } +} + +void +bar () +{ + float t[2] = { 1, 2 }; + int const *s[2] = { 0, 0 }; + t[1] / s[0]; // { dg-error "invalid operands of types 'float' and 'const int\\\*' to binary 'operator/'" } +} + +void +baz (float a, int* b) +{ + a -= b; // { dg-error "invalid operands of types 'float' and 'int\\\*' to binary 'operator-'" } +}