]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix ICE with nullptr comparison (GCC 11) [PR101592]
authorMarek Polacek <polacek@redhat.com>
Wed, 1 Sep 2021 20:47:44 +0000 (16:47 -0400)
committerMarek Polacek <polacek@redhat.com>
Wed, 1 Sep 2021 21:15:57 +0000 (17:15 -0400)
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.

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
gcc/testsuite/g++.dg/warn/Wlogical-op-3.C [new file with mode: 0644]

index 39f120db38c61495337ee266e59a8ca3807c5539..a1d08c740258d5eff9b59fd23403270c280ec171 100644 (file)
@@ -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 (file)
index 0000000..4b0bc22
--- /dev/null
@@ -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;
+}