From patchwork Wed Sep 15 04:27:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 45009 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 A6C6F3858023 for ; Wed, 15 Sep 2021 04:28:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6C6F3858023 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631680090; bh=Ul8lZTxE6ZZ09Hlcaqd4HXG0cb2nsusnfKdKKIt3oH8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=WvejOBlypzPxrJw70tt9qSsS+N9ju6y6uqklTLLdpY3LI+ZPOvlQQnUs4XhSF8RU4 vAGYd7dX0+IU7cscYeWC9a0pA+9Wm3+2tCC2X1CZs7S99fxExJqqIj8STdwbatw11P xDMpqgDiM540wTzJufOvDAGhMM1q9ffUMsy0o84g= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 710DC3858C2C for ; Wed, 15 Sep 2021 04:27:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 710DC3858C2C Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-455-eKFE904UPXOSSAU1gHqv0A-1; Wed, 15 Sep 2021 00:27:38 -0400 X-MC-Unique: eKFE904UPXOSSAU1gHqv0A-1 Received: by mail-qt1-f198.google.com with SMTP id p21-20020ac846150000b02902982d999bfbso1326789qtn.7 for ; Tue, 14 Sep 2021 21:27:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ul8lZTxE6ZZ09Hlcaqd4HXG0cb2nsusnfKdKKIt3oH8=; b=bjzN867XyhYYJEXlBusHY0pDRJa7gCrwM4K7gTgQR3hShJgtsfHzqTLDdGd1UNVXb4 o9Z0lt4OEBHcEbRSDbwusu9yKRQglIJ1iazZmWiGRhDgJqKVPkSkXleI3YnLRcRWBAhv TkY2WL/QlcTcS24X4e2w8uaXlh/F5U6UhoKsoiYy/mLlb9NNlQpUNbDWO13P+eSk3YJJ h8pRHEMTjCEx+jSd/5a65/mJCseOgs7CTrGmgE/OesTAYiFZdJ60l+RNqOQ3ZvLyBl03 CEBCFjGzGyfUvzY5J2Jj3sEF9ZzMZSPqakkr/U2y8kj3rtXwA/gPWNwhRtqJGUZ/g3sZ udkQ== X-Gm-Message-State: AOAM532EUeny6wFLqNF9GyYmUjSQAvEYME82nEWlHS8r3/+CQRKuvTqk gD4DF/G4lqyloGfW2Fj+hRTIivQ4/5ltwdrAJwjhvoIC6Nvw9Pkg7QfwgdUyd9EPOxhTKzJtcD/ UxRWxD7wpvbVFyPvfNM9dQIs6U8dnI+1QQnyt8SI4kCB/ovz32RETbjJkkQ0t9HOR4Q== X-Received: by 2002:ae9:df07:: with SMTP id t7mr8255263qkf.95.1631680056852; Tue, 14 Sep 2021 21:27:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCcoV4k/+SheGykmbzLwN7y+TAe/mN5PTIyjLw8MEPxfcoqfW8afYeFwtK7KzS5pnOGGVgdQ== X-Received: by 2002:ae9:df07:: with SMTP id t7mr8255239qkf.95.1631680056300; Tue, 14 Sep 2021 21:27:36 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s11817.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id n20sm9205818qkk.135.2021.09.14.21.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 21:27:35 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: don't predeclare std::type_info [PR48396] Date: Wed, 15 Sep 2021 00:27:33 -0400 Message-Id: <20210915042733.961132-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-27.2 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Cc: jwakely@redhat.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" We've always predeclared std::type_info, which has been wrong for a while, but now with modules it becomes more of a practical problem, if we want to declare it in the purview of a module. So don't predeclare it. For building up the type_info information to write out with the vtable, we can use void* instead of type_info*, since they already aren't the real types. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/48396 gcc/cp/ChangeLog: * cp-tree.h (enum cp_tree_index): Remove CPTI_TYPE_INFO_PTR_TYPE. (type_info_ptr_type): Remove. * rtti.c (init_rtti_processing): Don't predeclare std::type_info. (typeid_ok_p): Check for null const_type_info_type_node. (type_info_ptr_type, get_void_tinfo_ptr): New fns. (get_tinfo_decl_dynamic, get_tinfo_ptr): Use them. (ptr_initializer, ptm_initializer, get_pseudo_ti_init): Use them. (get_tinfo_desc): Use const_ptr_type_node. gcc/testsuite/ChangeLog: * g++.dg/rtti/undeclared1.C: New test. --- gcc/cp/cp-tree.h | 4 +- gcc/cp/rtti.c | 95 ++++++++++++++----------- gcc/testsuite/g++.dg/rtti/undeclared1.C | 5 ++ 3 files changed, 58 insertions(+), 46 deletions(-) create mode 100644 gcc/testsuite/g++.dg/rtti/undeclared1.C base-commit: ba9b07d0259b38a9eccd4eb0df327d3aaabad3c6 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index a82747ca627..060d1a0a3db 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -204,12 +204,11 @@ enum cp_tree_index /* These are created at init time, but the library/headers provide definitions. */ CPTI_ALIGN_TYPE, - CPTI_CONST_TYPE_INFO_TYPE, - CPTI_TYPE_INFO_PTR_TYPE, CPTI_TERMINATE_FN, CPTI_CALL_UNEXPECTED_FN, /* These are lazily inited. */ + CPTI_CONST_TYPE_INFO_TYPE, CPTI_GET_EXCEPTION_PTR_FN, CPTI_BEGIN_CATCH_FN, CPTI_END_CATCH_FN, @@ -251,7 +250,6 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; #define abi_node cp_global_trees[CPTI_ABI] #define global_namespace cp_global_trees[CPTI_GLOBAL] #define const_type_info_type_node cp_global_trees[CPTI_CONST_TYPE_INFO_TYPE] -#define type_info_ptr_type cp_global_trees[CPTI_TYPE_INFO_PTR_TYPE] #define conv_op_marker cp_global_trees[CPTI_CONV_OP_MARKER] #define abort_fndecl cp_global_trees[CPTI_ABORT_FNDECL] #define current_aggr cp_global_trees[CPTI_AGGR_TAG] diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c index fcb33088a21..9c5066bcacc 100644 --- a/gcc/cp/rtti.c +++ b/gcc/cp/rtti.c @@ -125,7 +125,6 @@ static tree tinfo_name (tree, bool); 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); -static tree get_tinfo_ptr (tree); static bool typeid_ok_p (void); static int qualifier_flags (tree); static bool target_incomplete_p (tree); @@ -142,22 +141,11 @@ static bool typeinfo_in_lib_p (tree); static int doing_runtime = 0; -/* Declare language defined type_info type and a pointer to const - type_info. This is incomplete here, and will be completed when - the user #includes . There are language defined - restrictions on what can be done until that is included. Create - the internal versions of the ABI types. */ +/* Create the internal versions of the ABI types. */ void init_rtti_processing (void) { - push_nested_namespace (std_node); - tree type_info_type = xref_tag (class_type, get_identifier ("type_info")); - pop_nested_namespace (std_node); - const_type_info_type_node - = cp_build_qualified_type (type_info_type, TYPE_QUAL_CONST); - type_info_ptr_type = build_pointer_type (const_type_info_type_node); - vec_alloc (unemitted_tinfo_decls, 124); create_tinfo_types (); @@ -238,6 +226,33 @@ throw_bad_typeid (void) return build_cxx_call (fn, 0, NULL, tf_warning_or_error); } +/* const type_info*. */ + +inline tree +type_info_ptr_type () +{ + return build_pointer_type (const_type_info_type_node); +} + +/* Return a pointer to a type_info object describing TYPE, suitably + cast to the language defined type (for typeid) or void (for building + up the descriptors). */ + +static tree +get_tinfo_ptr (tree type, bool voidp = false) +{ + tree decl = get_tinfo_decl (type); + mark_used (decl); + + tree ptype = voidp ? const_ptr_type_node : type_info_ptr_type (); + return build_nop (ptype, build_address (decl)); +} +static inline tree +get_void_tinfo_ptr (tree type) +{ + return get_tinfo_ptr (type, true); +} + /* Return an lvalue expression whose type is "const std::type_info" and whose value indicates the type of the expression EXP. If EXP is a reference to a polymorphic class, return the dynamic type; @@ -278,7 +293,7 @@ get_tinfo_decl_dynamic (tree exp, tsubst_flags_t complain) index = build_int_cst (NULL_TREE, -1 * TARGET_VTABLE_DATA_ENTRY_DISTANCE); t = build_vtbl_ref (exp, index); - t = convert (type_info_ptr_type, t); + t = convert (type_info_ptr_type (), t); } else /* Otherwise return the type_info for the static type of the expr. */ @@ -296,15 +311,22 @@ typeid_ok_p (void) return false; } - if (!COMPLETE_TYPE_P (const_type_info_type_node)) + if (!const_type_info_type_node) { - gcc_rich_location richloc (input_location); - maybe_add_include_fixit (&richloc, "", false); - error_at (&richloc, - "must %<#include %> before using" - " %"); + tree name = get_identifier ("type_info"); + tree decl = lookup_qualified_name (std_node, name); + if (TREE_CODE (decl) != TYPE_DECL) + { + gcc_rich_location richloc (input_location); + maybe_add_include_fixit (&richloc, "", false); + error_at (&richloc, + "must %<#include %> before using" + " %"); - return false; + return false; + } + const_type_info_type_node + = cp_build_qualified_type (TREE_TYPE (decl), TYPE_QUAL_CONST); } tree pseudo = TYPE_MAIN_VARIANT (get_tinfo_desc (TK_TYPE_INFO_TYPE)->type); @@ -471,19 +493,6 @@ get_tinfo_decl_direct (tree type, tree name, int pseudo_ix) return d; } -/* Return a pointer to a type_info object describing TYPE, suitably - cast to the language defined type. */ - -static tree -get_tinfo_ptr (tree type) -{ - tree decl = get_tinfo_decl (type); - - mark_used (decl); - return build_nop (type_info_ptr_type, - build_address (decl)); -} - /* Return the type_info object for TYPE. */ tree @@ -1032,7 +1041,7 @@ ptr_initializer (tinfo_s *ti, tree target) CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init); CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, flags)); CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, - get_tinfo_ptr (TYPE_MAIN_VARIANT (to))); + get_void_tinfo_ptr (TYPE_MAIN_VARIANT (to))); init = build_constructor (init_list_type_node, v); TREE_CONSTANT (init) = 1; @@ -1063,8 +1072,8 @@ ptm_initializer (tinfo_s *ti, tree target) CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init); CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, flags)); CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, - get_tinfo_ptr (TYPE_MAIN_VARIANT (to))); - CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, get_tinfo_ptr (klass)); + get_void_tinfo_ptr (TYPE_MAIN_VARIANT (to))); + CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, get_void_tinfo_ptr (klass)); init = build_constructor (init_list_type_node, v); TREE_CONSTANT (init) = 1; @@ -1156,7 +1165,7 @@ get_pseudo_ti_init (tree type, unsigned tk_index) case TK_SI_CLASS_TYPE: { tree base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), 0); - tree tinfo = get_tinfo_ptr (BINFO_TYPE (base_binfo)); + tree tinfo = get_void_tinfo_ptr (BINFO_TYPE (base_binfo)); /* get_tinfo_ptr might have reallocated the tinfo_descs vector. */ ti = &(*tinfo_descs)[tk_index]; @@ -1187,7 +1196,7 @@ get_pseudo_ti_init (tree type, unsigned tk_index) if ((*base_accesses)[ix] == access_public_node) flags |= 2; - tinfo = get_tinfo_ptr (BINFO_TYPE (base_binfo)); + tinfo = get_void_tinfo_ptr (BINFO_TYPE (base_binfo)); if (BINFO_VIRTUAL_P (base_binfo)) { /* We store the vtable offset at which the virtual @@ -1360,7 +1369,7 @@ get_tinfo_desc (unsigned ix) /* Base class internal helper. Pointer to base type, offset to base, flags. */ tree fld_ptr = build_decl (BUILTINS_LOCATION, FIELD_DECL, - NULL_TREE, type_info_ptr_type); + NULL_TREE, const_ptr_type_node); DECL_CHAIN (fld_ptr) = fields; fields = fld_ptr; @@ -1396,7 +1405,7 @@ get_tinfo_desc (unsigned ix) fields = fld_mask; tree fld_ptr = build_decl (BUILTINS_LOCATION, FIELD_DECL, - NULL_TREE, type_info_ptr_type); + NULL_TREE, const_ptr_type_node); DECL_CHAIN (fld_ptr) = fields; fields = fld_ptr; @@ -1404,7 +1413,7 @@ get_tinfo_desc (unsigned ix) { /* Add a pointer to the class too. */ tree fld_cls = build_decl (BUILTINS_LOCATION, FIELD_DECL, - NULL_TREE, type_info_ptr_type); + NULL_TREE, const_ptr_type_node); DECL_CHAIN (fld_cls) = fields; fields = fld_cls; } @@ -1421,7 +1430,7 @@ get_tinfo_desc (unsigned ix) class. This is really a descendant of __class_type_info. */ tree fld_ptr = build_decl (BUILTINS_LOCATION, FIELD_DECL, - NULL_TREE, type_info_ptr_type); + NULL_TREE, const_ptr_type_node); DECL_CHAIN (fld_ptr) = fields; fields = fld_ptr; break; diff --git a/gcc/testsuite/g++.dg/rtti/undeclared1.C b/gcc/testsuite/g++.dg/rtti/undeclared1.C new file mode 100644 index 00000000000..9594c229f45 --- /dev/null +++ b/gcc/testsuite/g++.dg/rtti/undeclared1.C @@ -0,0 +1,5 @@ +// PR c++/48396 + +namespace std { + type_info *p; // { dg-error "type_info" } +}