From patchwork Wed Dec 2 16:31:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1409832 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=plOoegxC; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CmPc41Fjjz9sTL for ; Thu, 3 Dec 2020 03:31:16 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C1BE5395C401; Wed, 2 Dec 2020 16:31:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by sourceware.org (Postfix) with ESMTPS id 2C046395BC05 for ; Wed, 2 Dec 2020 16:31:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2C046395BC05 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qk1-x72f.google.com with SMTP id q5so1742731qkc.12 for ; Wed, 02 Dec 2020 08:31:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=CbpRxT/cNE4u1LrOQuhSD0McTqTF7OG7Xgj+aIv5AQ0=; b=plOoegxCTKwAX8JI7vjVJug17WQncaqEK5xouQ89WI1BU/p9l6845naeXFBjPzix/Q dAIW1v5XLB9kNEeSd8o2i2ZgqM02VQSKHoSxydc008EKXA6u1knnOE8a7haRG2Op7zpX kmyKBYHnwnbnr4qpuiCcaEYLZoQ3kKtKmC2XbOPYfLlptk4YkdpQIRzVbWsmZSnH9vJh p05gef/FcyPR1pSLNXqAur6kjZcodGvJJHJV1yc3Nk4P0rIIbNW5YP6jr9htZHZWxAjF jKRNKQ9qCKy+yJxNqWi6rmMHQ+JzMXc09vtkIiRZKcv5N3ug6uBL9MCquHNNFBzABO6z Wr7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=CbpRxT/cNE4u1LrOQuhSD0McTqTF7OG7Xgj+aIv5AQ0=; b=Ee7lNxLO4OtWIOAXyb6DVEsnEEezsbTi8J65pwHE2ZZi+yMi29xbNimxbUH6PjcxXj f9h5PVb95RfvnRc/VsgFVcKc770UoHY+NpaPH/uzKSjEJ5dBSGp4Qtdnp3OC+sRAsiYx WnNZX+Msq9A6VELgkd7J/A4XtfudcU3YWJ27JJCnlfx5uRAcWTCFvX2i9USgQmb7kLoE cTe6U95Trk12SC3dVV/yUM7YQZ/EzvYN6bymk2AWamHn48Im17X5mMwUqhav+YRlCiZ1 UdlGIXvUOWwG2Lmk2HFE4Mlk2e3W+VHCdhCjVenTerV5okwsHIBUzJtYsNl9CX/wuBzG Y37g== X-Gm-Message-State: AOAM5307aWltRkuL8pYYYtiGxlPRSe12GhXa6jNxLYhhL06GejQCq2wr MtP3FYO1vC+mChl8nxLesHA= X-Google-Smtp-Source: ABdhPJzKp2LC9OAsKELVuGoF3vzzArALtNzholnLRhgfC22pKEADa0WtCFRPfakubd5mGcMYultyPA== X-Received: by 2002:a37:9f50:: with SMTP id i77mr3479426qke.433.1606926669289; Wed, 02 Dec 2020 08:31:09 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:fd8c:7733:5cca:4143? ([2620:10d:c091:480::1:32f1]) by smtp.googlemail.com with ESMTPSA id h8sm2123645qka.117.2020.12.02.08.31.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2020 08:31:07 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: c++: RTTI accessors for modules Message-ID: Date: Wed, 2 Dec 2020 11:31:06 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The module machinery needs to serialize tinfo types and vars by meaning, not literally. This adds the necessary pieces to rtti. gcc/cp/ * cp-tree.h (DECL_TINFO_P): Also for TYPE_DECLs. (get_tinfo_decl_direct): Declare. (get_pseudo_tinfo_index, get_pseudo_tinfo_type): Declare. * rtti.c (get_tinfo_decl_direct): Externalize. (get_tinfo_desc): Set DECL_TINFO_P on the typedef. (get_pseudo_tinfo_index, get_pseudo_tinfo_type): New. pushing to trunk diff --git i/gcc/cp/cp-tree.h w/gcc/cp/cp-tree.h index 4eaa10bc7fd..d69110f7ab6 100644 --- i/gcc/cp/cp-tree.h +++ w/gcc/cp/cp-tree.h @@ -494,7 +494,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; 4: IDENTIFIER_MARKED (IDENTIFIER_NODEs) TREE_HAS_CONSTRUCTOR (in INDIRECT_REF, SAVE_EXPR, CONSTRUCTOR, CALL_EXPR, or FIELD_DECL). - DECL_TINFO_P (in VAR_DECL) + DECL_TINFO_P (in VAR_DECL, TYPE_DECL) FUNCTION_REF_QUALIFIED (in FUNCTION_TYPE, METHOD_TYPE) OVL_LOOKUP_P (in OVERLOAD) LOOKUP_FOUND_P (in RECORD_TYPE, UNION_TYPE, ENUMERAL_TYPE, NAMESPACE_DECL) @@ -3350,7 +3350,8 @@ struct GTY(()) lang_decl { /* 1 iff VAR_DECL node NODE is a type-info decl. This flag is set for both the primary typeinfo object and the associated NTBS name. */ -#define DECL_TINFO_P(NODE) TREE_LANG_FLAG_4 (VAR_DECL_CHECK (NODE)) +#define DECL_TINFO_P(NODE) \ + TREE_LANG_FLAG_4 (TREE_CHECK2 (NODE,VAR_DECL,TYPE_DECL)) /* 1 iff VAR_DECL node NODE is virtual table or VTT. We forward to DECL_VIRTUAL_P from the common code, as that has the semantics we @@ -7025,6 +7026,7 @@ extern GTY(()) vec *unemitted_tinfo_decls; extern void init_rtti_processing (void); extern tree build_typeid (tree, tsubst_flags_t); +extern tree get_tinfo_decl_direct (tree, tree, int); extern tree get_tinfo_decl (tree); extern tree get_typeid (tree, tsubst_flags_t); extern tree build_headof (tree); @@ -7032,6 +7034,8 @@ extern tree build_dynamic_cast (location_t, tree, tree, tsubst_flags_t); extern void emit_support_tinfos (void); extern bool emit_tinfo_decl (tree); +extern unsigned get_pseudo_tinfo_index (tree); +extern tree get_pseudo_tinfo_type (unsigned); /* in search.c */ extern bool accessible_base_p (tree, tree, bool); diff --git i/gcc/cp/rtti.c w/gcc/cp/rtti.c index 887aae31bf6..d6288622246 100644 --- i/gcc/cp/rtti.c +++ w/gcc/cp/rtti.c @@ -123,7 +123,6 @@ static GTY (()) vec *tinfo_descs; static tree ifnonnull (tree, tree, tsubst_flags_t); static tree tinfo_name (tree, bool); -static tree get_tinfo_decl_direct (tree type, tree name, int pseudo_ix); static tree build_dynamic_cast_1 (location_t, tree, tree, tsubst_flags_t); static tree throw_bad_cast (void); static tree throw_bad_typeid (void); @@ -431,7 +430,7 @@ get_tinfo_decl (tree type) /* Get or create a tinfo VAR_DECL directly from the provided information. The caller must have already checked it is valid to do so. */ -static tree +tree get_tinfo_decl_direct (tree type, tree name, int pseudo_ix) { /* For a class type, the variable is cached in the type node @@ -1479,6 +1478,7 @@ get_tinfo_desc (unsigned ix) finish_builtin_struct (pseudo_type, pseudo_name, fields, NULL_TREE); CLASSTYPE_AS_BASE (pseudo_type) = pseudo_type; DECL_CONTEXT (TYPE_NAME (pseudo_type)) = FROB_CONTEXT (global_namespace); + DECL_TINFO_P (TYPE_NAME (pseudo_type)) = true; xref_basetypes (pseudo_type, /*bases=*/NULL_TREE); res->type = cp_build_qualified_type (pseudo_type, TYPE_QUAL_CONST); @@ -1491,6 +1491,36 @@ get_tinfo_desc (unsigned ix) return res; } +/* Return an identifying index for the pseudo type_info TYPE. + We wrote the index at the end of the name, so just scan it from + there. This isn't critical, as it's only on the first use of this + type during module stream out. */ + +unsigned +get_pseudo_tinfo_index (tree type) +{ + tree name = DECL_NAME (TYPE_NAME (type)); + unsigned ix = 0, scale = 1; + size_t len = IDENTIFIER_LENGTH (name); + const char *ptr = IDENTIFIER_POINTER (name) + len; + + for (; *--ptr != '_'; scale *= 10) + { + len--; + gcc_checking_assert (len && ISDIGIT (*ptr)); + ix += (*ptr - '0') * scale; + } + + gcc_assert (len != IDENTIFIER_LENGTH (name)); + return ix; +} + +tree +get_pseudo_tinfo_type (unsigned ix) +{ + return get_tinfo_desc (ix)->type; +} + /* We lazily create the type info types. */ static void