From 4d691426a602f3179ef2847903e417fe473955c5 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Tue, 9 Nov 2021 10:55:15 +0100 Subject: [PATCH] Get rid of infinite recursion for 'typedef' used with GTY-marked 'gcc/diagnostic-spec.h:nowarn_map' [PR101204] 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*, gt_pointer_operator, void*) ([...]) { : : goto ; } 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& x_r ATTRIBUTE_UNUSED) +gt_ggc_mx (struct xint_hash_t& x_r ATTRIBUTE_UNUSED) { - int_hash * ATTRIBUTE_UNUSED x = &x_r; - gt_ggc_mx (&((*x))); + struct xint_hash_t * ATTRIBUTE_UNUSED x = &x_r; } [...] void -gt_pch_nx (int_hash& x_r ATTRIBUTE_UNUSED) +gt_pch_nx (struct xint_hash_t& x_r ATTRIBUTE_UNUSED) { - int_hash * ATTRIBUTE_UNUSED x = &x_r; - gt_pch_nx (&((*x))); + struct xint_hash_t * ATTRIBUTE_UNUSED x = &x_r; } [...] void -gt_pch_nx (int_hash* 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 * diagnostic-spec.h (typedef xint_hash_t): Turn into... (struct xint_hash_t): ... this. * doc/gty.texi: Update. --- gcc/diagnostic-spec.h | 2 +- gcc/doc/gty.texi | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/gcc/diagnostic-spec.h b/gcc/diagnostic-spec.h index 9b3aaaa3ce6..d29cdd46290 100644 --- a/gcc/diagnostic-spec.h +++ b/gcc/diagnostic-spec.h @@ -130,7 +130,7 @@ operator!= (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs) return !(lhs == rhs); } -typedef int_hash xint_hash_t; +struct xint_hash_t : int_hash {}; typedef hash_map 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..8900e082225 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/PR101204,PR101204}. +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 -- 2.33.0