public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-5047] Get rid of infinite recursion for 'typedef' used with GTY-marked 'gcc/diagnostic-spec.h:nowarn_map'
Date: Tue,  9 Nov 2021 12:21:38 +0000 (GMT)	[thread overview]
Message-ID: <20211109122138.4F91E3858431@sourceware.org> (raw)

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

commit r12-5047-gc71cb26a9e841888f52e4bfcaad94c8f8ecb4fdb
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Tue Nov 9 10:55:15 2021 +0100

    Get rid of infinite recursion for 'typedef' used with GTY-marked 'gcc/diagnostic-spec.h:nowarn_map' [PR101204, PR103157]
    
    Reproduced with clang version 10.0.0-4ubuntu1:
    
        gtype-desc.c:11333:1: warning: all paths through this function will call itself [-Winfinite-recursion]
    
    ... as well as some GCC's '-O2 -fdump-tree-optimized':
    
        void gt_pch_nx(int_hash<unsigned int, 0u, 4294967295u>*, gt_pointer_operator, void*) ([...])
        {
          <bb 2>:
    
          <bb 3>:
          goto <bb 3>;
    
        }
    
    That three-arguments 'gt_pch_nx' function as well as two one-argument
    'gt_ggc_mx', 'gt_pch_nx' functions now turn empty:
    
        [...]
         void
        -gt_ggc_mx (int_hash<location_t,0,UINT_MAX>& x_r ATTRIBUTE_UNUSED)
        +gt_ggc_mx (struct xint_hash_t& x_r ATTRIBUTE_UNUSED)
         {
        -  int_hash<location_t,0,UINT_MAX> * ATTRIBUTE_UNUSED x = &x_r;
        -  gt_ggc_mx (&((*x)));
        +  struct xint_hash_t * ATTRIBUTE_UNUSED x = &x_r;
         }
        [...]
         void
        -gt_pch_nx (int_hash<location_t,0,UINT_MAX>& x_r ATTRIBUTE_UNUSED)
        +gt_pch_nx (struct xint_hash_t& x_r ATTRIBUTE_UNUSED)
         {
        -  int_hash<location_t,0,UINT_MAX> * ATTRIBUTE_UNUSED x = &x_r;
        -  gt_pch_nx (&((*x)));
        +  struct xint_hash_t * ATTRIBUTE_UNUSED x = &x_r;
         }
        [...]
         void
        -gt_pch_nx (int_hash<location_t,0,UINT_MAX>* x ATTRIBUTE_UNUSED,
        +gt_pch_nx (struct xint_hash_t* x ATTRIBUTE_UNUSED,
                ATTRIBUTE_UNUSED gt_pointer_operator op,
                ATTRIBUTE_UNUSED void *cookie)
         {
        -    gt_pch_nx (&((*x)), op, cookie);
         }
        [...]
    
            gcc/
            PR middle-end/101204
            PR other/103157
            * diagnostic-spec.h (typedef xint_hash_t): Turn into...
            (struct xint_hash_t): ... this.
            * doc/gty.texi: Update.

Diff:
---
 gcc/diagnostic-spec.h | 6 +++++-
 gcc/doc/gty.texi      | 8 ++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/diagnostic-spec.h b/gcc/diagnostic-spec.h
index 9b3aaaa3ce6..e54e9e3ddbe 100644
--- a/gcc/diagnostic-spec.h
+++ b/gcc/diagnostic-spec.h
@@ -130,7 +130,11 @@ operator!= (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
   return !(lhs == rhs);
 }
 
-typedef int_hash <location_t, 0, UINT_MAX> xint_hash_t;
+/* Per PR103157 "'gengtype': 'typedef' causing infinite-recursion code to be
+   generated", don't use
+       typedef int_hash<location_t, 0, UINT_MAX> xint_hash_t;
+   here.  */
+struct xint_hash_t : int_hash<location_t, 0, UINT_MAX> {};
 typedef hash_map<xint_hash_t, nowarn_spec_t> xint_hash_map_t;
 
 /* A mapping from a 'location_t' to the warning spec set for it.  */
diff --git a/gcc/doc/gty.texi b/gcc/doc/gty.texi
index 2ad7793191b..b996ff2c44e 100644
--- a/gcc/doc/gty.texi
+++ b/gcc/doc/gty.texi
@@ -64,6 +64,14 @@ The parser understands simple typedefs such as
 @code{typedef int @var{name};}.
 These don't need to be marked.
 
+However, in combination with GTY, avoid using typedefs such as
+@code{typedef int_hash<@dots{}> @var{name};}
+for these generate infinite-recursion code.
+See @uref{https://gcc.gnu.org/PR103157,PR103157}.
+Instead, you may use
+@code{struct @var{name} : int_hash<@dots{}> @{@};},
+for example.
+
 Since @code{gengtype}'s understanding of C++ is limited, there are
 several constructs and declarations that are not supported inside
 classes/structures marked for automatic GC code generation.  The


                 reply	other threads:[~2021-11-09 12:21 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=20211109122138.4F91E3858431@sourceware.org \
    --to=tschwinge@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).