public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/vendors/redhat/heads/gcc-8-branch)] tree-cfg: Allow enum types as result of POINTER_DIFF_EXPR [PR98556]
Date: Fri, 23 Apr 2021 10:52:32 +0000 (GMT)	[thread overview]
Message-ID: <20210423105232.B2C183A77C0C@sourceware.org> (raw)

https://gcc.gnu.org/g:d033427039789102a65b3dcb4aa5c64a757b762f

commit d033427039789102a65b3dcb4aa5c64a757b762f
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Jan 9 10:49:38 2021 +0100

    tree-cfg: Allow enum types as result of POINTER_DIFF_EXPR [PR98556]
    
    As conversions between signed integers and signed enums with the same
    precision are useless in GIMPLE, it seems strange that we require that
    POINTER_DIFF_EXPR result must be INTEGER_TYPE.
    
    If we really wanted to require that, we'd need to change the gimplifier
    to ensure that, which it isn't the case on the following testcase.
    What is going on during the gimplification is that when we have the
    (enum T) (p - q) cast, it is stripped through
          /* Strip away as many useless type conversions as possible
             at the toplevel.  */
          STRIP_USELESS_TYPE_CONVERSION (*expr_p);
    and when the MODIFY_EXPR is gimplified, the *to_p has enum T type,
    while *from_p has intptr_t type and as there is no conversion in between,
    we just create GIMPLE_ASSIGN from that.
    
    2021-01-09  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/98556
            * tree-cfg.c (verify_gimple_assign_binary): Allow lhs of
            POINTER_DIFF_EXPR to be any integral type.
    
            * c-c++-common/pr98556.c: New test.
    
    (cherry picked from commit 0188eab844eacda5edc6257771edb771844ae069)

Diff:
---
 gcc/testsuite/c-c++-common/pr98556.c | 11 +++++++++++
 gcc/tree-cfg.c                       |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/c-c++-common/pr98556.c b/gcc/testsuite/c-c++-common/pr98556.c
new file mode 100644
index 00000000000..865957bf353
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr98556.c
@@ -0,0 +1,11 @@
+/* PR c++/98556 */
+/* { dg-do compile } */
+/* { dg-options "-O0" } */
+
+enum T { E = -__LONG_MAX__ - 1 };
+
+enum T
+foo (char *p, char *q)
+{
+  return (enum T) (p - q);
+}
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 6a2cf8b01ff..4d144fcbd43 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -4163,7 +4163,7 @@ verify_gimple_assign_binary (gassign *stmt)
 	    /* Because we special-case pointers to void we allow difference
 	       of arbitrary pointers with the same mode.  */
 	    || TYPE_MODE (rhs1_type) != TYPE_MODE (rhs2_type)
-	    || TREE_CODE (lhs_type) != INTEGER_TYPE
+	    || !INTEGRAL_TYPE_P (lhs_type)
 	    || TYPE_UNSIGNED (lhs_type)
 	    || TYPE_PRECISION (lhs_type) != TYPE_PRECISION (rhs1_type))
 	  {


                 reply	other threads:[~2021-04-23 10:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210423105232.B2C183A77C0C@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).