public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/autopar_devel] c++: ICE when shortening right shift [PR94955]
@ 2020-08-22 21:22 Giuliano Belinassi
  0 siblings, 0 replies; only message in thread
From: Giuliano Belinassi @ 2020-08-22 21:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:44c70a5f3219c6c34b3709720a5c1a1be83a634c

commit 44c70a5f3219c6c34b3709720a5c1a1be83a634c
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed May 6 15:53:33 2020 -0400

    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.

Diff:
---
 gcc/cp/ChangeLog                              |  6 ++++++
 gcc/cp/typeck.c                               |  4 +++-
 gcc/testsuite/ChangeLog                       |  5 +++++
 gcc/testsuite/g++.dg/cpp0x/constexpr-shift2.C | 12 ++++++++++++
 4 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 605cdf33ae4..4e446585aa4 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+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
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 768c62281f4..d2e6c907622 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 67f2c550ff0..02de8028552 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+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
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 00000000000..9b3490a66a7
--- /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();
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-22 21:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-22 21:22 [gcc/devel/autopar_devel] c++: ICE when shortening right shift [PR94955] Giuliano Belinassi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).