diff options
author | Nathan Sidwell <nathan@acm.org> | 2022-10-31 06:11:28 -0400 |
---|---|---|
committer | Nathan Sidwell <nathan@acm.org> | 2022-11-01 17:44:36 -0400 |
commit | 2b0e81d5cc2f7e1d773f6c502bd65b097f392675 (patch) | |
tree | 56bc63afdde5a1c5b0aef088a4dafdcb200c08c0 /gcc/cp/cp-tree.h | |
parent | 4f8aac77e05d0ae0b7f242fd1aa344d36ff52ceb (diff) | |
download | gcc-2b0e81d5cc2f7e1d773f6c502bd65b097f392675.zip gcc-2b0e81d5cc2f7e1d773f6c502bd65b097f392675.tar.gz gcc-2b0e81d5cc2f7e1d773f6c502bd65b097f392675.tar.bz2 |
c++: per-scope, per-signature lambda discriminators
This implements ABI-compliant lambda discriminators. Not only do we
have per-scope counters, but we also distinguish by lambda signature.
Only lambdas with the same signature will need non-zero
discriminators. As the discriminator is signature-dependent, we have
to process the lambda function's declaration before we can determine
it. For templated and generic lambdas the signature is that of the
uninstantiated lambda -- not separate for each instantiation.
With this change, gcc and clang now produce the same lambda manglings
for all these testcases.
gcc/cp/
* cp-tree.h (LAMBDA_EXPR_SCOPE_SIG_DISCRIMINATOR): New.
(struct tree_lambda_expr): Add discriminator_sig bitfield.
(recrd_lambda_scope_sig_discriminator): Declare.
* lambda.cc (struct lambda_sig_count): New.
(lambda_discriminator): Add signature vector.
(start_lambda_scope): Adjust.
(compare_lambda_template_head, compare_lambda_sig): New.
(record_lambda_scope_sig_discriminator): New.
* mangle.cc (write_closure_type): Use the scope-sig discriminator for
ABI >= 18. Emit abi mangling warning if needed.
* module.cc (trees_out::core_vals): Stream the new discriminator.
(trees_in::core_vals): Likewise.
* parser.cc (cp_parser_lambda_declarator_opt): Call
record_lambda_scope_sig_discriminator.
* pt.cc (tsubst_lambda_expr): Likewise.
libcc1/
* libcp1plugin.cc (plugin_start_lambda_closure_class_type):
Initialize the per-scope, per-signature discriminator.
gcc/testsuite/
* g++.dg/abi/lambda-sig1-18.C: New.
* g++.dg/abi/lambda-sig1-18vs17.C: New.
* g++.dg/cpp1y/lambda-mangle-1-18.C: New.
Diffstat (limited to 'gcc/cp/cp-tree.h')
-rw-r--r-- | gcc/cp/cp-tree.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 4c0bacb..d13bb3d 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1501,9 +1501,12 @@ enum cp_lambda_default_capture_mode_type { (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->extra_scope) /* Lambdas in the same extra scope might need a discriminating count. - This is a single per-scope count. */ + For ABI 17, we have single per-scope count, for ABI 18, we have + per-scope, per-signature numbering. */ #define LAMBDA_EXPR_SCOPE_ONLY_DISCRIMINATOR(NODE) \ (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->discriminator_scope) +#define LAMBDA_EXPR_SCOPE_SIG_DISCRIMINATOR(NODE) \ + (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->discriminator_sig) /* During parsing of the lambda, a vector of capture proxies which need to be pushed once we're done processing a nested lambda. */ @@ -1533,6 +1536,7 @@ struct GTY (()) tree_lambda_expr location_t locus; enum cp_lambda_default_capture_mode_type default_capture_mode : 2; unsigned discriminator_scope : 15; // Per-scope discriminator + unsigned discriminator_sig : 15; // Per-scope, per-signature discriminator }; /* Non-zero if this template specialization has access violations that @@ -7783,6 +7787,7 @@ extern void start_lambda_scope (tree decl); extern void finish_lambda_scope (void); extern void record_lambda_scope (tree lambda); extern void record_lambda_scope_discriminator (tree lambda); +extern void record_lambda_scope_sig_discriminator (tree lambda, tree fn); extern tree start_lambda_function (tree fn, tree lambda_expr); extern void finish_lambda_function (tree body); extern bool regenerated_lambda_fn_p (tree); |