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 9BD2A3857C5F for ; Wed, 1 Sep 2021 21:18:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9BD2A3857C5F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-168-mLZ40hBEN0OAP95sPFAxjg-1; Wed, 01 Sep 2021 17:18:16 -0400 X-MC-Unique: mLZ40hBEN0OAP95sPFAxjg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7A9098799EB for ; Wed, 1 Sep 2021 21:18:15 +0000 (UTC) Received: from pdp-11.hsd1.ma.comcast.net (unknown [10.22.34.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1251F6B544; Wed, 1 Sep 2021 21:18:14 +0000 (UTC) From: Marek Polacek To: GCC Patches Cc: Jason Merrill , Jakub Jelinek Subject: [PATCH] c++: Fix ICE with nullptr comparison (GCC 11) [PR101592] Date: Wed, 1 Sep 2021 17:18:09 -0400 Message-Id: <20210901211809.94066-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-14.3 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Wed, 01 Sep 2021 21:18:18 -0000 On trunk, PR101592 was fixed by r12-2537, but that change shouldn't be backported to GCC 11. In the PR Jakub suggested this fix, so here it is, after the usual testing. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for 11? PR c++/101592 gcc/ChangeLog: * fold-const.c (make_range_step): Return NULL_TREE for NULLPTR_TYPE. gcc/testsuite/ChangeLog: * g++.dg/warn/Wlogical-op-3.C: New test. Co-authored-by: Jakub Jelinek --- gcc/fold-const.c | 3 ++- gcc/testsuite/g++.dg/warn/Wlogical-op-3.C | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wlogical-op-3.C diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 39f120db38c..a1d08c74025 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -5003,7 +5003,8 @@ make_range_step (location_t loc, enum tree_code code, tree arg0, tree arg1, being not equal to zero; "out" is leaving it alone. */ if (low == NULL_TREE || high == NULL_TREE || ! integer_zerop (low) || ! integer_zerop (high) - || TREE_CODE (arg1) != INTEGER_CST) + || TREE_CODE (arg1) != INTEGER_CST + || TREE_CODE (arg0_type) == NULLPTR_TYPE) return NULL_TREE; switch (code) diff --git a/gcc/testsuite/g++.dg/warn/Wlogical-op-3.C b/gcc/testsuite/g++.dg/warn/Wlogical-op-3.C new file mode 100644 index 00000000000..4b0bc22af4d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wlogical-op-3.C @@ -0,0 +1,12 @@ +// PR c++/101592 +// { dg-do compile { target c++11 } } +// { dg-options "-O2 -Wlogical-op" } + +decltype(nullptr) foo (); + +bool +bar () +{ + return foo () > nullptr + || foo () < nullptr; +} base-commit: 051040f0642cfd002d31f655a70aef50e6f44d25 -- 2.31.1