aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-01-04 12:16:22 +0100
committerJakub Jelinek <jakub@redhat.com>2023-01-04 12:16:22 +0100
commitebc449119442501c927ede0e83697eaece72223e (patch)
tree229d0671534b2446b2ae1b945a01e99d580c95fd /gcc/testsuite
parent345dffd0d4ebff7e705dfff1a8a72017a167120a (diff)
downloadgcc-ebc449119442501c927ede0e83697eaece72223e.zip
gcc-ebc449119442501c927ede0e83697eaece72223e.tar.gz
gcc-ebc449119442501c927ede0e83697eaece72223e.tar.bz2
vrp: Handle pointers in maybe_set_nonzero_bits [PR108253]
maybe_set_nonzero_bits calls set_nonzero_bits which asserts that var doesn't have pointer type. While we could punt for those cases, I think we can handle at least some easy cases. Earlier in maybe_set_nonzero_bits we've checked this is on (var & cst) == 0 edge and the other edge is __builtin_unreachable, so if cst is say 3 as in the testcase, we want to turn it into 4 byte alignment of the pointer. 2023-01-04 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/108253 * tree-vrp.cc (maybe_set_nonzero_bits): Handle var with pointer types. * g++.dg/opt/pr108253.C: New test.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/g++.dg/opt/pr108253.C48
1 files changed, 48 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/opt/pr108253.C b/gcc/testsuite/g++.dg/opt/pr108253.C
new file mode 100644
index 0000000..0409121
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr108253.C
@@ -0,0 +1,48 @@
+// PR tree-optimization/108253
+// { dg-do compile { target c++11 } }
+// { dg-options "-O2" }
+
+struct S
+{
+ int *s;
+ S () : s (new int) {}
+ S (const S &r) noexcept : s (r.s) { __atomic_fetch_add (r.s, 1, 4); }
+};
+struct T
+{
+ explicit T (const S &x) : t (x) {}
+ const S t;
+};
+struct U
+{
+ operator int () const { new T (u); return 0; }
+ S u;
+};
+bool foo (int matcher);
+unsigned long bar (unsigned long pos, unsigned long end_pos);
+struct V
+{
+ alignas (4) char v[4];
+};
+struct W
+{
+ void baz ()
+ {
+ if (!w) __builtin_abort ();
+ if (reinterpret_cast <__UINTPTR_TYPE__> (w->v) % 4 != 0) __builtin_abort ();
+ __builtin_unreachable ();
+ }
+ [[gnu::noinline]] void qux (unsigned long) { if (!w) bar (0, x); }
+ V *w = nullptr;
+ unsigned x = 0;
+};
+
+void
+test ()
+{
+ W w;
+ U t;
+ if (!foo (t))
+ w.baz ();
+ w.qux (0);
+}