public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3104] [Committed] PR middle-end/102029: Stricter typing in LSHIFT_EXPR sign folding.
@ 2021-08-24  2:00 Roger Sayle
  0 siblings, 0 replies; only message in thread
From: Roger Sayle @ 2021-08-24  2:00 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:78fa5112b4c2dcd94b78ee79baddebbf14d6ad98

commit r12-3104-g78fa5112b4c2dcd94b78ee79baddebbf14d6ad98
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Tue Aug 24 02:59:02 2021 +0100

    [Committed] PR middle-end/102029: Stricter typing in LSHIFT_EXPR sign folding.
    
    My sincere apologies to everyone (again).  As diagnosed by
    Jakub Jelinek, my recent patch to fold the signedness of LSHIFT_EXPR
    needs to be careful not to attempt transforming a left shift in an
    integer type into an invalid left shift of a pointer type.
    
    2021-08-24  Roger Sayle  <roger@nextmovesoftware.com>
                Jakub Jelinek  <jakub@redhat.com>
    
    gcc/ChangeLog
            PR middle-end/102029
            * match.pd (shift transformations): Add an additional check for
            !POINTER_TYPE_P in the recently added left shift transformation.
    
    gcc/testsuite/ChangeLog
            PR middle-end/102029
            * gcc.dg/fold-convlshift-3.c: New test case.

Diff:
---
 gcc/match.pd                             | 4 +++-
 gcc/testsuite/gcc.dg/fold-convlshift-3.c | 8 ++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 978a1b0172e..e5bbb123a6a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3389,7 +3389,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    the form that minimizes the number of conversions.  */
 (simplify
  (convert (lshift:s@0 (convert:s@1 @2) INTEGER_CST@3))
- (if (tree_nop_conversion_p (type, TREE_TYPE (@0))
+ (if (INTEGRAL_TYPE_P (type)
+      && !POINTER_TYPE_P (type)
+      && tree_nop_conversion_p (type, TREE_TYPE (@0))
       && INTEGRAL_TYPE_P (TREE_TYPE (@2))
       && TYPE_PRECISION (TREE_TYPE (@2)) <= TYPE_PRECISION (type))
   (lshift (convert @2) @3)))
diff --git a/gcc/testsuite/gcc.dg/fold-convlshift-3.c b/gcc/testsuite/gcc.dg/fold-convlshift-3.c
new file mode 100644
index 00000000000..8d01191f197
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-convlshift-3.c
@@ -0,0 +1,8 @@
+/* PR middle-end/102029 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+int *
+foo (const __PTRDIFF_TYPE__ l)
+{
+  return (int *) (l << 2);
+}


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

only message in thread, other threads:[~2021-08-24  2:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-24  2:00 [gcc r12-3104] [Committed] PR middle-end/102029: Stricter typing in LSHIFT_EXPR sign folding Roger Sayle

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).