]> gcc.gnu.org Git - gcc.git/commit
tree-cfg: Allow enum types as result of POINTER_DIFF_EXPR [PR98556]
authorJakub Jelinek <jakub@redhat.com>
Sat, 9 Jan 2021 09:49:38 +0000 (10:49 +0100)
committerJakub Jelinek <jakub@redhat.com>
Sat, 9 Jan 2021 10:52:01 +0000 (11:52 +0100)
commit0188eab844eacda5edc6257771edb771844ae069
treebaafe8b297895dc18665d2902aba9ffe4f958af7
parentee697d4bbb7991c99539ba6c20ec76b5d488cffc
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 991656092f78eeab2a48fdbacf4e1f08567badaf)
gcc/testsuite/c-c++-common/pr98556.c [new file with mode: 0644]
gcc/tree-cfg.c
This page took 0.054013 seconds and 5 git commands to generate.