aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-05-06 15:53:33 -0400
committerMarek Polacek <polacek@redhat.com>2020-05-18 19:01:54 -0400
commit2d4e1e144c25e526e4f668be5a0bc10d0c1c738c (patch)
tree1e73b7bcfa85d209cf4dcd1ada19fb46f881b49a
parentbf732686c0b9c42a2fe119db774c5a65e5a97174 (diff)
downloadgcc-2d4e1e144c25e526e4f668be5a0bc10d0c1c738c.zip
gcc-2d4e1e144c25e526e4f668be5a0bc10d0c1c738c.tar.gz
gcc-2d4e1e144c25e526e4f668be5a0bc10d0c1c738c.tar.bz2
c++: ICE when shortening right shift [PR94955]
Since r10-6527 fold_for_warn calls maybe_constant_value, which means it can fold more than it previously could. In this testcase it means that cp_build_binary_op/RSHIFT_EXPR set short_shift because now we were able to fold op1 to an INTEGER_CST. But then when actually performing the shortening we crashed because cp_fold_rvalue wasn't able to fold as much as f_f_w and so tree_int_cst_sgn crashed on a NOP_EXPR. Therefore the calls should probably match. PR c++/94955 * typeck.c (cp_build_binary_op): Use fold_for_warn instead of cp_fold_rvalue. * g++.dg/cpp0x/constexpr-shift2.C: New test.
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c4
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-shift2.C12
4 files changed, 26 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 605cdf3..4e44658 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,11 @@
2020-05-18 Marek Polacek <polacek@redhat.com>
+ PR c++/94955
+ * typeck.c (cp_build_binary_op): Use fold_for_warn instead of
+ cp_fold_rvalue.
+
+2020-05-18 Marek Polacek <polacek@redhat.com>
+
PR c++/94937
* cvt.c (cp_get_fndecl_from_callee): Return NULL_TREE if the function
type is not INDIRECT_TYPE_P.
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 768c622..d2e6c90 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5633,7 +5633,9 @@ cp_build_binary_op (const op_location_t &location,
{
int unsigned_arg;
tree arg0 = get_narrower (op0, &unsigned_arg);
- tree const_op1 = cp_fold_rvalue (op1);
+ /* We're not really warning here but when we set short_shift we
+ used fold_for_warn to fold the operand. */
+ tree const_op1 = fold_for_warn (op1);
final_type = result_type;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 67f2c55..02de802 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2020-05-18 Marek Polacek <polacek@redhat.com>
+ PR c++/94955
+ * g++.dg/cpp0x/constexpr-shift2.C: New test.
+
+2020-05-18 Marek Polacek <polacek@redhat.com>
+
PR c++/94937
* g++.dg/cpp1z/constexpr-if34.C: New test.
* g++.dg/cpp2a/is-constant-evaluated10.C: New test.
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-shift2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-shift2.C
new file mode 100644
index 0000000..9b3490a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-shift2.C
@@ -0,0 +1,12 @@
+// PR c++/94955
+// { dg-do compile { target c++11 } }
+
+struct S {
+ static constexpr char foo() { return 10; }
+};
+
+short int
+fn (short int e)
+{
+ return e >> S::foo();
+}