aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/method.c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2021-04-01 10:42:43 -0400
committerMarek Polacek <polacek@redhat.com>2021-04-01 17:04:15 -0400
commit6a60ffc297b9d4903543a25538e62e7fb39420a9 (patch)
treedb97bc7f8917b8ee7d2c87667c790c7f4dfc551e /gcc/cp/method.c
parent0cf4813202f19768e31666f6aa82bde4dce4065a (diff)
downloadgcc-6a60ffc297b9d4903543a25538e62e7fb39420a9.zip
gcc-6a60ffc297b9d4903543a25538e62e7fb39420a9.tar.gz
gcc-6a60ffc297b9d4903543a25538e62e7fb39420a9.tar.bz2
c++: GC collects live data when synthesizing operator== [PR99831]
Here we crash in reshape_init because we're accessing ggc_freed & poisoned data: since r277865 in defaulted_late_check we call synthesize_method here: if (kind == sfk_comparison) { /* If the function was declared constexpr, check that the definition qualifies. Otherwise we can define the function lazily. */ if (DECL_DECLARED_CONSTEXPR_P (fn) && !DECL_INITIAL (fn)) synthesize_method (fn); return; } which in this test triggers when we're processing the string<"a">{} in the static_assert. First, we create a CONSTRUCTOR for the "{}" in cp_parser_functional_cast, then we call finish_compound_literal which calls complete_type and that results in garbage collection, which then frees the CONSTRUCTOR {} we created when parsing the braced-list in string<"a">{} -- at this point, it's not referenced by anything. (That's not the case for 'type' in finish_compound_literal: the symbol table contains a node for operator==, so ggc_mark_roots goes and marks the fn decl, its type, its arguments etc., as used, so we don't collect it.) We could just bump function_depth around the new call to synthesize_method to prevent GC. gcc/cp/ChangeLog: PR c++/99831 * method.c (defaulted_late_check): ++ and -- function_depth around the call to synthesize_method. * pt.c: Remove the saved_trees global. gcc/testsuite/ChangeLog: PR c++/99831 * g++.dg/other/gc6.C: New test.
Diffstat (limited to 'gcc/cp/method.c')
-rw-r--r--gcc/cp/method.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index 8ae7496..0f416be 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -3131,7 +3131,12 @@ defaulted_late_check (tree fn)
/* If the function was declared constexpr, check that the definition
qualifies. Otherwise we can define the function lazily. */
if (DECL_DECLARED_CONSTEXPR_P (fn) && !DECL_INITIAL (fn))
- synthesize_method (fn);
+ {
+ /* Prevent GC. */
+ function_depth++;
+ synthesize_method (fn);
+ function_depth--;
+ }
return;
}