]> git.ipfire.org Git - thirdparty/gcc.git/commit
c-family: Fix up ICE during pretty-printing of PMF related expression [PR101515]
authorJakub Jelinek <jakub@redhat.com>
Sat, 19 Mar 2022 07:40:47 +0000 (08:40 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 29 Mar 2022 05:52:31 +0000 (07:52 +0200)
commitf70464efbfa9469c57ac75b9aa5a62a2cff4f1fe
tree7aafa91feeddc94ae1b2edba7c30cc6114d3e27c
parent91f7d7e1bb6827bf8e0b7ba7eb949953a5b1bd18
c-family: Fix up ICE during pretty-printing of PMF related expression [PR101515]

The intent of r11-6729 is that it prints something that helps user to figure
out what exactly is being accessed.
When we find a unique non-static data member that is being accessed, even
when we can't fold it nicely, IMNSHO it is better to print
  ((sometype *)&var)->field
or
  (*(sometype *)&var).field
instead of
  *(fieldtype *)((char *)&var + 56)
because the user doesn't know what is at offset 56, we shouldn't ask user
to decipher structure layout etc.

One question is if we could return something better for the TYPE_PTRMEMFUNC_FLAG
RECORD_TYPE members here (something that would print it more naturally/readably
in a C++ way), though the fact that the routine is in c-family makes it
harder.

Another one is whether we shouldn't punt for FIELD_DECLs that don't have
nicely printable name of its containing scope, something like:
                if (tree scope = get_containing_scope (field))
                  if (TYPE_P (scope) && TYPE_NAME (scope) == NULL_TREE)
                    break;
                return cop;
or so.  This patch implements that.

Note the returned cop is a COMPONENT_REF where the first argument has a
nicely printable type name (x with type sp), but sp's TYPE_MAIN_VARIANT
is the unnamed TYPE_PTRMEMFUNC_FLAG.  So another possibility would be if
we see such a problem for the FIELD_DECL's scope, check if TYPE_MAIN_VARIANT
of the first COMPONENT_REF's argument is equal to that scope and in that
case use TREE_TYPE of the first COMPONENT_REF's argument as the scope
instead.

2022-03-19  Jakub Jelinek  <jakub@redhat.com>

PR c++/101515
* c-pretty-print.c (c_fold_indirect_ref_for_warn): For C++ don't
return COMPONENT_REFs with FIELD_DECLs whose containing scope can't
be printed.

* g++.dg/warn/pr101515.C: New test.

(cherry picked from commit 2663d18356b0a62f5a800c7e5596d814cd3c2c41)
gcc/c-family/c-pretty-print.c
gcc/testsuite/g++.dg/warn/pr101515.C [new file with mode: 0644]