aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2016-12-06 10:24:36 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2016-12-06 10:24:36 +0100
commit0f57194bfccc05e07b48e8ccd60d3653c6d65c9a (patch)
tree0be8f1ad83787cea9053f376cd058a980b2a2abe /gcc
parent66972191ee05c5dd2d02e5d062fe1c942e42fcd7 (diff)
downloadgcc-0f57194bfccc05e07b48e8ccd60d3653c6d65c9a.zip
gcc-0f57194bfccc05e07b48e8ccd60d3653c6d65c9a.tar.gz
gcc-0f57194bfccc05e07b48e8ccd60d3653c6d65c9a.tar.bz2
re PR c++/71537 (GCC rejects consetxpr boolean conversions and comparisons on the result of pointer arithmetic.)
PR c++/71537 * fold-const.c (fold_comparison): Assume CONSTANT_CLASS_P (base0) plus offset is non-zero. For maybe_nonzero_address decl base0, require indirect_base0. * g++.dg/cpp0x/constexpr-71537.C: New test. From-SVN: r243286
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/fold-const.c18
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-71537.C18
4 files changed, 36 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9ed8f5f..aef86e3 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,11 @@
2016-12-06 Jakub Jelinek <jakub@redhat.com>
PR c++/71537
+ * fold-const.c (fold_comparison): Assume CONSTANT_CLASS_P (base0)
+ plus offset is non-zero. For maybe_nonzero_address decl base0,
+ require indirect_base0.
+
+ PR c++/71537
* fold-const-call.c (fold_const_call_1): Remove memchr handling here.
(fold_const_call) <case CFN_BUILT_IN_STRNCMP,
case CFN_BUILT_IN_STRNCASECMP>: Formatting improvements.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 6517188..c649e54 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8419,14 +8419,16 @@ fold_comparison (location_t loc, enum tree_code code, tree type,
below follow the C++ rules with the additional property that
every object pointer compares greater than a null pointer.
*/
- else if (DECL_P (base0)
- && maybe_nonzero_address (base0) > 0
- /* Avoid folding references to struct members at offset 0 to
- prevent tests like '&ptr->firstmember == 0' from getting
- eliminated. When ptr is null, although the -> expression
- is strictly speaking invalid, GCC retains it as a matter
- of QoI. See PR c/44555. */
- && (offset0 == NULL_TREE && bitpos0 != 0)
+ else if (((DECL_P (base0)
+ && maybe_nonzero_address (base0) > 0
+ /* Avoid folding references to struct members at offset 0 to
+ prevent tests like '&ptr->firstmember == 0' from getting
+ eliminated. When ptr is null, although the -> expression
+ is strictly speaking invalid, GCC retains it as a matter
+ of QoI. See PR c/44555. */
+ && (offset0 == NULL_TREE && bitpos0 != 0))
+ || CONSTANT_CLASS_P (base0))
+ && indirect_base0
/* The caller guarantees that when one of the arguments is
constant (i.e., null in this case) it is second. */
&& integer_zerop (arg1))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b44993b..7aa429f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,9 @@
2016-12-06 Jakub Jelinek <jakub@redhat.com>
PR c++/71537
+ * g++.dg/cpp0x/constexpr-71537.C: New test.
+
+ PR c++/71537
* g++.dg/cpp0x/constexpr-memchr.C: New test.
PR c++/71537
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-71537.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-71537.C
new file mode 100644
index 0000000..3d5ac34
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-71537.C
@@ -0,0 +1,18 @@
+// PR c++/71537
+// { dg-do compile { target c++11 } }
+
+constexpr int n[42] = {1};
+constexpr int x1 = n ? 1 : 0;
+constexpr int x2 = n + 1 ? 1 : 0;
+constexpr int x3 = "abc" ? 1 : 0;
+constexpr int x4 = "abc" + 1 ? 1 : 0;
+constexpr bool x5 = "abc" + 1;
+constexpr bool x6 = "abc" + 4;
+constexpr bool x7 = n + 42;
+static_assert (x1 == 1, "");
+static_assert (x2 == 1, "");
+static_assert (x3 == 1, "");
+static_assert (x4 == 1, "");
+static_assert (x5, "");
+static_assert (x6, "");
+static_assert (x7, "");