* [PATCH] c++: Fix ICE with nullptr comparison (GCC 11) [PR101592]
@ 2021-09-01 21:18 Marek Polacek
2021-09-01 21:21 ` Jakub Jelinek
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2021-09-01 21:18 UTC (permalink / raw)
To: GCC Patches; +Cc: Jason Merrill, Jakub Jelinek
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 <jakub@redhat.com>
---
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: Fix ICE with nullptr comparison (GCC 11) [PR101592]
2021-09-01 21:18 [PATCH] c++: Fix ICE with nullptr comparison (GCC 11) [PR101592] Marek Polacek
@ 2021-09-01 21:21 ` Jakub Jelinek
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2021-09-01 21:21 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches, Jason Merrill
On Wed, Sep 01, 2021 at 05:18:09PM -0400, Marek Polacek wrote:
> 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.
Ok, thanks.
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-01 21:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01 21:18 [PATCH] c++: Fix ICE with nullptr comparison (GCC 11) [PR101592] Marek Polacek
2021-09-01 21:21 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).