From patchwork Tue Oct 17 21:31:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1850501 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ddpUJK+V; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S96cT2qzWz20cx for ; Wed, 18 Oct 2023 08:31:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3C24C3858288 for ; Tue, 17 Oct 2023 21:31:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9B9053858C52 for ; Tue, 17 Oct 2023 21:31:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B9053858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9B9053858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697578280; cv=none; b=UQV/Jq0Kfz53MMPpCdlWcfiSWwVrN6NKmHo/OsmF/3nIrAfoYOEUH7PMnrpMBJLCfZZyjkLfNRhXNQqzIn4fSSn/85Y6NVPgFD7BIjyYQISFSuIAn/TCV5M0lwf6UaXHVdvNLWeJ1AH5zBuYjFRF/FWXOY0KqoYaqBxp8s8l/SU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697578280; c=relaxed/simple; bh=Yltehy0KvaQf8ATtd+i8chclsDU5DxLXYonAvMEQQUE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Cs8zc+N3tAx4xctS6iGDlhER3EcBNubJNXiXXIom4sFqFIpZZfr8agJqCojA4nvIqk/xr+xBsvhF6SYtI9Zj0xIw+wQyxq4hft9FFaFGlHgEGsqgk/Za4zoiRa/t/JaMI4QzNzE+mUtqeJNCnhQlv/29N8lMvNNQVDh/OeE3/NI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697578278; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yNSQiw5+4nIKLC8M0UvDAGrlyIAkym0qbAJXIwIdsfo=; b=ddpUJK+Viow5Zw0QBtXovtrGVAI3tZrWBT+qWL5IrxCCxFyLcsiyL+F3GD3sid5FUczS6q 7R6s+OR4D4pfl2uOwznmJAU/2VaSurU9aW6fr8ksQlB8QV4KhWRW9HCueJ4PJbHRcuc35H 3OT2Fy72dBHwqTmWcYP4pcMuX7PcxjA= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-298-A6S3OQJZNTStiSqycLuFIg-1; Tue, 17 Oct 2023 17:31:15 -0400 X-MC-Unique: A6S3OQJZNTStiSqycLuFIg-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3b2e44c8664so739833b6e.3 for ; Tue, 17 Oct 2023 14:31:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697578274; x=1698183074; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yNSQiw5+4nIKLC8M0UvDAGrlyIAkym0qbAJXIwIdsfo=; b=fB7lr30bHJBKcoaKKwanQhn1xythPwfRV1ujl1qMqe3PeFP5Q1umvhEPM1Nogs7AEk CRgLZ2HKFJrCo+ixBdG0x3OLHChvomDfKrs+8zRbn5Bk8nUCBklFuAEd70fFrAEregUA uX6MREgrWDjz4dMk/5Mxvs9q9T3KjC5iQHe+XFIBePvIAv4oq158hEMgR4q3dUqoJrFy 4toyggU45IYIskQRjrmfJDng3HZP2pZ/Bp8zj9IyfXJJ8UWNqLWSrnz7jy10lj0JXfOp 8ExmqLePMTd2+q/IqdXDgVlyDhcE0jI5aPHmL8ve7vRbtSRmy6WPVnfeO5PiQEs6H52C pEuw== X-Gm-Message-State: AOJu0YyUY55hvEYqsZ2hFgmz5K6huPVzqiOhS6W26vVTgl3UWEldMUjM LZXUIfZYhyAOEKkaXzwNuCc+oQWBgXNqJ0OoN6Ldboh30p2Rlpmb/0gKlT9qtHViC8gQwHSjuFR TaCuNcprlgIWUSqI5nekg56hXdkz+HbZkvEMJpdi8bwEsMbp7K06IsibCuvvGuv8eV9U4GpFA1g == X-Received: by 2002:a05:6808:1704:b0:3a9:e8e2:5799 with SMTP id bc4-20020a056808170400b003a9e8e25799mr4960914oib.14.1697578274355; Tue, 17 Oct 2023 14:31:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUQ9KJV3ESzb5j4otHvZ5shhH92FU5CswRfEWA4Mz0MBIBgPmZbEowRP6HcYXbP5eDGQIBOw== X-Received: by 2002:a05:6808:1704:b0:3a9:e8e2:5799 with SMTP id bc4-20020a056808170400b003a9e8e25799mr4960889oib.14.1697578273718; Tue, 17 Oct 2023 14:31:13 -0700 (PDT) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id o11-20020a05620a22cb00b00774830b40d4sm975136qki.47.2023.10.17.14.31.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 14:31:12 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: mangling tweaks Date: Tue, 17 Oct 2023 17:31:10 -0400 Message-Id: <20231017213110.1485201-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- Most of this is introducing the abi_check function to reduce the verbosity of most places that check -fabi-version. The start_mangling change is to avoid needing to zero-initialize additional members of the mangling globals, though I'm not actually adding any. The comment documents existing semantics. gcc/cp/ChangeLog: * mangle.cc (abi_check): New. (write_prefix, write_unqualified_name, write_discriminator) (write_type, write_member_name, write_expression) (write_template_arg, write_template_param): Use it. (start_mangling): Assign from {}. * cp-tree.h: Update comment. --- gcc/cp/cp-tree.h | 6 ++-- gcc/cp/mangle.cc | 85 +++++++++++++++++------------------------------- 2 files changed, 34 insertions(+), 57 deletions(-) base-commit: 4f8700078c8e7d8b9c2022c77b0da007810deb0f diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index efcd2de54e5..1d7df62961e 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4969,12 +4969,14 @@ get_vec_init_expr (tree t) /* The DECL_TEMPLATE_PARMS are a list. The TREE_PURPOSE of each node is a INT_CST whose TREE_INT_CST_LOW indicates the level of the template parameters, with 1 being the outermost set of template - parameters. The TREE_VALUE is a vector, whose elements are the + parameters. The TREE_TYPE is TEMPLATE_PARMS_CONSTRAINTS. + The TREE_VALUE is a vector, whose elements are the template parameters at each level. Each element in the vector is a TREE_LIST, whose TREE_VALUE is a PARM_DECL (if the parameter is a non-type parameter), or a TYPE_DECL (if the parameter is a type parameter) or a TEMPLATE_DECL (if the parameter is a template - parameter). The TREE_PURPOSE is the default value, if any. The + parameter). The TREE_PURPOSE is the default value, if any. + The TREE_TYPE is TEMPLATE_PARM_CONSTRAINTS. The TEMPLATE_PARM_INDEX for the parameter is available as the DECL_INITIAL (for a PARM_DECL) or as the TREE_TYPE (for a TYPE_DECL). diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc index d079f724910..afa68da871c 100644 --- a/gcc/cp/mangle.cc +++ b/gcc/cp/mangle.cc @@ -275,6 +275,17 @@ static tree mangle_special_for_type (const tree, const char *); #define write_unsigned_number(NUMBER) \ write_number ((NUMBER), /*unsigned_p=*/1, 10) +/* Check for -fabi-version dependent mangling and also set the need_abi_warning + flag as appropriate. */ + +static bool +abi_check (int ver) +{ + if (abi_warn_or_compat_version_crosses (ver)) + G.need_abi_warning = true; + return abi_version_at_least (ver); +} + /* If DECL is a template instance (including the uninstantiated template itself), return its TEMPLATE_INFO. Otherwise return NULL. */ @@ -1267,9 +1278,7 @@ write_prefix (const tree node) /* Before ABI 18, we did not count these as substitution candidates. This leads to incorrect demanglings (and ABI divergence to other compilers). */ - if (abi_warn_or_compat_version_crosses (18)) - G.need_abi_warning = true; - if (!abi_version_at_least (18)) + if (!abi_check (18)) return; } } @@ -1542,9 +1551,7 @@ write_unqualified_name (tree decl) && any_abi_below (11)) if (tree mtags = missing_abi_tags (decl)) { - if (abi_warn_or_compat_version_crosses (11)) - G.need_abi_warning = true; - if (!abi_version_at_least (11)) + if (!abi_check (11)) tags = chainon (mtags, tags); } write_abi_tags (tags); @@ -2094,9 +2101,7 @@ write_discriminator (const int discriminator) write_char ('_'); if (discriminator - 1 >= 10) { - if (abi_warn_or_compat_version_crosses (11)) - G.need_abi_warning = 1; - if (abi_version_at_least (11)) + if (abi_check (11)) write_char ('_'); } write_unsigned_number (discriminator - 1); @@ -2425,9 +2430,7 @@ write_type (tree type) if (etype && !type_uses_auto (etype)) { - if (abi_warn_or_compat_version_crosses (5)) - G.need_abi_warning = 1; - if (!abi_version_at_least (5)) + if (!abi_check (5)) { write_type (etype); return; @@ -2448,10 +2451,8 @@ write_type (tree type) case NULLPTR_TYPE: write_string ("Dn"); - if (abi_version_at_least (7)) + if (abi_check (7)) ++is_builtin_type; - if (abi_warn_or_compat_version_crosses (7)) - G.need_abi_warning = 1; break; case TYPEOF_TYPE: @@ -2935,10 +2936,8 @@ write_member_name (tree member) { if (IDENTIFIER_ANY_OP_P (member)) { - if (abi_version_at_least (11)) + if (abi_check (11)) write_string ("on"); - if (abi_warn_or_compat_version_crosses (11)) - G.need_abi_warning = 1; } write_unqualified_id (member); } @@ -3108,7 +3107,7 @@ write_expression (tree expr) write_char ('f'); if (delta != 0) { - if (abi_version_at_least (5)) + if (abi_check (5)) { /* Let L be the number of function prototype scopes from the innermost one (in which the parameter reference occurs) up @@ -3120,8 +3119,6 @@ write_expression (tree expr) write_char ('L'); write_unsigned_number (delta - 1); } - if (abi_warn_or_compat_version_crosses (5)) - G.need_abi_warning = true; } write_char ('p'); write_compact_number (index - 1); @@ -3138,9 +3135,7 @@ write_expression (tree expr) if (PACK_EXPANSION_P (op)) { - if (abi_warn_or_compat_version_crosses (11)) - G.need_abi_warning = true; - if (abi_version_at_least (11)) + if (abi_check (11)) { /* sZ rather than szDp. */ write_string ("sZ"); @@ -3158,9 +3153,7 @@ write_expression (tree expr) { tree args = ARGUMENT_PACK_ARGS (op); int length = TREE_VEC_LENGTH (args); - if (abi_warn_or_compat_version_crosses (10)) - G.need_abi_warning = true; - if (abi_version_at_least (10)) + if (abi_check (10)) { /* sP * E # sizeof...(T), size of a captured template parameter pack from an alias template */ @@ -3198,9 +3191,7 @@ write_expression (tree expr) { if (!ALIGNOF_EXPR_STD_P (expr)) { - if (abi_warn_or_compat_version_crosses (16)) - G.need_abi_warning = true; - if (abi_version_at_least (16)) + if (abi_check (16)) { /* We used to mangle __alignof__ like alignof. */ write_string ("u11__alignof__"); @@ -3445,10 +3436,8 @@ write_expression (tree expr) tree name = dependent_name (expr); if (IDENTIFIER_ANY_OP_P (name)) { - if (abi_version_at_least (16)) + if (abi_check (16)) write_string ("on"); - if (abi_warn_or_compat_version_crosses (16)) - G.need_abi_warning = 1; } write_unqualified_id (name); } @@ -3507,9 +3496,7 @@ write_expression (tree expr) if (code == CONST_CAST_EXPR || code == STATIC_CAST_EXPR) { - if (abi_warn_or_compat_version_crosses (6)) - G.need_abi_warning = 1; - if (!abi_version_at_least (6)) + if (!abi_check (6)) name = OVL_OP_INFO (false, CAST_EXPR)->mangled_name; } @@ -3578,10 +3565,8 @@ write_expression (tree expr) case PREINCREMENT_EXPR: case PREDECREMENT_EXPR: - if (abi_version_at_least (6)) + if (abi_check (6)) write_char ('_'); - if (abi_warn_or_compat_version_crosses (6)) - G.need_abi_warning = 1; /* Fall through. */ default: @@ -3776,11 +3761,9 @@ write_template_arg (tree node) if (TREE_CODE (node) == BASELINK && !type_unknown_p (node)) { - if (abi_version_at_least (6)) + /* Before v6 we wrongly wrapped a class-scope function in X/E. */ + if (abi_check (6)) node = BASELINK_FUNCTIONS (node); - if (abi_warn_or_compat_version_crosses (6)) - /* We wrongly wrapped a class-scope function in X/E. */ - G.need_abi_warning = 1; } if (ARGUMENT_PACK_P (node)) @@ -3788,12 +3771,10 @@ write_template_arg (tree node) /* Expand the template argument pack. */ tree args = ARGUMENT_PACK_ARGS (node); int i, length = TREE_VEC_LENGTH (args); - if (abi_version_at_least (6)) + if (abi_check (6)) write_char ('J'); else write_char ('I'); - if (abi_warn_or_compat_version_crosses (6)) - G.need_abi_warning = 1; for (i = 0; i < length; ++i) write_template_arg (TREE_VEC_ELT (args, i)); write_char ('E'); @@ -3816,12 +3797,10 @@ write_template_arg (tree node) write_char ('L'); /* Until ABI version 3, the underscore before the mangled name was incorrectly omitted. */ - if (!abi_version_at_least (3)) + if (!abi_check (3)) write_char ('Z'); else write_string ("_Z"); - if (abi_warn_or_compat_version_crosses (3)) - G.need_abi_warning = 1; write_encoding (node); write_char ('E'); } @@ -3946,9 +3925,7 @@ write_template_param (const tree parm) write_char ('T'); if (level > 1) { - if (abi_warn_or_compat_version_crosses (19)) - G.need_abi_warning = 1; - if (abi_version_at_least (19)) + if (abi_check (19)) { write_char ('L'); write_compact_number (level - 1); @@ -4007,10 +3984,8 @@ write_substitution (const int seq_id) static inline void start_mangling (const tree entity) { + G = {}; G.entity = entity; - G.need_abi_warning = false; - G.need_cxx17_warning = false; - G.mod = false; obstack_free (&name_obstack, name_base); mangle_obstack = &name_obstack; name_base = obstack_alloc (&name_obstack, 0);