From patchwork Mon Jan 6 12:21:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 104164 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 256563858CD1 for ; Mon, 6 Jan 2025 12:24:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 256563858CD1 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=bOw/eH23 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 3D60E3858C32 for ; Mon, 6 Jan 2025 12:21:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D60E3858C32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3D60E3858C32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736166111; cv=none; b=RYW5yO2/F/NZBtCn4zNSmjIvWpFODmB3NGk/UbUr4kNWJ7E7KZJd6fX5mskvd1GaooyCLssl5xqomRSDl3huYlq2NTrSQyF6FC1YvXh3B7lmD8KtCJrK+ruoLhehomqWj/eaAc70xAAD+8K/oVNx6kJ7leTQzkiRCkOJzFafWEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736166111; c=relaxed/simple; bh=Dh930WmskWVjuV4P3VnfvJmIIn+IF3Biqc8CCmNbGFI=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=YhjTa+hqVUxLzvZ7QAGpy0LnBZn52XLFbrn1d4v/wSw+OGQaejxQnKC/Sn/b6qKpvniFHEnx/PtGTU5L1kg3nyWutL50JvNyGx662X9D6yJAEBTELZQmcTDTd3UA4SHKS3jsfD13jgkp2CaiA4eo30L84BJl6bM+XAs2oOsqu5Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2166db59927so20328575ad.0 for ; Mon, 06 Jan 2025 04:21:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736166080; x=1736770880; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=Fqv9f66oCW1t511lGlHHoKm4a94zbYAmQrcahpUXgLY=; b=bOw/eH23v+BAgaiWNQPVTYpfQGZyqHdTayQ0jR8JaZ2VPStmUZ6E231A/fWq8xPU3O rQDTckh+sjbe14P+iu096WWyszgxDIiQGtqXrAFNYTRgEx89Rq9sP0Gm8C0ik5yEZyEz KML0frzavBeAZ8tBUZCe29kNYCXePcqpXYQfs5NHZ/6+hrc9lykyQjje+T8KEKsv8YJn 04YcS/pG2QHWUAoeHk9cDQa4Y8YObCkMPovMGAOqVEnunRK5okQFTl74lqwCP32L8xbT xBCOTg+3xXC4qmIWdOHOMUFWyECY5g9Ed58jA7wCvcj3hcxVdOFax1TZT6gu8azeljOw /SJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736166080; x=1736770880; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Fqv9f66oCW1t511lGlHHoKm4a94zbYAmQrcahpUXgLY=; b=n77rMuXQccDRYtcOZ8x3vdmSGTvmXy0tyzFseCuqV+Pf7ifgHoy1pVBJsKxlyBBAFm rMImFDUXnFipnrTLeGe1TrdB4NEbyu2nomSVeOsnkFi8MEk+aNsqWyk5awiZrIVU9+y5 z4nqpWmBTMlFNDM8B93Mr0m2dB8FoMDmZ8yyfyNyIdqo1MFhdliZBovYfkF4BzKYMeYS Q4UVzmIV8dpszVK6mSw+4/X0SBNImtEzwj5ukGCJ3T64QU41Gz5ECzs5ZENSohaBUIkZ qdxZ45HU6HNO4RFWREmZWcqP5CXjk1tPpFFm6XA0qbPN1undQtag7kP+UwKkk0Au5lFK VAXQ== X-Gm-Message-State: AOJu0YyiLHut2Xmje5uCgu+lVH1B7dXeuXMgT8hg1V1wJ/WKmJKIsXjA huI86iYOnkIpEb79/KaP2cLYiEuYM1ghBEVkT0ThE/bF9VtxR0jvtw7vnQ== X-Gm-Gg: ASbGncsrCjzuSAKRhQ3no6PAsKcBfAYdbBHvJ3hu5yFDomoc5EdBm2s8pFdWyYd/0B7 O45QDKHFPF4UILfVu0uwatNt+V0WyejleS+eK3+y7PAvyhpf8CY/JzWpdR5paxka6Q6MVKclMaJ 5pLpd2YzBniUkkM3kHhwN7ekOCV6Mb8M47ebBsGhmEPqqdJCEMy1vjv709JuP3U8n1XBzhPCxP1 QBvNhDOStq6J2ZJfgMryIwG+jlEgfhxZEcYG/ULftuf7GzXHB4Tff1qt7/T0osF/giv3tddOdz9 PDUQmKXcV9stQsxoifIZug== X-Google-Smtp-Source: AGHT+IEAKw+AqNEQtrxyjCVxXSckO6Yrh/ttiK9Y7eV/fqEGD9EmRcf+Gc35tj6J66O8UbxRcF5JjQ== X-Received: by 2002:a05:6a20:8403:b0:1cf:3b1e:ccd with SMTP id adf61e73a8af0-1e5e0471468mr34823193637.5.1736166079849; Mon, 06 Jan 2025 04:21:19 -0800 (PST) Received: from Thaum. (163-47-68-2.ipv4.originbroadband.com.au. [163.47.68.2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad81575fsm31125495b3a.36.2025.01.06.04.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 04:21:17 -0800 (PST) Message-ID: <677bcabd.a70a0220.30746a.51ad@mx.google.com> X-Google-Original-Message-ID: Date: Mon, 6 Jan 2025 23:21:12 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH v3 1/6] c++: Fix mangling of lambdas in static data member initializers [PR107741] References: <677bca93.050a0220.33acbc.5415@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <677bca93.050a0220.33acbc.5415@mx.google.com> X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org This fixes an issue where lambdas declared in the initializer of a static data member within the class body do not get a mangling scope of that variable; this results in mangled names that do not conform to the ABI spec. To do this, the patch splits up grokfield for this case specifically, allowing a declaration to be build and used in start_lambda_scope before parsing the initializer, so that record_lambda_scope works correctly. As a drive-by, this also fixes the issue of a static member not being visible within its own initializer. PR c++/107741 gcc/c-family/ChangeLog: * c-opts.cc (c_common_post_options): Bump ABI version. gcc/ChangeLog: * common.opt: Add -fabi-version=20. * doc/invoke.texi: Likewise. gcc/cp/ChangeLog: * cp-tree.h (start_initialized_static_member): Declare. (finish_initialized_static_member): Declare. * decl2.cc (start_initialized_static_member): New function. (finish_initialized_static_member): New function. * lambda.cc (record_lambda_scope): Support falling back to old ABI (maybe with warning). * parser.cc (cp_parser_member_declaration): Build decl early when parsing an initialized static data member. gcc/testsuite/ChangeLog: * g++.dg/abi/macro0.C: Bump ABI version. * g++.dg/abi/mangle74.C: Remove XFAILs. * g++.dg/other/fold1.C: Restore originally raised error. * g++.dg/abi/lambda-ctx2-19.C: New test. * g++.dg/abi/lambda-ctx2-19vs20.C: New test. * g++.dg/abi/lambda-ctx2-20.C: New test. * g++.dg/abi/lambda-ctx2.h: New test. * g++.dg/cpp0x/static-member-init-1.C: New test. Signed-off-by: Nathaniel Shead --- gcc/c-family/c-opts.cc | 2 +- gcc/common.opt | 5 +- gcc/cp/cp-tree.h | 3 + gcc/cp/decl2.cc | 77 +++++++++++++++++++ gcc/cp/lambda.cc | 33 ++++++-- gcc/cp/parser.cc | 74 ++++++++++++------ gcc/doc/invoke.texi | 3 + gcc/testsuite/g++.dg/abi/lambda-ctx2-19.C | 10 +++ gcc/testsuite/g++.dg/abi/lambda-ctx2-19vs20.C | 8 ++ gcc/testsuite/g++.dg/abi/lambda-ctx2-20.C | 10 +++ gcc/testsuite/g++.dg/abi/lambda-ctx2.h | 27 +++++++ gcc/testsuite/g++.dg/abi/macro0.C | 2 +- gcc/testsuite/g++.dg/abi/mangle74.C | 4 +- .../g++.dg/cpp0x/static-member-init-1.C | 5 ++ gcc/testsuite/g++.dg/other/fold1.C | 2 +- 15 files changed, 230 insertions(+), 35 deletions(-) create mode 100644 gcc/testsuite/g++.dg/abi/lambda-ctx2-19.C create mode 100644 gcc/testsuite/g++.dg/abi/lambda-ctx2-19vs20.C create mode 100644 gcc/testsuite/g++.dg/abi/lambda-ctx2-20.C create mode 100644 gcc/testsuite/g++.dg/abi/lambda-ctx2.h create mode 100644 gcc/testsuite/g++.dg/cpp0x/static-member-init-1.C diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index b81d1350b1a..87b231861a6 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -1084,7 +1084,7 @@ c_common_post_options (const char **pfilename) /* Change flag_abi_version to be the actual current ABI level, for the benefit of c_cpp_builtins, and to make comparison simpler. */ - const int latest_abi_version = 19; + const int latest_abi_version = 20; /* Generate compatibility aliases for ABI v13 (8.2) by default. */ const int abi_compat_default = 13; diff --git a/gcc/common.opt b/gcc/common.opt index e2ac99df1d0..4c2560a0632 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1034,10 +1034,13 @@ Driver Undocumented ; Default in G++ 13. ; ; 19: Emits ABI tags if needed in structured binding mangled names. -; Ignores cv-quals on [[no_unique_object]] members. +; Ignores cv-quals on [[no_unique_address]] members. ; Mangles constraints on function templates. ; Default in G++ 14. ; +; 20: Fix mangling of lambdas in static data member initializers. +; Default in G++ 15. +; ; Additional positive integers will be assigned as new versions of ; the ABI become the default version of the ABI. fabi-version= diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 1d741ecedc3..f77a325bdd0 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7224,6 +7224,9 @@ extern tree grokfield (const cp_declarator *, cp_decl_specifier_seq *, tree, bool, tree, tree); extern tree grokbitfield (const cp_declarator *, cp_decl_specifier_seq *, tree, tree, tree); +extern tree start_initialized_static_member (const cp_declarator *, + cp_decl_specifier_seq *, tree); +extern void finish_initialized_static_member (tree, tree, tree); extern tree splice_template_attributes (tree *, tree); extern bool any_dependent_type_attributes_p (tree); extern tree cp_reconstruct_complex_type (tree, tree); diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 869701bceee..5e534935dfd 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -1252,6 +1252,83 @@ grokfield (const cp_declarator *declarator, return NULL_TREE; } +/* Like grokfield, but just for the initial grok of an initialized static + member. Used to be able to push the new decl before parsing the + initialiser. */ + +tree +start_initialized_static_member (const cp_declarator *declarator, + cp_decl_specifier_seq *declspecs, + tree attrlist) +{ + tree value = grokdeclarator (declarator, declspecs, FIELD, SD_INITIALIZED, + &attrlist); + if (!value || error_operand_p (value)) + return error_mark_node; + if (TREE_CODE (value) == TYPE_DECL) + { + error_at (declarator->init_loc, + "typedef %qD is initialized (use %qs instead)", + value, "decltype"); + return error_mark_node; + } + else if (TREE_CODE (value) == FUNCTION_DECL) + { + if (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE) + error_at (declarator->init_loc, + "invalid initializer for member function %qD", + value); + else if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE) + error_at (declarator->init_loc, + "initializer specified for static member function %qD", + value); + else + gcc_unreachable (); + return error_mark_node; + } + else if (TREE_CODE (value) == FIELD_DECL) + { + /* NSDM marked 'static', grokdeclarator has already errored. */ + gcc_checking_assert (seen_error ()); + return error_mark_node; + } + gcc_checking_assert (VAR_P (value)); + + DECL_CONTEXT (value) = current_class_type; + if (processing_template_decl) + { + value = push_template_decl (value); + if (error_operand_p (value)) + return error_mark_node; + } + + if (attrlist) + cplus_decl_attributes (&value, attrlist, 0); + + finish_member_declaration (value); + DECL_INITIALIZED_IN_CLASS_P (value) = true; + + return value; +} + +/* Finish a declaration prepared with start_initialized_static_member. */ + +void +finish_initialized_static_member (tree decl, tree init, tree asmspec) +{ + if (decl == error_mark_node) + return; + gcc_checking_assert (VAR_P (decl)); + + int flags; + if (init && DIRECT_LIST_INIT_P (init)) + flags = LOOKUP_NORMAL; + else + flags = LOOKUP_IMPLICIT; + finish_static_data_member_decl (decl, init, /*init_const_expr_p=*/true, + asmspec, flags); +} + /* Like `grokfield', but for bitfields. WIDTH is the width of the bitfield, a constant expression. The other parameters are as for grokfield. */ diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc index be8a0fe01cb..3166f5eab2c 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see #include "gimplify.h" #include "target.h" #include "decl.h" +#include "flags.h" /* Constructor for a lambda expression. */ @@ -1540,13 +1541,35 @@ finish_lambda_scope (void) void record_lambda_scope (tree lambda) { - LAMBDA_EXPR_EXTRA_SCOPE (lambda) = lambda_scope.scope; - if (lambda_scope.scope) + tree closure = LAMBDA_EXPR_CLOSURE (lambda); + gcc_checking_assert (closure); + + /* Before ABI v20, lambdas in static data member initializers did not + get a dedicated lambda scope. */ + tree scope = lambda_scope.scope; + if (scope + && VAR_P (scope) + && DECL_CLASS_SCOPE_P (scope) + && DECL_INITIALIZED_IN_CLASS_P (scope)) { - tree closure = LAMBDA_EXPR_CLOSURE (lambda); - gcc_checking_assert (closure); - maybe_key_decl (lambda_scope.scope, TYPE_NAME (closure)); + if (!abi_version_at_least (20)) + scope = NULL_TREE; + if (warn_abi && abi_version_crosses (20) && !processing_template_decl) + { + if (abi_version_at_least (20)) + warning_at (location_of (closure), OPT_Wabi, + "the mangled name of %qT changed in " + "%<-fabi-version=20%> (GCC 15.1)", closure); + else + warning_at (location_of (closure), OPT_Wabi, + "the mangled name of %qT changes in " + "%<-fabi-version=20%> (GCC 15.1)", closure); + } } + + LAMBDA_EXPR_EXTRA_SCOPE (lambda) = scope; + if (scope) + maybe_key_decl (scope, TYPE_NAME (closure)); } // Compare lambda template heads TMPL_A and TMPL_B, used for both diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index f548dc31c2b..dd986444449 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -28737,6 +28737,7 @@ cp_parser_member_declaration (cp_parser* parser) tree first_attribute; tree initializer; bool named_bitfld = false; + bool decl_was_initialized_p = false; /* Peek at the next token. */ token = cp_lexer_peek_token (parser->lexer); @@ -28906,9 +28907,8 @@ cp_parser_member_declaration (cp_parser* parser) pure-specifier. It is not correct to parse the initializer before registering the member declaration since the member declaration should be in scope while - its initializer is processed. However, the rest of the - front end does not yet provide an interface that allows - us to handle this correctly. */ + its initializer is processed. As such we might build + decl pre-emptively. */ if (cp_lexer_next_token_is (parser->lexer, CPP_EQ)) { /* In [class.mem]: @@ -28935,18 +28935,31 @@ cp_parser_member_declaration (cp_parser* parser) initializer = cp_parser_pure_specifier (parser); else if (decl_specifiers.storage_class != sc_static) initializer = cp_parser_save_nsdmi (parser); - else if (cxx_dialect >= cxx11) + else { - /* Don't require a constant rvalue in C++11, since we - might want a reference constant. We'll enforce - constancy later. */ - cp_lexer_consume_token (parser->lexer); - /* Parse the initializer. */ - initializer = cp_parser_initializer_clause (parser); + decl = start_initialized_static_member (declarator, + &decl_specifiers, + attributes); + start_lambda_scope (decl); + + if (cxx_dialect >= cxx11) + { + /* Don't require a constant rvalue in C++11, since we + might want a reference constant. We'll enforce + constancy later. */ + cp_lexer_consume_token (parser->lexer); + /* Parse the initializer. */ + initializer = cp_parser_initializer_clause (parser); + } + else + /* Parse the initializer. */ + initializer = cp_parser_constant_initializer (parser); + + finish_lambda_scope (); + finish_initialized_static_member (decl, initializer, + asm_specification); + decl_was_initialized_p = true; } - else - /* Parse the initializer. */ - initializer = cp_parser_constant_initializer (parser); } else if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE) && !function_declarator_p (declarator)) @@ -28956,7 +28969,17 @@ cp_parser_member_declaration (cp_parser* parser) if (decl_specifiers.storage_class != sc_static) initializer = cp_parser_save_nsdmi (parser); else - initializer = cp_parser_initializer (parser); + { + decl = start_initialized_static_member (declarator, + &decl_specifiers, + attributes); + start_lambda_scope (decl); + initializer = cp_parser_initializer (parser); + finish_lambda_scope (); + finish_initialized_static_member (decl, initializer, + asm_specification); + decl_was_initialized_p = true; + } } /* Detect invalid bit-field cases such as @@ -29031,16 +29054,19 @@ cp_parser_member_declaration (cp_parser* parser) declarator->id_loc = token->location; /* Create the declaration. */ - decl = grokfield (declarator, &decl_specifiers, - initializer, /*init_const_expr_p=*/true, - asm_specification, attributes); - - if (parser->fully_implicit_function_template_p) + if (!decl_was_initialized_p) { - if (friend_p) - finish_fully_implicit_template (parser, 0); - else - decl = finish_fully_implicit_template (parser, decl); + decl = grokfield (declarator, &decl_specifiers, + initializer, /*init_const_expr_p=*/true, + asm_specification, attributes); + + if (parser->fully_implicit_function_template_p) + { + if (friend_p) + finish_fully_implicit_template (parser, 0); + else + decl = finish_fully_implicit_template (parser, decl); + } } } @@ -29094,7 +29120,7 @@ cp_parser_member_declaration (cp_parser* parser) assume_semicolon = true; } - if (decl) + if (decl && !decl_was_initialized_p) { /* Add DECL to the list of members. */ if (!friend_p diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 0a7a81b2067..e2e7f29f9ce 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -3018,6 +3018,9 @@ that have additional context. Version 19, which first appeard in G++ 14, fixes manglings of structured bindings to include ABI tags. +Version 20, which first appeared in G++ 15, fixes manglings of lambdas +in static data member initializers. + See also @option{-Wabi}. @opindex fabi-compat-version diff --git a/gcc/testsuite/g++.dg/abi/lambda-ctx2-19.C b/gcc/testsuite/g++.dg/abi/lambda-ctx2-19.C new file mode 100644 index 00000000000..35d394da8c5 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/lambda-ctx2-19.C @@ -0,0 +1,10 @@ +// { dg-do compile { target c++17 } } +// { dg-options -fabi-version=19 } + +#include "lambda-ctx2.h" + +// A and B demangle incorrectly due to static data members missing a lambda scope +// { dg-final { scan-assembler {_ZNK1AUlvE_clEv:} } } +// { dg-final { scan-assembler {_ZNK1BIiEUlvE2_clEv:} } } +// { dg-final { scan-assembler {_ZNK1BIiEUlvE3_clEv:} } } +// { dg-final { scan-assembler {_ZNK1CIiE1xMUlvE_clEv:} } } diff --git a/gcc/testsuite/g++.dg/abi/lambda-ctx2-19vs20.C b/gcc/testsuite/g++.dg/abi/lambda-ctx2-19vs20.C new file mode 100644 index 00000000000..d4662291e0c --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/lambda-ctx2-19vs20.C @@ -0,0 +1,8 @@ +// { dg-do compile { target c++17 } } +// { dg-options "-fabi-version=20 -Wabi=19" } + +#include "lambda-ctx2.h" + +// { dg-regexp {[^\n]*lambda-ctx2.h:[:0-9]* warning: the mangled name of .A::.[^\n]*\n} } +// { dg-regexp {[^\n]*lambda-ctx2.h:[:0-9]* warning: the mangled name of .B::.[^\n]*\n} } +// { dg-regexp {[^\n]*lambda-ctx2.h:[:0-9]* warning: the mangled name of .B::.[^\n]*\n} } diff --git a/gcc/testsuite/g++.dg/abi/lambda-ctx2-20.C b/gcc/testsuite/g++.dg/abi/lambda-ctx2-20.C new file mode 100644 index 00000000000..764f6061876 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/lambda-ctx2-20.C @@ -0,0 +1,10 @@ +// { dg-do compile { target c++17 } } +// { dg-options -fabi-version=20 } + +#include "lambda-ctx2.h" + +// These correctly associate lambdas in A::x and B::x. +// { dg-final { scan-assembler {_ZNK1A1xMUlvE_clEv:} } } +// { dg-final { scan-assembler {_ZNK1BIiE1xMUlvE_clEv:} } } +// { dg-final { scan-assembler {_ZNK1BIiE1xMUlvE0_clEv:} } } +// { dg-final { scan-assembler {_ZNK1CIiE1xMUlvE_clEv:} } } diff --git a/gcc/testsuite/g++.dg/abi/lambda-ctx2.h b/gcc/testsuite/g++.dg/abi/lambda-ctx2.h new file mode 100644 index 00000000000..e359254db90 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/lambda-ctx2.h @@ -0,0 +1,27 @@ +// PR c++/107741 + +void side_effect(); + +struct A { + static constexpr auto x = []{ return 1; }; +}; + +template +struct B { + static inline auto x = (side_effect(), []{ return 2; }(), []{ return 3; }()); +}; + +template +struct C { + static int x; +}; + +template +int C::x = (side_effect(), []{ return 4; }()); + +template int C::x; + +int f() { + A::x(); + return B::x; +} diff --git a/gcc/testsuite/g++.dg/abi/macro0.C b/gcc/testsuite/g++.dg/abi/macro0.C index 183184e0f0a..f6a57c11ae7 100644 --- a/gcc/testsuite/g++.dg/abi/macro0.C +++ b/gcc/testsuite/g++.dg/abi/macro0.C @@ -1,6 +1,6 @@ // This testcase will need to be kept in sync with c_common_post_options. // { dg-options "-fabi-version=0" } -#if __GXX_ABI_VERSION != 1019 +#if __GXX_ABI_VERSION != 1020 #error "Incorrect value of __GXX_ABI_VERSION" #endif diff --git a/gcc/testsuite/g++.dg/abi/mangle74.C b/gcc/testsuite/g++.dg/abi/mangle74.C index 7451ce81495..14fe9b9fbf2 100644 --- a/gcc/testsuite/g++.dg/abi/mangle74.C +++ b/gcc/testsuite/g++.dg/abi/mangle74.C @@ -26,5 +26,5 @@ int thorn () } // { dg-final { scan-assembler "_ZNK3varMUlvE_clEv:" } } -// { dg-final { scan-assembler "_ZNK3Foo3barMUlvE_clEv:" { xfail *-*-* } } } -// { dg-final { scan-assembler-not "_ZNK3FooUlvE_clEv:" { xfail *-*-* } } } +// { dg-final { scan-assembler "_ZNK3Foo3barMUlvE_clEv:" } } +// { dg-final { scan-assembler-not "_ZNK3FooUlvE_clEv:" } } diff --git a/gcc/testsuite/g++.dg/cpp0x/static-member-init-1.C b/gcc/testsuite/g++.dg/cpp0x/static-member-init-1.C new file mode 100644 index 00000000000..e64e77faade --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/static-member-init-1.C @@ -0,0 +1,5 @@ +// { dg-do compile { target c++11 } } + +struct S { + static constexpr const void* x = &x; +}; diff --git a/gcc/testsuite/g++.dg/other/fold1.C b/gcc/testsuite/g++.dg/other/fold1.C index 8d8df3de68e..d2fc518c220 100644 --- a/gcc/testsuite/g++.dg/other/fold1.C +++ b/gcc/testsuite/g++.dg/other/fold1.C @@ -3,6 +3,6 @@ struct A { - static const int i = i; // { dg-error "not declared" } + static const int i = j; // { dg-error "not declared" } int x[i]; // { dg-error "11:size of array .x. is not an integral constant-expression" } }; From patchwork Mon Jan 6 12:21:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 104166 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 97E97385840C for ; Mon, 6 Jan 2025 12:24:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97E97385840C Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Er2DhzBd X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id 81B183858D38 for ; Mon, 6 Jan 2025 12:22:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 81B183858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 81B183858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736166139; cv=none; b=TDt3zKweStp2+VEdv587eT15VCkQ1n4QDxVEZhapmwHxua7Ix7x0x7PxJ4s/8Nvhd/yfdjYpyLCwMHRaARXuNO/qjoRQL07cIv+jgJbR2SxZ779BMEBSW2tyH4cn/ew29jiE9GSmgue0GvcxpzPMzxsUDshWsmExQQvMt/vjVPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736166139; c=relaxed/simple; bh=IM/4l3vuHT0KCz1yAOCKAhvHZwOnHSpM6R6trqkNwe0=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=vTNRbGEtUTuemO+TfaeBhxhGjFa8tBz6oLOKMfOXrk0Z2/Kj8V0wi/jrgO/97/CTd2GBoBzBIT+Bo/61ULnb9o1sBNBfTAnqCJF+a8iwAcuAjvfNYMV/EMDaJFkOREnOcZlNiNEtXaubnnfccMTjoCYQgb1jv6a1HpPvvRLeoxk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2f440e152fdso3043605a91.0 for ; Mon, 06 Jan 2025 04:22:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736166112; x=1736770912; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=TyHnRAGKNRokBPyuAiGDptaqWff/ySzxd5umRhEBN2A=; b=Er2DhzBd+k85xRAtxOWEvnbg9OWYXdngjZ511foplJI3Fk7HvP9XBkducdS6JHanMh f/LqY7GAHlTP/V4Yn0/w1/vEqwNYoTGITi1d+mPToIawgkhEjPSCb2itbMK2h2b6Ujt8 OKeVBE2hyGn8gtMAyzydgq1TYykK3h0j/NdboW/U/BTK3eAvNxyKxyAoY7OkSdrFdMvA Nzw/cIf0/13xXnJNPDVpXih7uQezWE53XDaqslDXiD0IqsOSrcaC+wP6lxCr/tWvWEui 4/+2BxBlHoeHsT2S7d8hYV6BXTILwQf3CPxzLwrMFNH96c+Lz8CQcZYp7KaGxZ4ElPHU fwqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736166112; x=1736770912; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TyHnRAGKNRokBPyuAiGDptaqWff/ySzxd5umRhEBN2A=; b=MPFxwY4gcNsZl7AwqRfDqg46UUzzkN2YOaEQ/1cSZRUUBbbrYTug6CuZxdKgU78cWr k4WOiP9w71zRC54F8rRLve+pYwZ3rguqE7MGUSHDHoTacvDlV3IuWBrsr0V8+qQxMOpZ Q/OM6VV00dJHjbc7Iihvf5rtHz9MV3g1f2C9BT51cuvIULFNdzzjkktEm+j2Wtul8LoG L6xr5Fbc+e6NIF/UgwEPspC3o2SJHA2HjdgK5Zof4ezwLUQp/FvBaILF88zT0HyQJ6r9 qn1cRdWMLGUfYgyH3YT4hwrsW7mL8A4JacRyWuiG+s3leSCIhYRfHYK/MJ1drfP8m8gU 9/AQ== X-Gm-Message-State: AOJu0Yz/mekYGGwpr9Dz6qemTREvDXOWH5od/PZNNNazgbbaRR96o0bd bl9u9KtKMi3wrjbyP8OPrR1ArnGFyTCXUNmKNYbKVjltAz09/hs9mg0S2g== X-Gm-Gg: ASbGncs/LHXt3IN9ydtx3tv0AZiLb2j/U6f3ZYQkbX4DQ/84ROdfTMW6CLlcsqLWM+0 i+sLHfl5j2T71BsL4NPEe8BPAOSCbPmnymkvT3TzsXJQVrege1DacCg0gN0F95quirQgwr/nwKI BK8c0FMsFr8ysp17p2SvGt+WASJGafUNQT4JpDHfrmz98Y0m8YXL9bPXtnhGCrEeoiEFkcD4gE+ qiPDGcTW1wZe3zcJ/3U6mLK+AjnioqK+KmahXqK/9cXAjNkhB3sHmU2NlUPvcYrlrymHEr+iauZ 8AdpeKYLXL9DdzMNuZsS2g== X-Google-Smtp-Source: AGHT+IE4VIxDkk4ESYBAZqZUvKgkRX0bHmYLejI84oFEVqaDIpwS67qi9p0ZgKjfGF4C5fiolccKFQ== X-Received: by 2002:a05:6a00:10cb:b0:727:3c8f:36fb with SMTP id d2e1a72fcca58-72abe051630mr32157864b3a.7.1736166112217; Mon, 06 Jan 2025 04:21:52 -0800 (PST) Received: from Thaum. (163-47-68-2.ipv4.originbroadband.com.au. [163.47.68.2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad90c149sm31263578b3a.191.2025.01.06.04.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 04:21:51 -0800 (PST) Message-ID: <677bcadf.620a0220.3667ef.5712@mx.google.com> X-Google-Original-Message-ID: Date: Mon, 6 Jan 2025 23:21:47 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH v3 2/6] c++: Fix mangling of otherwise unattached class-scope lambdas [PR118245] References: <677bca93.050a0220.33acbc.5415@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <677bca93.050a0220.33acbc.5415@mx.google.com> X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Something like this should probably be backported to GCC 14 too, since my change in r14-9232-g3685fae23bb008 inadvertantly caused ICEs that this fixes. But without the previous patch this patch will cause ABI changes, and I'm not sure how easily it would be to divorce those changes from the fix here. I suppose probably the true issue is that r14-9232 inadvertantly changed ABI for lambdas in base classes, and we should just revert the parser.cc changes for 14.3? (And accept that it'll regress those modules tests.) -- >8 -- This is a step closer to implementing the suggested changes for https://github.com/itanium-cxx-abi/cxx-abi/pull/85. Most lambdas defined within a class should have an extra scope of that class so that uses across different TUs are properly merged by the linker. This also needs to happen during template instantiation. While I was working on this I found some other cases where the mangling of lambdas was incorrect and causing issues, notably the testcase lambda-ctx3.C which currently emits the same mangling for the base class and member lambdas, causing mysterious assembler errors since r14-9232. This is also the root cause of PR c++/118245. One notable case not handled either here or in the ABI is what is supposed to happen with lambdas declared in alias templates; see lambda-ctx4.C. I believe that by the C++ standard, such lambdas should also dedup across TUs, but this isn't currently implemented (for class-scope or not). I wasn't able to work out how to fix the mangling logic for this case easily so I've just excluded alias templates from the class-scope mangling rules in template instantiation. Since this should only affect usage of lambdas in unevaluated contexts (a C++20 feature) this patch does not add an ABI flag to control this behaviour. PR c++/118245 gcc/cp/ChangeLog: * cp-tree.h (LAMBDA_EXPR_EXTRA_SCOPE): Adjust comment. * parser.cc (cp_parser_class_head): Start (and do not finish) lambda scope for all valid types. (cp_parser_class_specifier): Finish lambda scope after parsing members instead. (cp_parser_member_declaration): Adjust comment to mention missing lambda scoping for static member initializers. * pt.cc (instantiate_class_template): Add lambda scoping. (instantiate_template): Likewise. gcc/testsuite/ChangeLog: * g++.dg/abi/lambda-ctx3.C: New test. * g++.dg/abi/lambda-ctx4.C: New test. * g++.dg/cpp2a/lambda-uneval20.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/cp-tree.h | 3 ++- gcc/cp/parser.cc | 23 ++++++++++++-------- gcc/cp/pt.cc | 14 +++++++++++- gcc/testsuite/g++.dg/abi/lambda-ctx3.C | 21 ++++++++++++++++++ gcc/testsuite/g++.dg/abi/lambda-ctx4.C | 22 +++++++++++++++++++ gcc/testsuite/g++.dg/cpp2a/lambda-uneval20.C | 7 ++++++ 6 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/abi/lambda-ctx3.C create mode 100644 gcc/testsuite/g++.dg/abi/lambda-ctx4.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-uneval20.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index f77a325bdd0..824b7bb61ae 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1562,7 +1562,8 @@ enum cp_lambda_default_capture_mode_type { (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->locus) /* The mangling scope for the lambda: FUNCTION_DECL, PARM_DECL, VAR_DECL, - FIELD_DECL or NULL_TREE. If this is NULL_TREE, we have no linkage. */ + FIELD_DECL, TYPE_DECL, or NULL_TREE. If this is NULL_TREE, we have no + linkage. */ #define LAMBDA_EXPR_EXTRA_SCOPE(NODE) \ (((struct tree_lambda_expr *)LAMBDA_EXPR_CHECK (NODE))->extra_scope) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index dd986444449..c851185a86d 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -27313,6 +27313,8 @@ cp_parser_class_specifier (cp_parser* parser) if (!braces.require_open (parser)) { pop_deferring_access_checks (); + if (type != error_mark_node) + finish_lambda_scope (); return error_mark_node; } @@ -27377,7 +27379,10 @@ cp_parser_class_specifier (cp_parser* parser) if (cp_parser_allow_gnu_extensions_p (parser)) attributes = cp_parser_gnu_attributes_opt (parser); if (type != error_mark_node) - type = finish_struct (type, attributes); + { + type = finish_struct (type, attributes); + finish_lambda_scope (); + } if (nested_name_specifier_p) pop_inner_scope (old_scope, scope); @@ -28217,6 +28222,12 @@ cp_parser_class_head (cp_parser* parser, if (flag_concepts) type = associate_classtype_constraints (type); + /* Lambdas in bases and members must have the same mangling scope for ABI. + We open this scope now, and will close it in cp_parser_class_specifier + after parsing the member list. */ + if (type && type != error_mark_node) + start_lambda_scope (TYPE_NAME (type)); + /* We will have entered the scope containing the class; the names of base classes should be looked up in that context. For example: @@ -28231,16 +28242,10 @@ cp_parser_class_head (cp_parser* parser, if (cp_lexer_next_token_is (parser->lexer, CPP_COLON)) { if (type) - { - pushclass (type); - start_lambda_scope (TYPE_NAME (type)); - } + pushclass (type); bases = cp_parser_base_clause (parser); if (type) - { - finish_lambda_scope (); - popclass (); - } + popclass (); } else bases = NULL_TREE; diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index dfaa8906a2c..cb234b53a55 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -12604,6 +12604,10 @@ instantiate_class_template (tree type) gcc_assert (!DECL_CLASS_SCOPE_P (TYPE_MAIN_DECL (pattern)) || COMPLETE_OR_OPEN_TYPE_P (TYPE_CONTEXT (type))); + /* When instantiating nested lambdas, ensure that they get the mangling + scope of the new class type. */ + start_lambda_scope (TYPE_NAME (type)); + base_list = NULL_TREE; /* Defer access checking while we substitute into the types named in the base-clause. */ @@ -12965,6 +12969,8 @@ instantiate_class_template (tree type) finish_struct_1 (type); TYPE_BEING_DEFINED (type) = 0; + finish_lambda_scope (); + /* Remember if instantiating this class ran into errors, so we can avoid instantiating member functions in limit_bad_template_recursion. We set this flag even if the problem was in another instantiation triggered by @@ -22530,6 +22536,8 @@ instantiate_template (tree tmpl, tree orig_args, tsubst_flags_t complain) ctx = tsubst_entering_scope (DECL_CONTEXT (gen_tmpl), targ_ptr, complain, gen_tmpl); push_nested_class (ctx); + if (!DECL_ALIAS_TEMPLATE_P (gen_tmpl)) + start_lambda_scope (TYPE_NAME (ctx)); } tree pattern = DECL_TEMPLATE_RESULT (gen_tmpl); @@ -22559,7 +22567,11 @@ instantiate_template (tree tmpl, tree orig_args, tsubst_flags_t complain) if (fndecl == NULL_TREE) fndecl = tsubst_decl (pattern, targ_ptr, complain, /*use_spec_table=*/false); if (DECL_CLASS_SCOPE_P (gen_tmpl)) - pop_nested_class (); + { + if (!DECL_ALIAS_TEMPLATE_P (gen_tmpl)) + finish_lambda_scope (); + pop_nested_class (); + } pop_from_top_level (); if (fndecl == error_mark_node) diff --git a/gcc/testsuite/g++.dg/abi/lambda-ctx3.C b/gcc/testsuite/g++.dg/abi/lambda-ctx3.C new file mode 100644 index 00000000000..f92f2500531 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/lambda-ctx3.C @@ -0,0 +1,21 @@ +// { dg-do compile { target c++20 } } +// { dg-additional-options "-fkeep-inline-functions" } +// See also https://github.com/itanium-cxx-abi/cxx-abi/pull/85 + +struct A { + decltype([]{ return 1; }) f; +}; + +struct B : decltype([]{ return 2; }) { + decltype([]{ return 3; }) f; +}; + +struct C : decltype([]{ return 4; }) { + decltype([]{ return 5; }) f; +}; + +// { dg-final { scan-assembler {_ZNK1AUlvE_clEv:} } } +// { dg-final { scan-assembler {_ZNK1BUlvE_clEv:} } } +// { dg-final { scan-assembler {_ZNK1BUlvE0_clEv:} } } +// { dg-final { scan-assembler {_ZNK1CUlvE_clEv:} } } +// { dg-final { scan-assembler {_ZNK1CUlvE0_clEv:} } } diff --git a/gcc/testsuite/g++.dg/abi/lambda-ctx4.C b/gcc/testsuite/g++.dg/abi/lambda-ctx4.C new file mode 100644 index 00000000000..d6544a84652 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/lambda-ctx4.C @@ -0,0 +1,22 @@ +// { dg-do compile { target c++20 } } +// { dg-additional-options "-fkeep-inline-functions" } + +struct S { + template + using T = decltype([]{ return I; }); +}; + +S::T<0> a; +S::T<1> b; + +int main() { + a(); + b(); +} + +// Currently we don't implement any special mangling rules for template aliases +// (though we probably should; an alias template is a definable item by +// [basic.def.odr] p1.5 and as such contained lambdas in different TUs should have +// the same type, see [basic.def.odr] p15.6) +// { scan_assembler {_ZNK1SUlvE_clEv:} } +// { scan_assembler {_ZNK1SUlvE0_clEv:} } diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-uneval20.C b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval20.C new file mode 100644 index 00000000000..fa009f53ff2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval20.C @@ -0,0 +1,7 @@ +// PR c++/118245 +// { dg-do compile { target c++20 } } + +template struct Cask {}; +struct T1 : Cask<[]{}> { + Cask<[]{}> c{}; +}; From patchwork Mon Jan 6 12:22:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 104163 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C939E3858C32 for ; Mon, 6 Jan 2025 12:23:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 824C43858CD1 for ; Mon, 6 Jan 2025 12:22:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 824C43858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 824C43858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::632 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736166168; cv=none; b=hoa8AsjpRd5pWAyygoWu/3LtbuU1eEh+SGD7ZvRv6i2kxmtgiKfEAJeSKeE6lo9phP6b7Qc7KaPOdmLe5nK/QrIbgHvX10Dm6w4ysDyr7L5gbykOzNh+Hy86PTMCcrDE57/aaums2ILsbPJ84UliT27taok3cQgkgvLVykfHYFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736166168; c=relaxed/simple; bh=B1qwoKzmU7lQsBifl/3JCiXSTgJ/n/IPbL2JilS/A/Y=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=RcN9MnD+PFFZNrPeYlEyGUnLPD1aZC5PPx1qYQlBuUl9T143EDJwLn2JsC1PwP3iGJG3HItvUlZdxCRu7bgVe9eY6hbUZ5jToAgoXnpnOLGsOPo7xr/CJ1KaB0bYlh0fyqLXQcqubIb/ADfM/qX0fZG10QQEwzNap3QeA+0bT5w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2162699e0ccso21160715ad.0 for ; Mon, 06 Jan 2025 04:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736166157; x=1736770957; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=dUcVlLitGLue6T8OKOum2YYVtG9hZ+7IiKvqLqKoDwA=; b=RnZIFn7cSJiCduRYmOzRNQTAcGKlA2/CigPRit5xcscmXjgKLiKSZob425OrDtPwlz uzKaXA1YnQlAYa8WrlJ6WlANlBCx1XksBE0MVZT57vH1qCHAwlXm0+OAH27CrHlI/aMy DscndGfKI3yiIXGzeJ/KZ62samOoTamAip0/aFOmMZr4mutnBbYaqZmwCdaurt4gwYzY BVdrhgC8hcYJFSX8aWj93YPo2ZdLXrTQKKKS6n2R7cAEwb8gOElgxNjtZPb/yA1mb6zt mpRT/+FFlGSj2E9LW8xANu19UbCLtw5zFLWvz8IfUO7ErWh+W7vvDCeTC1jHKUY4Fm/U sDxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736166157; x=1736770957; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=dUcVlLitGLue6T8OKOum2YYVtG9hZ+7IiKvqLqKoDwA=; b=ZeWTN/UgRUNk893HWufhJ2pK+depLrGz1rMIe0aP4Rd4MbUwwBST1OgeiGNFgTaY+m Ka+MNq88i2kXslTmWeogaylnje1ny/WCmEYMXLmU2reZrH3qsc9LVtutuBl5fMQFCfKo wqzYORXt6pZqV64TYUDuQ62yGnpBQmZ4rKwfwa03XeUEGWNMLrDTniO27dVL2YSOuLZ2 GynC2TiGt0JowPM40e7jCDVfnnuOxLYgDWF/W2BziCjG1wz6yy7ybEFyxvZUid1RA7GI rrZFlnPigIcObk91GopQ0KnRZeP1rmVHvELtACIpIdYEIvdE8FRAlY5YL/RbN/PulpmE paZA== X-Gm-Message-State: AOJu0YyN6nB9H8G4SVwF/109J7axAFmhVfGS5gnf+cJW2RuNCqlryKRa Uv2gjG2RB6v+4VX21VHzot98vKTchXK9m3JGQFujNCKqrmuTrwiOVxo5pw== X-Gm-Gg: ASbGncvrvPuHU4bQ0Go34t+sQN3dgVO0CgB+eTO/I+/C+ME5bBY5yoPpUkCteeU2vU9 qWC97YjVaardjb7ut1YzQkpPzNVgzoVPkZY7cU6S75dllKRdb7lcAeZq/iE5BXIS2Jvk3M3byQn u5IZHpE/tzb/A4rIhJ6rjOu9BJe+SSnvD6vP/Eq3pTrtOBb3X4jrMIr4Y2v5ezG3qQZMmqk1Koa ldv29UWqduJK9DRbuAtr52nIqgpOfWoK7tJJVQJtOD8iU1Q6DTbP3uL7VbgAYs/OLtcIZYYHpvu /2TYCfMLYYPVcej637xpYA== X-Google-Smtp-Source: AGHT+IGmVnrGqmjJH7oNphAnX+Twew3GYnPfLxaxado1nved/WA0/1/dHgmpNxhc/2sg3wnimnxQLA== X-Received: by 2002:a17:902:d510:b0:216:6db1:1a70 with SMTP id d9443c01a7336-219e6e84532mr309815255ad.3.1736166157008; Mon, 06 Jan 2025 04:22:37 -0800 (PST) Received: from Thaum. (163-47-68-2.ipv4.originbroadband.com.au. [163.47.68.2]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc7ec98asm293647685ad.0.2025.01.06.04.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 04:22:36 -0800 (PST) Message-ID: <677bcb0c.170a0220.3b0b63.0c69@mx.google.com> X-Google-Original-Message-ID: Date: Mon, 6 Jan 2025 23:22:32 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH v3 3/6] c++: Fix ABI for lambdas declared in alias templates [PR116568] References: <677bca93.050a0220.33acbc.5415@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <677bca93.050a0220.33acbc.5415@mx.google.com> X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org I'm not 100% sure I've handled this properly, any feedback welcome. In particular, maybe should I use `DECL_IMPLICIT_TYPEDEF_P` in the mangling logic instead of `!TYPE_DECL_ALIAS_P`? They both seem to work in this case but not sure which would be clearer. I also looked into trying do a limited form of 'start_decl' before parsing the type but there were too many circular dependencies for me to work through, so I think any such changes would have to wait till GCC16 (if they're even possible at all). -- >8 -- This adds mangling support for lambdas with a mangling context of an alias template, and gives that context when instantiating such a lambda. This only currently works for class-scope alias templates, however, due to the if (LAMBDA_EXPR_EXTRA_SCOPE (t)) record_lambda_scope (r); condition in 'tsubst_lambda_scope'. For namespace-scope alias templates, we can't easily add the mangling context: we can't build the TYPE_DECL to record against until after we've parsed the type (and already recorded lambda scope), as `start_decl` relies on the type being passed in correctly, and setting the mangling scope after parsing is too late because e.g. 'template_class_depth' (called from grokfndecl when building the lambda functions while parsing the type) relies on the LAMBDA_EXPR_EXTRA_SCOPE already being properly set. This will also likely matter for 'determine_visibility'. I'm not sure what a good way to break this recursive dependency is. This change also requires a slight adjustment to the late-ret-3 testcase, as changing the order of creating the node for the alias adjusted the tiebreak sorting of cluster members when logging. PR c++/116568 gcc/cp/ChangeLog: * mangle.cc (maybe_template_info): Support getting template info of alias templates. (canonicalize_for_substitution): Don't canonicalise aliases. (decl_mangling_context): Don't treat aliases as lambda closure types. (write_unqualified_name): Likewise. * pt.cc (tsubst_decl): Start lambda scope for alias templates. (instantiate_template): No longer need to special case alias templates here. gcc/testsuite/ChangeLog: * g++.dg/abi/lambda-ctx4.C: Adjust mangling, include namespace scope alias templates (XFAILed for now). * g++.dg/modules/late-ret-3_a.H: Adjust cluster order. Signed-off-by: Nathaniel Shead --- gcc/cp/mangle.cc | 13 +++++++----- gcc/cp/pt.cc | 23 +++++++++------------ gcc/testsuite/g++.dg/abi/lambda-ctx4.C | 21 ++++++++++++------- gcc/testsuite/g++.dg/modules/late-ret-3_a.H | 2 +- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc index 170dafd52c1..9d457e2a2f3 100644 --- a/gcc/cp/mangle.cc +++ b/gcc/cp/mangle.cc @@ -292,7 +292,7 @@ abi_check (int ver) static tree maybe_template_info (const tree decl) { - if (TREE_CODE (decl) == TYPE_DECL) + if (TREE_CODE (decl) == TYPE_DECL && !TYPE_DECL_ALIAS_P (decl)) { /* TYPE_DECLs are handled specially. Look at its type to decide if this is a template instantiation. */ @@ -305,7 +305,7 @@ maybe_template_info (const tree decl) { /* Check if the template is a primary template. */ if (DECL_LANG_SPECIFIC (decl) != NULL - && VAR_OR_FUNCTION_DECL_P (decl) + && (VAR_OR_FUNCTION_DECL_P (decl) || TREE_CODE (decl) == TYPE_DECL) && DECL_TEMPLATE_INFO (decl) && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))) return DECL_TEMPLATE_INFO (decl); @@ -402,8 +402,8 @@ write_exception_spec (tree spec) static inline tree canonicalize_for_substitution (tree node) { - /* For a TYPE_DECL, use the type instead. */ - if (TREE_CODE (node) == TYPE_DECL) + /* For a non-alias TYPE_DECL, use the type instead. */ + if (TREE_CODE (node) == TYPE_DECL && !TYPE_DECL_ALIAS_P (node)) node = TREE_TYPE (node); if (TYPE_P (node) && TYPE_CANONICAL (node) != node @@ -1044,6 +1044,7 @@ decl_mangling_context (tree decl) decl = DECL_TEMPLATE_RESULT (decl); if (TREE_CODE (decl) == TYPE_DECL + && !TYPE_DECL_ALIAS_P (decl) && LAMBDA_TYPE_P (TREE_TYPE (decl))) { tree extra = LAMBDA_TYPE_EXTRA_SCOPE (TREE_TYPE (decl)); @@ -1588,7 +1589,9 @@ write_unqualified_name (tree decl) if (TREE_CODE (decl) == TYPE_DECL && TYPE_UNNAMED_P (type)) write_unnamed_type_name (type); - else if (TREE_CODE (decl) == TYPE_DECL && LAMBDA_TYPE_P (type)) + else if (TREE_CODE (decl) == TYPE_DECL + && !TYPE_DECL_ALIAS_P (decl) + && LAMBDA_TYPE_P (type)) write_closure_type_name (type); else write_source_name (DECL_NAME (decl)); diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index cb234b53a55..cba7b97ef70 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -15753,6 +15753,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain, } /* Create a new node for the specialization we need. */ + r = copy_decl (t); if (type == NULL_TREE) { if (is_typedef_decl (t)) @@ -15766,19 +15767,17 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain, tsubst_flags_t tcomplain = complain; if (VAR_P (t)) tcomplain |= tf_tst_ok; + bool is_alias + = (is_typedef_decl (t) + && alias_template_specialization_p (TREE_TYPE (t), nt_opaque)); + if (is_alias) + start_lambda_scope (r); type = tsubst (type, args, tcomplain, in_decl); - /* Substituting the type might have recursively instantiated this - same alias (c++/86171). */ - if (use_spec_table && gen_tmpl && DECL_ALIAS_TEMPLATE_P (gen_tmpl) - && (spec = retrieve_specialization (gen_tmpl, argvec, hash))) - { - r = spec; - break; - } + if (is_alias) + finish_lambda_scope (); } if (type == error_mark_node && !(complain & tf_error)) RETURN (error_mark_node); - r = copy_decl (t); if (VAR_P (r)) { DECL_INITIALIZED_P (r) = 0; @@ -22536,8 +22535,7 @@ instantiate_template (tree tmpl, tree orig_args, tsubst_flags_t complain) ctx = tsubst_entering_scope (DECL_CONTEXT (gen_tmpl), targ_ptr, complain, gen_tmpl); push_nested_class (ctx); - if (!DECL_ALIAS_TEMPLATE_P (gen_tmpl)) - start_lambda_scope (TYPE_NAME (ctx)); + start_lambda_scope (TYPE_NAME (ctx)); } tree pattern = DECL_TEMPLATE_RESULT (gen_tmpl); @@ -22568,8 +22566,7 @@ instantiate_template (tree tmpl, tree orig_args, tsubst_flags_t complain) fndecl = tsubst_decl (pattern, targ_ptr, complain, /*use_spec_table=*/false); if (DECL_CLASS_SCOPE_P (gen_tmpl)) { - if (!DECL_ALIAS_TEMPLATE_P (gen_tmpl)) - finish_lambda_scope (); + finish_lambda_scope (); pop_nested_class (); } pop_from_top_level (); diff --git a/gcc/testsuite/g++.dg/abi/lambda-ctx4.C b/gcc/testsuite/g++.dg/abi/lambda-ctx4.C index d6544a84652..809cace8574 100644 --- a/gcc/testsuite/g++.dg/abi/lambda-ctx4.C +++ b/gcc/testsuite/g++.dg/abi/lambda-ctx4.C @@ -1,5 +1,4 @@ // { dg-do compile { target c++20 } } -// { dg-additional-options "-fkeep-inline-functions" } struct S { template @@ -9,14 +8,22 @@ struct S { S::T<0> a; S::T<1> b; +template +using L = decltype([]{ return I; }); + +L<0> c; +L<1> d; + int main() { a(); b(); + c(); + d(); } -// Currently we don't implement any special mangling rules for template aliases -// (though we probably should; an alias template is a definable item by -// [basic.def.odr] p1.5 and as such contained lambdas in different TUs should have -// the same type, see [basic.def.odr] p15.6) -// { scan_assembler {_ZNK1SUlvE_clEv:} } -// { scan_assembler {_ZNK1SUlvE0_clEv:} } +// { dg-final { scan-assembler {_ZNK1S1TILi0EEUlvE_clEv:} } } +// { dg-final { scan-assembler {_ZNK1S1TILi1EEUlvE_clEv:} } } + +// namespace-scope aliases don't have LAMBDA_EXPR_EXTRA_CONTEXT properly set +// { dg-final { scan-assembler {_ZNK1LILi0EEUlvE_clEv:} { xfail *-*-* } } } +// { dg-final { scan-assembler {_ZNK1LILi1EEUlvE_clEv:} { xfail *-*-* } } } diff --git a/gcc/testsuite/g++.dg/modules/late-ret-3_a.H b/gcc/testsuite/g++.dg/modules/late-ret-3_a.H index 54f95db0456..e64a6f340c0 100644 --- a/gcc/testsuite/g++.dg/modules/late-ret-3_a.H +++ b/gcc/testsuite/g++.dg/modules/late-ret-3_a.H @@ -17,4 +17,4 @@ auto Bar (const A& arg) -> TPL_3::type> {return 3;} -// { dg-final { scan-lang-dump { Cluster members:\n \[0\]=decl definition '::template Foo'\n \[1\]=specialization declaration '::TPL_1<#null#>'\n \[2\]=specialization declaration '::TPL_3<::TPL_1<#null#>::type>'\n \[3\]=specialization declaration '::TPL_2<::TPL_1<#null#>::type>'\n \[4\]=binding '::Foo'\n} module } } +// { dg-final { scan-lang-dump { Cluster members:\n \[0\]=decl definition '::template Foo'\n \[1\]=specialization declaration '::TPL_3<::TPL_1<#null#>::type>'\n \[2\]=specialization declaration '::TPL_1<#null#>'\n \[3\]=specialization declaration '::TPL_2<::TPL_1<#null#>::type>'\n \[4\]=binding '::Foo'\n} module } } From patchwork Mon Jan 6 12:23:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 104165 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A518385840C for ; Mon, 6 Jan 2025 12:24:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 86C923858023 for ; Mon, 6 Jan 2025 12:23:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 86C923858023 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 86C923858023 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736166216; cv=none; b=h1XjRJ+AeJEk79YhxbkVfJkVobMwK99A5oBeew+BEvJ0AvdE3AykIQwa5VTP+yrAfYRfGwyA1P/oWyz9KA67BoAvTs5zm+dtIcmFtW4itJeNfDY3sjw696Tf4kVzwmBIhMJ0cR8ZFKVO56Wvi8Z7nEE356wlvcpE6q1EXMpZsmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736166216; c=relaxed/simple; bh=Kzygf+SLvBHDt+qtYtJyyN6/9tMGC1iMCmJfpIcfs+8=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=KSLOmG20v+bFZtgFm92DFuAevWp3CXPCs8Pao8QA772RYePvhfF/cvyuJ5/gJd061yblEg9v5i/ZzMXPTBVok4LxSlztmgQvl8vzg7eaTluhERdUMmwcC5Hs4BYjqdHJHEvmNXI8fyRlBKgONNUaL1KtGLUWvl6QhdffpGPOYog= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-21a0374a1fcso16890935ad.2 for ; Mon, 06 Jan 2025 04:23:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736166209; x=1736771009; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=6bDescJ/7dhIzmaUflIPtiJDM9ZUdimlOzU23lRTLI4=; b=fwfr+pTb3JGiZQvRa3EdhCFHUC86/EjQmfb0CJ0mvj4AODBX9TBedycyeLII5huVqr haq+C2uxr9gWYnAXAgf4WUCgejxDCBoP1MWVg/6i98yqy3qEXgRfFu92JkW2CkLDDDB6 OWO1h5fxMmTzLiK2yRfqiEIlczyhmsln4ZBkDTko/ir/KkLLi2Ryj0XP6TG77xH4oyoX 3NQdE2wZXiEpEwvDloaYPSCpV4rOaXJGsHhOLkcAOTigS4PZVrkXd/EIGdjEvzw3+dOC qd+aEYXW/CXWWs7ifwv09L1huKz9pGNUmRr3IIarBnB2Hd3LRQNUXV3wvCK2NVvch0dp N0Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736166209; x=1736771009; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6bDescJ/7dhIzmaUflIPtiJDM9ZUdimlOzU23lRTLI4=; b=Q8FC3Pg0bW8UeqwzcVUFM4qei04VZMI+JR1ffenogpUGXeO7uPE0g2d5F3wgBtktGj km0XzniB4cZcvj7iKrDzE1rrljV7u2C+W+GPPw9wxtrvn4SP4kVpjQY+mKqHgOc8AHvr Y61/bNdD6UvVdsbEcmM3Rdf3RI0POM9x6IVTLPaapdfWW/qycUF99qpAYVpnp26NSyHZ 4I/+6knMgvZxsQqlkNuBFpAaISTC7vNHziPT7yd40gHeeGg0L3yoK97F3y2NF9e9YCa+ lLL8yzsfn/yfRdsUWwjwHGgxSKCEFds0LHfkOH1o2vrXzwOLaWeSDyGQ+HNmVHnhNJoV m4Pw== X-Gm-Message-State: AOJu0YwsjWLrEW2SvqpdUc/LCmI0L+D0myCRHcP8uTQ58Z1s61Ia+VZF 8DbO1TIzOg8CIKL6nbctQiJLS/BLatkZTcway3hnMDFBl6SnTH/FAn2/Ig== X-Gm-Gg: ASbGncu14dE0zzsJa8ZJyh599oHL/4zGfFJX5P5km6AIUKK8FbeHYUNR0f6sCaheVGr Tc3c38ELBef5eZ/YSAFLLijPzDNE+MqBA4jEZdewvakCMAOH0khAq4Trt1RyHstgnSo4zI5EzUt 1RBOapZM/+Y8yFyosXjeFhEe4Df+0YOZsC8hOEaTsLhwBnprtjLY2eWf578F3p4cqkQnMmSamcM Z2savjIulwgogZpK7/STLfQ6V5l88ZqwYSomnZscljnJHVOK2ZYiSD0LsDQCGihst/IaYWngEKH 18RwMFkydZdIu8JBZshz3A== X-Google-Smtp-Source: AGHT+IGpB9KnYSWlU+aLAohPYk4HOzDUacEXADEPlpYbmKUYEPF5Z/gRD/vg5u6Z01cqICWD8P61Zg== X-Received: by 2002:a17:902:db07:b0:215:2bfb:3cd7 with SMTP id d9443c01a7336-219e6f0982cmr301527355ad.10.1736166209327; Mon, 06 Jan 2025 04:23:29 -0800 (PST) Received: from Thaum. (163-47-68-2.ipv4.originbroadband.com.au. [163.47.68.2]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc96eb40sm291526555ad.86.2025.01.06.04.23.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 04:23:28 -0800 (PST) Message-ID: <677bcb40.170a0220.24b8d0.1211@mx.google.com> X-Google-Original-Message-ID: Date: Mon, 6 Jan 2025 23:23:24 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH v3 4/6] c++: Update mangling of lambdas in expressions References: <677bca93.050a0220.33acbc.5415@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <677bca93.050a0220.33acbc.5415@mx.google.com> X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org https://github.com/itanium-cxx-abi/cxx-abi/pull/85 clarifies that mangling a lambda expression should use 'L' rather than "tl". This only affects C++20 (and later) so no ABI flag is given. gcc/cp/ChangeLog: * mangle.cc (write_expression): Update mangling for lambdas. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/lambda-generic-mangle1.C: Update mangling. * g++.dg/cpp2a/lambda-generic-mangle1a.C: Likewise. Signed-off-by: Nathaniel Shead --- gcc/cp/mangle.cc | 2 +- gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1.C | 2 +- gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1a.C | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc index 9d457e2a2f3..e2e8fb2c71b 100644 --- a/gcc/cp/mangle.cc +++ b/gcc/cp/mangle.cc @@ -3769,7 +3769,7 @@ write_expression (tree expr) equivalent. So just use the closure type mangling. */ - write_string ("tl"); + write_char ('L'); write_type (LAMBDA_EXPR_CLOSURE (expr)); write_char ('E'); } diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1.C index 0051307f53d..306959a4f9f 100644 --- a/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1.C +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1.C @@ -6,4 +6,4 @@ struct C { void f(decltype([](T, auto) { return 0; })) {} }; void g() { C().f({}); } -// { dg-final { scan-assembler "_ZN1C1fIiEEvDTtlNS_UlT_TL0__E_EEE" } } +// { dg-final { scan-assembler "_ZN1C1fIiEEvDTLNS_UlT_TL0__E_EEE" } } diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1a.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1a.C index dc7b0125631..b7bd4ecdd46 100644 --- a/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1a.C +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic-mangle1a.C @@ -7,4 +7,4 @@ struct C { void f(decltype([](T, auto) { return 0; })) {} }; void g() { C().f({}); } -// { dg-final { scan-assembler "_ZN1C1fIiEEvDTtlNS_UlT_T_E_EEE" } } +// { dg-final { scan-assembler "_ZN1C1fIiEEvDTLNS_UlT_T_E_EEE" } } From patchwork Mon Jan 6 12:23:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 104168 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89C0C3858C33 for ; Mon, 6 Jan 2025 12:27:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89C0C3858C33 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Kyw6KGT/ X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 83C10385842A for ; Mon, 6 Jan 2025 12:24:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83C10385842A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 83C10385842A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::636 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736166247; cv=none; b=coWqr/i07dWh45f47wN4O2l4jlOAyki9R0yYyRMSfq7N31si2lLVaTmJLqX/IUEg9f8shbvj3BSNmSY/IQjvp0zKxdlieIsvhPlKtQIYeS9SchYlurhvFBK4U6l9UFtvmVTohL7B3mFctStEzcvZVHsQOWF5Vy6nTBgKkCNTtrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736166247; c=relaxed/simple; bh=aAu1guWeT6Odk9Um+5hyd8y9R4sj3iWS8QpQT5Xs8LY=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=azeeojlohSkJhKAZvL6682JZh5/XTdm9iml4iRf+AfGVXhwDsmYvjDx3Bud775pgqoSqJzk/48F1kfo0oqz0oHsGoZP+Y5uw9xTKISzkVG4AGSHqnanxUleOS1DE/sjfD3TEoyUtB6QJXRQIyLsDoR3FhZMEA5qRCnLhDDwU0Z8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-21644b473ddso21284175ad.0 for ; Mon, 06 Jan 2025 04:24:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736166236; x=1736771036; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=TlUcnOqjHyHSPKD4T5hDUAYA8kpVz3l4vgvph2XIR/Y=; b=Kyw6KGT/FZy14RtTu8chxttW2CR7ti9gdlI4z8GPvTaf2nZLxLpETVZ1scnpTK0BCF yTq1G6qqoesuk7kjakVvRx1hdapeeNAk30dFdcAoLczO47LIJ6XUn0AIuBYNeQu+fyNZ 1dbIsD2NgtYFiTci6YmHB6KkC4QC/dn5z019iFTCBeeoisz4e7YNtgmSeEYhjx+GoxJi O1uox1quaXQfksgNUa7lTSLVd3Tbhydv3/P6FplHn1vbibs+9S9/2NUm99koQBVlsfXV auSl2BE7olL02TpAEFjfzJ/SbvpIQyKh1bR2ATS8oMBjHtxKEVhz31nvcReG1FbZg5hg qcjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736166236; x=1736771036; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TlUcnOqjHyHSPKD4T5hDUAYA8kpVz3l4vgvph2XIR/Y=; b=B9ZS99UdOrfC24NnCXrh/DIGgpDOkOOWzpzhADLdqhvCyJ8jMuVyNYKimBFEdDE+2X 6FqkHTi2ydY8dh6Yf+pGG4fyKhazfv0ygye3IpHjRhQW/7QeqmjnlbKEiryRvJawsjFM hUF9hLXKc8dXCJuxBhDj9n47dTOF4Lc17UhnuUFBxT+lL9LlTPZ4ln2v/7/ETFtM8pr4 WU3r027KCJDxFo5lCsBBF4kTdsn8o3XGHb8scf4guPAJ89fmu7+ThwjDfQ0DO4cIlxAd MqwX16MtQVNmKibP165yxD7kb34vDwr0x27fEZ3/TR3D80Yd088aNjrUjlI9fsSwvxiH lDkQ== X-Gm-Message-State: AOJu0YzTmbzvBUx9ZFOQA+Lr77M/OobqWVgq+5RMMpoKICT//9CA6h9T n/b5jF2yqpBVWwx5k9F+BwO45ZdtHfrNAgL0cQGoQoGpSzr1ZgNpB6+RCg== X-Gm-Gg: ASbGncvsRyxr3QlXUEFiezYgXHvnQlgW0DhbFSXWRGcXXjYFZUr44/MWOl4Zdns1bX9 9bezwF/CG4CA332d1Bfmc3iIRrIvN1/m1IkY61270r7luKfgr5X9wJduL69k/d5WYUO55ZhDaUk 9rx14Pa36MPtm6AYAZp5c9k9BtArP/q6iaf1piPMbUJSQEur/12djPIru7Ts34BKfDZarnrId/W ra80cjSQLv23h2XHvmdmyfcyBuXM4SIaQoSeVmUok2f2w2Oh66b6a5BA3MzKxl/YRjvklcVIc2F PWLdBhYrxmBDnWfGS3nqqg== X-Google-Smtp-Source: AGHT+IGNQfQ47WTyQTOg4U83AqJKzYYtzgF7K8ANRNtUgk8zOt4Bry/bnuh6tAToXvWdXXHrlL424A== X-Received: by 2002:a17:903:2a8c:b0:216:2dc4:50bf with SMTP id d9443c01a7336-219e6e9a450mr312647185ad.6.1736166236444; Mon, 06 Jan 2025 04:23:56 -0800 (PST) Received: from Thaum. (163-47-68-2.ipv4.originbroadband.com.au. [163.47.68.2]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9cddb1sm289354265ad.139.2025.01.06.04.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 04:23:55 -0800 (PST) Message-ID: <677bcb5b.170a0220.182ee4.f964@mx.google.com> X-Google-Original-Message-ID: Date: Mon, 6 Jan 2025 23:23:51 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH v3 5/6] c++/modules: Add testcase for fixed ICE [PR116568] References: <677bca93.050a0220.33acbc.5415@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <677bca93.050a0220.33acbc.5415@mx.google.com> X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org This ICE was fixed by ensuring that the lambdas had LAMBDA_EXPR_EXTRA_SCOPE properly set. PR c++/116568 gcc/testsuite/ChangeLog: * g++.dg/modules/lambda-8.h: New test. * g++.dg/modules/lambda-8_a.H: New test. * g++.dg/modules/lambda-8_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/testsuite/g++.dg/modules/lambda-8.h | 7 +++++++ gcc/testsuite/g++.dg/modules/lambda-8_a.H | 5 +++++ gcc/testsuite/g++.dg/modules/lambda-8_b.C | 5 +++++ 3 files changed, 17 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/lambda-8.h create mode 100644 gcc/testsuite/g++.dg/modules/lambda-8_a.H create mode 100644 gcc/testsuite/g++.dg/modules/lambda-8_b.C diff --git a/gcc/testsuite/g++.dg/modules/lambda-8.h b/gcc/testsuite/g++.dg/modules/lambda-8.h new file mode 100644 index 00000000000..0c66f053b20 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/lambda-8.h @@ -0,0 +1,7 @@ +template struct S { + template static constexpr auto x = []{}; + template using t = decltype([]{}); +}; + +inline auto x = S::x; +using t = S::t; diff --git a/gcc/testsuite/g++.dg/modules/lambda-8_a.H b/gcc/testsuite/g++.dg/modules/lambda-8_a.H new file mode 100644 index 00000000000..d20958ee140 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/lambda-8_a.H @@ -0,0 +1,5 @@ +// PR c++/116568 +// { dg-additional-options "-fmodules-ts -std=c++20" } +// { dg-module-cmi {} } + +#include "lambda-8.h" diff --git a/gcc/testsuite/g++.dg/modules/lambda-8_b.C b/gcc/testsuite/g++.dg/modules/lambda-8_b.C new file mode 100644 index 00000000000..05ea4afd8c1 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/lambda-8_b.C @@ -0,0 +1,5 @@ +// PR c++/116568 +// { dg-additional-options "-fmodules-ts -std=c++20" } + +#include "lambda-8.h" +import "lambda-8_a.H"; From patchwork Mon Jan 6 12:24:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 104167 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B7A66385840F for ; Mon, 6 Jan 2025 12:25:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id BED163857C6C for ; Mon, 6 Jan 2025 12:24:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BED163857C6C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BED163857C6C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::630 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736166270; cv=none; b=VdRX2Q21OLJVnSGMjFnCWV+QddpW6ekNfPMseCeFlxBE/VFnjSh+Z/+I1GATjUBU3sFBZ4awl0lPFFDvJ/N+Bb0hrO+aUlCYszpV281bAm2zJBezmHMpGaecu4b9vtqLb03skONIU//L25ovSo5BYnRVkBqOzjNKWuG7g2F8G+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736166270; c=relaxed/simple; bh=HBJAvQyKwS2CDQvUN+wj8pwBk6JSwf8CKRPKh30UO6I=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=FVOvE8Vli8Bbzt0tH3ghVJLaClqYB7lHGwxdmpBR1PyJyUKktjjtsvT/ZXyvVLvWrBHyG++XqStp8i+trwnrYaUs/M9KC/SJUEdUVvspNUFUc+Hr7egV5obOzwjzWzt5KfAqrOfJmeK7/7EWXlyaYbWkrCrq6eCUMojyOu0ZXFc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BED163857C6C Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=M6BabAny Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-215607278acso16777965ad.1 for ; Mon, 06 Jan 2025 04:24:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736166259; x=1736771059; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=yUMlmuLEPNtBgIkux5LfDgH780MiYaYEzNW55L3esw4=; b=M6BabAnyGEyf6kVeFZ9/vpwc/3CvPHUbcbiV8s4tFCMAL0A/Ah7GYLRIy3bCUKaMFT IyTgS/Lm/bWSAfjdsAY1quxXI2lxkUsh9WghKQU3xrPoqmNoy7BveuFd4DC6X5Udmt/P 48UgmZfkE2HK9ncXmpujLejsrpbSt1pnKAXZkFwQUQLA/P//42JCFUmuXr+6WecatA4L L0vw8e4jIOt7CUMwQVN3Q43lHdAwFa0iUsTDjmpCEyWKhS0xLbsxpnpcbv61py4V/gXf NhQMcqeqNVaZdC59JM5YsytKfI7GqCKk8UfBTP9/CccmMOl2EtE+aNbjYm7hVp+gNqCa REhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736166259; x=1736771059; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=yUMlmuLEPNtBgIkux5LfDgH780MiYaYEzNW55L3esw4=; b=Az8d4PvfQXC6sUWMLScF2SJau0gqqTNXRDlrGa9xKXHckMNyQzIUHae5KPCf2LBC+Y QxLPCG5NILvxYoqDCW5EfrBoT2Nrcr+PE+Rrz8XTHfKN1b3b/WJNiHjBUblMn1XuW/eo 0obr2RmsYC7DcSxElMaouUC3Z+n0OULu1fdRU0pxRmNb0EtTXYBxpcU5fzwS76Q4p4Pe BnWz7GieQi3KyoajdvlNCB+JwytkC8xtDYXr6Jo711HFB9KbH6PHfR6MzrgWt7Uxs17T s4pi4Yo2aDtxJjfh+PyBoOcFES9KR88otcmNIzKoC9ev89ApzRxqcLwUAKOdvO+vlIBf w10A== X-Gm-Message-State: AOJu0YyM6VzIvhhaAT6nQ1R6wXz3Fs7MnieIj5MKjrvNiuDIdj9mRQZv IAs8ldGsIb0Pio80C3lBiJW9tdAGLrcRe1T3KRY3JZ1/u8UEt6/Fx9d1dQ== X-Gm-Gg: ASbGncvPB5+upOS/KbatMsqzFU+kNUZkpKszPKDkSz4D5UoUGFwQOdP4pK7/xp1HkVw MITb8pTE5N0TSHgfl4TX9BxtQkaP4rBtPeYT9JssUaFerY6ufEjQeIMyCy9DZ1hO/oWet97d1Dq UItlSYC1gSiOQKbnIQLnMhhVHjoR9fEucNcXeHd5vUVTAom4leBWGnbyfpTbXt7yqDJso1FJQOr uQdtxlzu8PfsVyO6pVrOuQzM9SaIKAXKkpyHsyaXDNT+3ypnr7JDlGIcsiRRqv1G9C9i+c9VwlF 8keHRw+k4lxQiv0sMNKNsQ== X-Google-Smtp-Source: AGHT+IEv9KikFqpaZ9nRuonEQPopt7OGh4m2jjpuYGH4VXS5js6DW5FKsve+4vhWbjVmI/UimhyEsA== X-Received: by 2002:a05:6a21:6d96:b0:1dc:77fc:1cd4 with SMTP id adf61e73a8af0-1e5e0848b35mr30812155637.12.1736166259018; Mon, 06 Jan 2025 04:24:19 -0800 (PST) Received: from Thaum. (163-47-68-2.ipv4.originbroadband.com.au. [163.47.68.2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8fbac8sm31335870b3a.159.2025.01.06.04.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 04:24:18 -0800 (PST) Message-ID: <677bcb72.a70a0220.2a1825.5a9a@mx.google.com> X-Google-Original-Message-ID: Date: Mon, 6 Jan 2025 23:24:14 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH v3 6/6] c++/modules: Diagnose TU-local lambdas, give mangling scope to lambdas in concepts References: <677bca93.050a0220.33acbc.5415@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <677bca93.050a0220.33acbc.5415@mx.google.com> X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Happy to defer this till GCC16 if preferred. -- >8 -- This fills in a hole left in r15-6378-g9016c5ac94c557 with regards to detection of TU-local lambdas. Now that LAMBDA_EXPR_EXTRA_SCOPE is properly set for most lambdas we can use it to detect lambdas that are TU-local. Lambdas in concept definitions I believe should not be considered TU-local, since they are always unevaluated and should never be emitted. This patch gives these lambdas a mangling scope (though it will never be actually used in name mangling). Namespace-scope alias declarations currently do not have an extra scope set either, so this patch will cause them to be falsely detected as TU-local and error. However, I believe this is better than the alternative, as such lambdas cannot be properly referred to from other TUs now anyway causing strange issues down the line if they were allowed. (Clang makes such lambdas internal linkage.) If in the future we ever correctly give an extra scope to these lambdas they will automatically start working in modules again, but in the meantime they should be avoided (or wrapped in an unnamed namespace). gcc/cp/ChangeLog: * cp-tree.h (finish_concept_definition): Adjust parameters. (start_concept_definition): Declare. * module.cc (depset::hash::is_tu_local_entity): Use LAMBDA_EXPR_EXTRA_SCOPE to detect TU-local lambdas. * parser.cc (cp_parser_concept_definition): Start a lambda scope for concept definitions. * pt.cc (tsubst_lambda_expr): Namespace-scope lambdas may now have extra scope. (finish_concept_definition): Split into... (start_concept_definition): ...this new function. gcc/testsuite/ChangeLog: * g++.dg/modules/internal-4_b.C: Remove XFAILs, add new XFAIL for lambda alias. * g++.dg/modules/lambda-9.h: New test. * g++.dg/modules/lambda-9_a.H: New test. * g++.dg/modules/lambda-9_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/cp-tree.h | 3 ++- gcc/cp/module.cc | 7 ++++--- gcc/cp/parser.cc | 14 +++++++++++++- gcc/cp/pt.cc | 21 +++++++++++++++------ gcc/testsuite/g++.dg/modules/internal-4_b.C | 6 +++++- gcc/testsuite/g++.dg/modules/lambda-9.h | 2 ++ gcc/testsuite/g++.dg/modules/lambda-9_a.H | 4 ++++ gcc/testsuite/g++.dg/modules/lambda-9_b.C | 6 ++++++ 8 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/lambda-9.h create mode 100644 gcc/testsuite/g++.dg/modules/lambda-9_a.H create mode 100644 gcc/testsuite/g++.dg/modules/lambda-9_b.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 824b7bb61ae..ec8935243de 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -8679,7 +8679,8 @@ struct diagnosing_failed_constraint extern cp_expr finish_constraint_or_expr (location_t, cp_expr, cp_expr); extern cp_expr finish_constraint_and_expr (location_t, cp_expr, cp_expr); extern cp_expr finish_constraint_primary_expr (cp_expr); -extern tree finish_concept_definition (cp_expr, tree, tree); +extern tree start_concept_definition (cp_expr); +extern tree finish_concept_definition (tree, tree, tree); extern tree combine_constraint_expressions (tree, tree); extern tree append_constraint (tree, tree); extern tree get_constraints (const_tree); diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 5350e6c4bad..aa0fee1c6cf 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -13365,9 +13365,10 @@ depset::hash::is_tu_local_entity (tree decl, bool explain/*=false*/) tree main_decl = TYPE_MAIN_DECL (type); if (!DECL_CLASS_SCOPE_P (main_decl) && !decl_function_context (main_decl) - /* FIXME: Lambdas defined outside initializers. We'll need to more - thoroughly set LAMBDA_TYPE_EXTRA_SCOPE to check this. */ - && !LAMBDA_TYPE_P (type)) + /* LAMBDA_EXPR_EXTRA_SCOPE will be set for lambdas defined in + contexts where they would not be TU-local. */ + && !(LAMBDA_TYPE_P (type) + && LAMBDA_TYPE_EXTRA_SCOPE (type))) { if (explain) inform (loc, "%qT has no name and is not defined within a class, " diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index c851185a86d..f29d2fd0b00 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -31680,8 +31680,20 @@ cp_parser_concept_definition (cp_parser *parser) return error_mark_node; } + tree decl = start_concept_definition (id); + if (decl == error_mark_node) + { + cp_parser_skip_to_end_of_statement (parser); + cp_parser_consume_semicolon_at_end_of_statement (parser); + return error_mark_node; + } + processing_constraint_expression_sentinel parsing_constraint; + + start_lambda_scope (decl); tree init = cp_parser_constraint_expression (parser); + finish_lambda_scope (); + if (init == error_mark_node) cp_parser_skip_to_end_of_statement (parser); @@ -31689,7 +31701,7 @@ cp_parser_concept_definition (cp_parser *parser) but continue as if it were. */ cp_parser_consume_semicolon_at_end_of_statement (parser); - return finish_concept_definition (id, init, attrs); + return finish_concept_definition (decl, init, attrs); } // -------------------------------------------------------------------------- // diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index cba7b97ef70..2c508c04f4d 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -20098,7 +20098,7 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (LAMBDA_EXPR_EXTRA_SCOPE (t)) record_lambda_scope (r); - else if (TYPE_NAMESPACE_SCOPE_P (TREE_TYPE (t))) + if (TYPE_NAMESPACE_SCOPE_P (TREE_TYPE (t))) /* If we're pushed into another scope (PR105652), fix it. */ TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_NAME (type)) = TYPE_CONTEXT (TREE_TYPE (t)); @@ -29886,12 +29886,10 @@ placeholder_type_constraint_dependent_p (tree t) return false; } -/* Build and return a concept definition. Like other templates, the - CONCEPT_DECL node is wrapped by a TEMPLATE_DECL. This returns the - the TEMPLATE_DECL. */ +/* Prepare and return a concept definition. */ tree -finish_concept_definition (cp_expr id, tree init, tree attrs) +start_concept_definition (cp_expr id) { gcc_assert (identifier_p (id)); gcc_assert (processing_template_decl); @@ -29923,9 +29921,20 @@ finish_concept_definition (cp_expr id, tree init, tree attrs) /* Initially build the concept declaration; its type is bool. */ tree decl = build_lang_decl_loc (loc, CONCEPT_DECL, *id, boolean_type_node); DECL_CONTEXT (decl) = current_scope (); - DECL_INITIAL (decl) = init; TREE_PUBLIC (decl) = true; + return decl; +} + +/* Finish building a concept definition. Like other templates, the + CONCEPT_DECL node is wrapped by a TEMPLATE_DECL. This returns the + the TEMPLATE_DECL. */ + +tree +finish_concept_definition (tree decl, tree init, tree attrs) +{ + DECL_INITIAL (decl) = init; + if (attrs) cplus_decl_attributes (&decl, attrs, 0); diff --git a/gcc/testsuite/g++.dg/modules/internal-4_b.C b/gcc/testsuite/g++.dg/modules/internal-4_b.C index 86bec294fc8..99eda6fbceb 100644 --- a/gcc/testsuite/g++.dg/modules/internal-4_b.C +++ b/gcc/testsuite/g++.dg/modules/internal-4_b.C @@ -80,7 +80,7 @@ void in_function_body() { struct {} x; } // OK auto in_initializer = []{}; // OK #if __cplusplus >= 202002L -decltype([]{}) d_lambda; // { dg-error "exposes TU-local entity" "" { xfail *-*-* } } +decltype([]{}) d_lambda; // { dg-error "exposes TU-local entity" "" { target c++20 } } template concept in_constraint_expression = requires { @@ -89,6 +89,10 @@ concept in_constraint_expression = requires { // but I don't think that is intended. []{}; // { dg-bogus "exposes TU-local entity" } }; + +// Again, by the standard this should probably be legal, but currently +// we cannot properly mangle lambdas in namespace-scope aliases. +using alias_lambda = decltype([]{}); // { dg-bogus "exposes TU-local entity" "" { xfail c++20 } } #endif // (But consider unnamed types with names for linkage purposes as having names) diff --git a/gcc/testsuite/g++.dg/modules/lambda-9.h b/gcc/testsuite/g++.dg/modules/lambda-9.h new file mode 100644 index 00000000000..4de9b7861c1 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/lambda-9.h @@ -0,0 +1,2 @@ +template +concept C = requires { []{}; }; diff --git a/gcc/testsuite/g++.dg/modules/lambda-9_a.H b/gcc/testsuite/g++.dg/modules/lambda-9_a.H new file mode 100644 index 00000000000..da0fa3b31f2 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/lambda-9_a.H @@ -0,0 +1,4 @@ +// { dg-additional-options "-fmodule-header -std=c++20" } +// { dg-module-cmi {} } + +#include "lambda-9.h" diff --git a/gcc/testsuite/g++.dg/modules/lambda-9_b.C b/gcc/testsuite/g++.dg/modules/lambda-9_b.C new file mode 100644 index 00000000000..6f2186421f7 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/lambda-9_b.C @@ -0,0 +1,6 @@ +// { dg-additional-options "-fmodules -std=c++20 -fno-module-lazy" } + +#include "lambda-9.h" +import "lambda-9_a.H"; + +static_assert(C);