aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2016-03-08 21:05:21 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2016-03-08 21:05:21 +0100
commitd259b234a301aa5c06ca78262ae814b3d8d0f1a5 (patch)
tree897ce2c797917765609e86f7a7499d60e9903ecf /gcc/testsuite
parent56aae4b7c0d088f2b1056b41ba1f502d93550020 (diff)
downloadgcc-d259b234a301aa5c06ca78262ae814b3d8d0f1a5.zip
gcc-d259b234a301aa5c06ca78262ae814b3d8d0f1a5.tar.gz
gcc-d259b234a301aa5c06ca78262ae814b3d8d0f1a5.tar.bz2
re PR sanitizer/70135 (-fsanitize=undefined causes static_assert to fail)
PR c++/70135 * constexpr.c (cxx_eval_loop_expr): Forget saved values of SAVE_EXPRs even after the last iteration of the loop. * g++.dg/cpp1y/constexpr-loop4.C: New test. * g++.dg/ubsan/pr70135.C: New test. From-SVN: r234064
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/constexpr-loop4.C27
-rw-r--r--gcc/testsuite/g++.dg/ubsan/pr70135.C36
3 files changed, 67 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 28229ee..5149414 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2016-03-08 Jakub Jelinek <jakub@redhat.com>
+ PR c++/70135
+ * g++.dg/cpp1y/constexpr-loop4.C: New test.
+ * g++.dg/ubsan/pr70135.C: New test.
+
PR target/70110
* gcc.dg/pr70110.c: New test.
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-loop4.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-loop4.C
new file mode 100644
index 0000000..67f7cfa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-loop4.C
@@ -0,0 +1,27 @@
+// { dg-do compile { target c++14 } }
+
+struct A
+{
+ int i;
+};
+
+constexpr bool f()
+{
+ A ar[5] = { 6, 7, 8, 9, 10 };
+ A *ap = ar;
+ int i = 0, j = 0;
+ for (j = 0; j < 2; j++)
+ {
+ do
+ *ap++ = A{i};
+ while (++i < j * 2 + 2);
+ }
+ return (ar[0].i == 0
+ && ar[1].i == 1
+ && ar[2].i == 2
+ && ar[3].i == 3
+ && ar[4].i == 10);
+}
+
+#define SA(X) static_assert((X),#X)
+SA(f());
diff --git a/gcc/testsuite/g++.dg/ubsan/pr70135.C b/gcc/testsuite/g++.dg/ubsan/pr70135.C
new file mode 100644
index 0000000..340334a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ubsan/pr70135.C
@@ -0,0 +1,36 @@
+// PR c++/70135
+// { dg-do run }
+// { dg-options "-fsanitize=bounds -std=c++14" }
+
+template <bool... b>
+struct S {
+ static constexpr bool c[] {b...};
+ static constexpr auto foo ()
+ {
+ unsigned long n = 0;
+ for (unsigned long i = 0; i < sizeof (c); i++)
+ if (!c[i])
+ ++n;
+ return n;
+ }
+ static constexpr auto n = foo () + 1;
+ static constexpr auto bar ()
+ {
+ int h = 0;
+ for (int g = 0, i = 0; g < n; ++g)
+ {
+ while (i < sizeof...(b) && c[i++])
+ ++h;
+ h += 64;
+ }
+ return h;
+ }
+};
+
+int
+main ()
+{
+ S <true, false, false, true, true, true, false, true> s;
+ constexpr auto c = s.bar ();
+ static_assert (s.bar () == 4 * 64 + 5);
+}